From ec518844146943aafc3dca4183528eb57aac38d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 28 Jul 2020 22:59:29 +0800 Subject: [PATCH] Revised the fill_transaction_from_previous_form() utility in the accounting application. --- accounting/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/accounting/utils.py b/accounting/utils.py index 321ef4a..46907f9 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -315,12 +315,14 @@ def fill_transaction_from_previous_form(request, transaction): max_debit_no = 0 max_credit_no = 0 for key in form.keys(): - m = re.match("^debit-([1-9][0-9]*)-", key) + m = re.match( + "^debit-([1-9][0-9]*)-(sn|ord|account|summary|amount)", key) if m is not None: no = int(m.group(1)) if max_debit_no < no: max_debit_no = no - m = re.match("^credit-([1-9][0-9]*)-", key) + m = re.match( + "^credit-([1-9][0-9]*)-(sn|ord|account|summary|amount)", key) if m is not None: no = int(m.group(1)) if max_credit_no < no: @@ -328,7 +330,7 @@ def fill_transaction_from_previous_form(request, transaction): records = [] for i in range(max_debit_no): no = i + 1 - record = Record(ord=no, is_credit=False) + record = Record(ord=no, is_credit=False, transaction=transaction) if F"debit-{no}-sn" in form: record.pk = form[F"debit-{no}-sn"] if F"debit-{no}-account" in form: @@ -340,7 +342,7 @@ def fill_transaction_from_previous_form(request, transaction): records.append(record) for i in range(max_credit_no): no = i + 1 - record = Record(ord=no, is_credit=True) + record = Record(ord=no, is_credit=False, transaction=transaction) if F"credit-{no}-sn" in form: record.pk = form[F"credit-{no}-sn"] if F"credit-{no}-account" in form: