Fixed the fill_txn_from_post() utility so that it works on new transactions without any record in the accounting application.

This commit is contained in:
依瑪貓 2020-08-05 08:04:40 +08:00
parent 65bfdf3a88
commit b6f5bbaf9e

View File

@ -407,9 +407,15 @@ def fill_txn_from_post(txn_type, txn, post):
records.append(record) records.append(record)
if txn_type != "transfer": if txn_type != "transfer":
if txn_type == "expense": 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: 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.ord = 1
record.account = Account.objects.get(code=Account.CASH) record.account = Account.objects.get(code=Account.CASH)
record.summary = None record.summary = None