From b353a3fba878deac0f1ad4c551b0694c48109408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 21 Jul 2020 19:45:14 +0800 Subject: [PATCH] Replaced filter().first() with get() when finding the account #3351 in the accounting application. --- accounting/views/reports.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/accounting/views/reports.py b/accounting/views/reports.py index e4fd540..af2a844 100644 --- a/accounting/views/reports.py +++ b/accounting/views/reports.py @@ -144,7 +144,7 @@ def cash(request, account_code, period_spec): x.amount for x in records if not x.is_credit]) records.insert(0, Record( transaction=Transaction(date=period.start), - account=Account.objects.filter(code="3351").first(), + account=Account.objects.get(code="3351"), is_credit=balance_before >= 0, amount=abs(balance_before), balance=balance_before)) @@ -502,14 +502,14 @@ def journal(request, period_spec): if sum_debits < sum_credits: debit_records.append(Record( transaction=Transaction(date=period.start), - account=Account.objects.filter(code="3351").first(), + account=Account.objects.get(code="3351"), is_credit=False, amount=sum_credits - sum_debits )) elif sum_debits > sum_credits: credit_records.append(Record( transaction=Transaction(date=period.start), - account=Account.objects.filter(code="3351").first(), + account=Account.objects.get(code="3351"), is_credit=True, amount=sum_debits - sum_credits )) @@ -610,7 +610,7 @@ def trial_balance(request, period_spec): When(is_credit=True, then=-1), default=1) * F("amount")))["balance"] if balance is not None and balance != 0: - brought_forward = Account.objects.filter(code="3351").first() + brought_forward = Account.objects.get(code="3351") if balance > 0: brought_forward.debit = balance brought_forward.credit = 0