forked from DGNum/gestioCOF
Begin/end balance stat graph
- Anytime begin at account creation datetime - Others doesn't take care of account creation - Add check to avoid to bug on actions list length
This commit is contained in:
parent
769c37634d
commit
87bc90ec8b
|
@ -2186,7 +2186,22 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
||||||
# autre passe)
|
# autre passe)
|
||||||
# }
|
# }
|
||||||
|
|
||||||
actions = [
|
actions = []
|
||||||
|
|
||||||
|
actions.append({
|
||||||
|
'at': (begin_date or account.created_at).isoformat(),
|
||||||
|
'amount': 0,
|
||||||
|
'label': 'début',
|
||||||
|
'balance': 0,
|
||||||
|
})
|
||||||
|
actions.append({
|
||||||
|
'at': (end_date or timezone.now()).isoformat(),
|
||||||
|
'amount': 0,
|
||||||
|
'label': 'fin',
|
||||||
|
'balance': 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
actions += [
|
||||||
{
|
{
|
||||||
'at': ope_grp.at.isoformat(),
|
'at': ope_grp.at.isoformat(),
|
||||||
'amount': ope_grp.amount,
|
'amount': ope_grp.amount,
|
||||||
|
@ -2210,11 +2225,12 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
||||||
]
|
]
|
||||||
# Maintenant on trie la liste des actions par ordre du plus récent
|
# Maintenant on trie la liste des actions par ordre du plus récent
|
||||||
# an plus ancien et on met à jour la balance
|
# an plus ancien et on met à jour la balance
|
||||||
actions = sorted(actions, key=lambda k: k['at'], reverse=True)
|
if len(actions) > 1:
|
||||||
actions[0]['balance'] = account.balance
|
actions = sorted(actions, key=lambda k: k['at'], reverse=True)
|
||||||
for i in range(len(actions)-1):
|
actions[0]['balance'] = account.balance
|
||||||
actions[i+1]['balance'] = \
|
for i in range(len(actions)-1):
|
||||||
actions[i]['balance'] - actions[i+1]['amount']
|
actions[i+1]['balance'] = \
|
||||||
|
actions[i]['balance'] - actions[i+1]['amount']
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue