Renamed the credit_amount attribute to credit and debit_summary to debit in RecordSummary in the accounting application.

This commit is contained in:
依瑪貓 2020-07-18 07:52:16 +08:00
parent a15a359ca7
commit 753e69d4e9
4 changed files with 24 additions and 24 deletions

View File

@ -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

View File

@ -102,8 +102,8 @@ First written: 2020/7/15
{% for record in records %}
<tr class="{% if record.balance < 0 %} table-danger {% endif %}">
<td>{{ record.label }}</td>
<td class="amount">{{ record.credit_amount|accounting_amount }}</td>
<td class="amount">{{ record.debit_amount|accounting_amount }}</td>
<td class="amount">{{ record.credit|accounting_amount }}</td>
<td class="amount">{{ record.debit|accounting_amount }}</td>
<td class="amount {% if record.balance < 0 %} text-danger {% endif %}">{{ record.balance|accounting_amount }}</td>
<td class="amount {% if record.cumulative_balance < 0 %} text-danger {% endif %}">{{ record.cumulative_balance|accounting_amount }}</td>
<td class="actions">
@ -128,10 +128,10 @@ First written: 2020/7/15
{{ record.label }}
<div>
<span class="badge badge-success badge-pill">
{{ record.credit_amount|accounting_amount }}
{{ record.credit|accounting_amount }}
</span>
<span class="badge badge-warning badge-pill">
{{ record.debit_amount|accounting_amount }}
{{ record.debit|accounting_amount }}
</span>
<span class="badge {% if record.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
{{ record.balance|intcomma:False }}
@ -146,10 +146,10 @@ First written: 2020/7/15
{{ record.label }}
<div>
<span class="badge badge-success badge-pill">
{{ record.credit_amount|accounting_amount }}
{{ record.credit|accounting_amount }}
</span>
<span class="badge badge-warning badge-pill">
{{ record.debit_amount|accounting_amount }}
{{ record.debit|accounting_amount }}
</span>
<span class="badge {% if record.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
{{ record.balance|intcomma:False }}

View File

@ -95,8 +95,8 @@ First written: 2020/7/17
{% for record in records %}
<tr class="{% if current_subject.code|first in "12" and record.balance < 0 %} table-danger {% endif %}">
<td>{{ record.label }}</td>
<td class="amount">{{ record.debit_amount|accounting_amount }}</td>
<td class="amount">{{ record.credit_amount|accounting_amount }}</td>
<td class="amount">{{ record.debit|accounting_amount }}</td>
<td class="amount">{{ record.credit|accounting_amount }}</td>
<td class="amount {% if record.balance < 0 %} text-danger {% endif %}">{{ record.balance|accounting_amount }}</td>
<td class="amount {% if record.cumulative_balance < 0 %} text-danger {% endif %}">{{ record.cumulative_balance|accounting_amount }}</td>
<td class="actions">
@ -121,10 +121,10 @@ First written: 2020/7/17
{{ record.label }}
<div>
<span class="badge badge-success badge-pill">
{{ record.debit_amount|accounting_amount }}
{{ record.debit|accounting_amount }}
</span>
<span class="badge badge-warning badge-pill">
{{ record.credit_amount|accounting_amount }}
{{ record.credit|accounting_amount }}
</span>
<span class="badge {% if record.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
{{ record.balance|intcomma:False }}
@ -145,10 +145,10 @@ First written: 2020/7/17
{{ record.label }}
<div>
<span class="badge badge-success badge-pill">
{{ record.debit_amount|accounting_amount }}
{{ record.debit|accounting_amount }}
</span>
<span class="badge badge-warning badge-pill">
{{ record.credit_amount|accounting_amount }}
{{ record.credit|accounting_amount }}
</span>
<span class="badge {% if record.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
{{ record.balance|intcomma:False }}

View File

@ -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,
))