Fix initial account calculation. master
authorNIIBE Yutaka <gniibe@fsij.org>
Mon, 1 Jul 2019 00:42:11 +0000 (09:42 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Mon, 1 Jul 2019 00:42:11 +0000 (09:42 +0900)
fsij/accounting/models.py

index 4f72595..4d42c20 100644 (file)
@@ -183,15 +183,26 @@ class GeneralLedgerEntry(object):
         return cash
 
     def get_initial_value(self,account):
+        le_list = []
         for t in self.transactions_over_terms:
             if t.date != self.fy.begin():
                 continue
             try:
                 le = t.ledgerentry_set.get(account=account)
-                return le
+                le_list.append(le)
             except:
                 continue
-        return None
+        if le_list:
+            if len(le_list) == 1:
+                return le_list[0]
+            else:
+                le = le_list[0]
+                amount = 0
+                for le0 in le_list:
+                    amount += le0.amount
+                return LedgerEntry(t=le.t, is_credit=le.is_credit, account=le.account, amount=amount)
+        else:
+            return None
 #
 # Transactions, example
 #