diff --git a/accounting/models.py b/accounting/models.py index d4d25d2..e756323 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -322,8 +322,8 @@ class Record(models.Model): class RecordSummary(models.Model): """A summary record.""" month = models.DateField(primary_key=True) - credit_amount = models.PositiveIntegerField() - debit_amount = models.PositiveIntegerField() + credit = models.PositiveIntegerField() + debit = models.PositiveIntegerField() balance = models.IntegerField() _label = None diff --git a/accounting/templates/accounting/cash_summary.html b/accounting/templates/accounting/cash_summary.html index d620bd1..b622285 100644 --- a/accounting/templates/accounting/cash_summary.html +++ b/accounting/templates/accounting/cash_summary.html @@ -102,8 +102,8 @@ First written: 2020/7/15 {% for record in records %} {{ record.label }} - {{ record.credit_amount|accounting_amount }} - {{ record.debit_amount|accounting_amount }} + {{ record.credit|accounting_amount }} + {{ record.debit|accounting_amount }} {{ record.balance|accounting_amount }} {{ record.cumulative_balance|accounting_amount }} @@ -128,10 +128,10 @@ First written: 2020/7/15 {{ record.label }}
- {{ record.credit_amount|accounting_amount }} + {{ record.credit|accounting_amount }} - {{ record.debit_amount|accounting_amount }} + {{ record.debit|accounting_amount }} {{ record.balance|intcomma:False }} @@ -146,10 +146,10 @@ First written: 2020/7/15 {{ record.label }}
- {{ record.credit_amount|accounting_amount }} + {{ record.credit|accounting_amount }} - {{ record.debit_amount|accounting_amount }} + {{ record.debit|accounting_amount }} {{ record.balance|intcomma:False }} diff --git a/accounting/templates/accounting/ledger_summary.html b/accounting/templates/accounting/ledger_summary.html index 50bf4c2..06e6e94 100644 --- a/accounting/templates/accounting/ledger_summary.html +++ b/accounting/templates/accounting/ledger_summary.html @@ -95,8 +95,8 @@ First written: 2020/7/17 {% for record in records %} {{ record.label }} - {{ record.debit_amount|accounting_amount }} - {{ record.credit_amount|accounting_amount }} + {{ record.debit|accounting_amount }} + {{ record.credit|accounting_amount }} {{ record.balance|accounting_amount }} {{ record.cumulative_balance|accounting_amount }} @@ -121,10 +121,10 @@ First written: 2020/7/17 {{ record.label }}
- {{ record.debit_amount|accounting_amount }} + {{ record.debit|accounting_amount }} - {{ record.credit_amount|accounting_amount }} + {{ record.credit|accounting_amount }} {{ record.balance|intcomma:False }} @@ -145,10 +145,10 @@ First written: 2020/7/17 {{ record.label }}
- {{ record.debit_amount|accounting_amount }} + {{ record.debit|accounting_amount }} - {{ record.credit_amount|accounting_amount }} + {{ record.credit|accounting_amount }} {{ record.balance|intcomma:False }} diff --git a/accounting/views/__init__.py b/accounting/views/__init__.py index 93f7d1a..1077345 100644 --- a/accounting/views/__init__.py +++ b/accounting/views/__init__.py @@ -298,8 +298,8 @@ def cash_summary(request, subject_code): records = list(RecordSummary.objects.raw( f"""SELECT {month_definition} AS month, - SUM(CASE WHEN r.is_credit THEN r.amount ELSE 0 END) AS credit_amount, - SUM(CASE WHEN r.is_credit THEN 0 ELSE r.amount END) AS debit_amount, + SUM(CASE WHEN r.is_credit THEN r.amount ELSE 0 END) AS credit, + SUM(CASE WHEN r.is_credit THEN 0 ELSE r.amount END) AS debit, SUM(CASE WHEN r.is_credit THEN 1 ELSE -1 END * r.amount) AS balance FROM accounting_records AS r INNER JOIN (SELECT @@ -326,8 +326,8 @@ ORDER BY month""")) records = list(RecordSummary.objects.raw( f"""SELECT {month_definition} AS month, - SUM(CASE WHEN r.is_credit THEN r.amount ELSE 0 END) AS credit_amount, - SUM(CASE WHEN r.is_credit THEN 0 ELSE r.amount END) AS debit_amount, + SUM(CASE WHEN r.is_credit THEN r.amount ELSE 0 END) AS credit, + SUM(CASE WHEN r.is_credit THEN 0 ELSE r.amount END) AS debit, SUM(CASE WHEN r.is_credit THEN 1 ELSE -1 END * r.amount) AS balance FROM accounting_records AS r INNER JOIN (SELECT @@ -351,8 +351,8 @@ ORDER BY month""", record.cumulative_balance = cumulative_balance records.append(RecordSummary( label=pgettext("Accounting|", "Total"), - credit_amount=sum([x.credit_amount for x in records]), - debit_amount=sum([x.debit_amount for x in records]), + credit=sum([x.credit for x in records]), + debit=sum([x.debit for x in records]), balance=sum([x.balance for x in records]), cumulative_balance=cumulative_balance, )) @@ -468,8 +468,8 @@ def ledger_summary(request, subject_code): # The accounting records records = [RecordSummary( month=x["month"], - debit_amount=x["debit"] if x["debit"] is not None else 0, - credit_amount=x["credit"] if x["credit"] is not None else 0, + debit=x["debit"] if x["debit"] is not None else 0, + credit=x["credit"] if x["credit"] is not None else 0, balance=x["balance"], ) for x in Record.objects\ .filter(subject__code__startswith=current_subject.code)\ @@ -492,8 +492,8 @@ def ledger_summary(request, subject_code): record.cumulative_balance = cumulative_balance records.append(RecordSummary( label=pgettext("Accounting|", "Total"), - credit_amount=sum([x.credit_amount for x in records]), - debit_amount=sum([x.debit_amount for x in records]), + credit=sum([x.credit for x in records]), + debit=sum([x.debit for x in records]), balance=sum([x.balance for x in records]), cumulative_balance=cumulative_balance, ))