From df6c961dc39f3c523e9af2131011ed4f09136601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 24 Aug 2021 07:10:47 +0800 Subject: [PATCH] Added the output_field when calculating the balance in the cash report. --- accounting/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/accounting/views.py b/accounting/views.py index a6ee8a1..ce0bcd8 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -28,7 +28,7 @@ from django.conf import settings from django.contrib import messages from django.db import transaction from django.db.models import Sum, Case, When, F, Q, Count, BooleanField, \ - ExpressionWrapper, Exists, OuterRef, Value, CharField + ExpressionWrapper, Exists, OuterRef, Value, CharField, DecimalField from django.db.models.functions import TruncMonth, Coalesce, Left, StrIndex from django.http import JsonResponse, HttpResponseRedirect, Http404, \ HttpRequest, HttpResponse @@ -124,7 +124,8 @@ def cash(request: HttpRequest, account: Account, .aggregate( balance=Coalesce(Sum(Case(When( is_credit=True, then=-1), - default=1) * F("amount")), 0))["balance"] + default=1) * F("amount"), output_field=DecimalField()), + 0, output_field=DecimalField()))["balance"] balance = balance_before for record in records: sign = 1 if record.is_credit else -1