Fixed the fill_txn_from_post() utility when constructing the records in the accounting application.

This commit is contained in:
依瑪貓 2020-08-02 09:51:17 +08:00
parent fe8dae191e
commit 330b43c71b

View File

@ -284,13 +284,13 @@ def find_order_holes(records):
def fill_txn_from_post(txn, post):
"""Fills the transaction from the POSTed data.
"""Fills the transaction from the POSTed data. The POSTed data must be
validated and clean at this moment.
Args:
txn (Transaction): The transaction.
post (dict): The POSTed data.
"""
if "date" in post:
txn.date = post["date"]
if "notes" in post:
txn.notes = post["notes"]
@ -300,17 +300,17 @@ def fill_txn_from_post(txn, post):
for rec_type in max_no.keys():
for i in range(max_no[rec_type]):
no = i + 1
if F"{rec_type}-{no}-id" in post:
record = Record.objects.get(pk=post[F"{rec_type}-{no}-id"])
else:
record = Record(
ord=no,
is_credit=(rec_type == "credit"),
transaction=txn)
if F"{rec_type}-{no}-id" in post:
record.pk = post[F"{rec_type}-{no}-id"]
if F"{rec_type}-{no}-account" in post:
record.account = Account(code=post[F"{rec_type}-{no}-account"])
record.ord = no
record.account = Account.objects.get(
code=post[F"{rec_type}-{no}-account"])
if F"{rec_type}-{no}-summary" in post:
record.summary = post[F"{rec_type}-{no}-summary"]
if F"{rec_type}-{no}-amount" in post:
record.amount = post[F"{rec_type}-{no}-amount"]
records.append(record)
txn.records = records