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
1 changed files with 22 additions and 6 deletions
|
@ -2186,7 +2186,22 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
|||
# 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(),
|
||||
'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
|
||||
# an plus ancien et on met à jour la balance
|
||||
actions = sorted(actions, key=lambda k: k['at'], reverse=True)
|
||||
actions[0]['balance'] = account.balance
|
||||
for i in range(len(actions)-1):
|
||||
actions[i+1]['balance'] = \
|
||||
actions[i]['balance'] - actions[i+1]['amount']
|
||||
if len(actions) > 1:
|
||||
actions = sorted(actions, key=lambda k: k['at'], reverse=True)
|
||||
actions[0]['balance'] = account.balance
|
||||
for i in range(len(actions)-1):
|
||||
actions[i+1]['balance'] = \
|
||||
actions[i]['balance'] - actions[i+1]['amount']
|
||||
return actions
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue