From b6f5bbaf9ef0847a545ffb7e7edd5302e2413f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 5 Aug 2020 08:04:40 +0800 Subject: [PATCH] Fixed the fill_txn_from_post() utility so that it works on new transactions without any record in the accounting application. --- accounting/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/accounting/utils.py b/accounting/utils.py index ef8d2fc..66ae258 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -407,9 +407,15 @@ def fill_txn_from_post(txn_type, txn, post): records.append(record) if txn_type != "transfer": if txn_type == "expense": - record = txn.credit_records[0] + if len(txn.credit_records) > 0: + record = txn.credit_records[0] + else: + record = Record(is_credit=True, transaction=txn) else: - record = txn.debit_records[0] + if len(txn.debit_records) > 0: + record = txn.debit_records[0] + else: + record = Record(is_credit=False, transaction=txn) record.ord = 1 record.account = Account.objects.get(code=Account.CASH) record.summary = None