From 54939d305080fc1cc93338fd748383029a73279a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 1 Aug 2020 07:49:56 +0800 Subject: [PATCH] Fixed the error in the view of the cash account when there is no data in the current period in the accounting application. --- accounting/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/accounting/views.py b/accounting/views.py index 52b5aa4..49999a1 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -26,6 +26,7 @@ from django.db.models import Sum, Case, When, F, Q from django.db.models.functions import TruncMonth, Coalesce from django.shortcuts import render from django.urls import reverse +from django.utils import timezone from django.utils.decorators import method_decorator from django.utils.translation import pgettext, gettext_noop from django.views.decorators.http import require_GET, require_POST @@ -124,7 +125,8 @@ def cash(request, account, period): balance = balance + sign * record.amount record.balance = balance record_sum = Record( - transaction=Transaction(date=records[-1].transaction.date), + transaction=Transaction(date=records[-1].transaction.date) + if len(records)>0 else Transaction(date=timezone.localdate()), account=account, summary=pgettext("Accounting|", "Total"), balance=balance