diff --git a/kfet/views.py b/kfet/views.py index fdcb3763..a82e5cea 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -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):