Added the mount, debit_amount, and credit_amount properties to replace the run-time balance, total, debit, and credit properties in the Account data model in the accounting application.
This commit is contained in:
parent
bcc394128e
commit
b652d090d3
@ -58,6 +58,9 @@ class Account(DirtyFieldsMixin, models.Model):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Account, self).__init__(*args, **kwargs)
|
super(Account, self).__init__(*args, **kwargs)
|
||||||
self.url = None
|
self.url = None
|
||||||
|
self.debit_amount = None
|
||||||
|
self.credit_amount = None
|
||||||
|
self.amount = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Returns the string representation of this account."""
|
"""Returns the string representation of this account."""
|
||||||
|
@ -95,7 +95,7 @@ First written: 2020/7/20
|
|||||||
{% for item in group.details %}
|
{% for item in group.details %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div class="account">{{ item.title|title }}</div></td>
|
<td><div class="account">{{ item.title|title }}</div></td>
|
||||||
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
|
<td class="amount {% if item.amount < 0 %} text-danger {% endif %}">{{ item.amount|accounting_amount }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
@ -126,7 +126,7 @@ First written: 2020/7/20
|
|||||||
{% for item in group.details %}
|
{% for item in group.details %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div class="account">{{ item.title|title }}</div></td>
|
<td><div class="account">{{ item.title|title }}</div></td>
|
||||||
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
|
<td class="amount {% if item.amount < 0 %} text-danger {% endif %}">{{ item.amount|accounting_amount }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
@ -140,8 +140,8 @@ First written: 2020/7/20
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
||||||
<td class="amount {% if liabilities.balance < 0 %} text-danger {% endif %}">
|
<td class="amount {% if liabilities.amount < 0 %} text-danger {% endif %}">
|
||||||
{{ liabilities.balance|accounting_amount }}
|
{{ liabilities.amount|accounting_amount }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -163,7 +163,7 @@ First written: 2020/7/20
|
|||||||
{% for item in group.details %}
|
{% for item in group.details %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div class="account">{{ item.title|title }}</div></td>
|
<td><div class="account">{{ item.title|title }}</div></td>
|
||||||
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
|
<td class="amount {% if item.amount < 0 %} text-danger {% endif %}">{{ item.amount|accounting_amount }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
<a href="{{ item.url }}" class="btn btn-info" role="button">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
@ -177,8 +177,8 @@ First written: 2020/7/20
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
||||||
<td class="amount {% if owners_equity.balance < 0 %} text-danger {% endif %}">
|
<td class="amount {% if owners_equity.amount < 0 %} text-danger {% endif %}">
|
||||||
{{ owners_equity.balance|accounting_amount }}
|
{{ owners_equity.amount|accounting_amount }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -192,8 +192,8 @@ First written: 2020/7/20
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td class="align-middle">{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
<td class="align-middle">{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
||||||
<td class="text-right align-middle font-italic {% if assets.balance < 0 %} text-danger {% endif %}">
|
<td class="text-right align-middle font-italic {% if assets.amount < 0 %} text-danger {% endif %}">
|
||||||
{{ assets.balance|accounting_amount }}
|
{{ assets.amount|accounting_amount }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -205,8 +205,8 @@ First written: 2020/7/20
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td class="align-middle">{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
<td class="align-middle">{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
||||||
<td class="text-right align-middle font-italic {% if liabilities.balance|add:owners_equity.balance < 0 %} text-danger {% endif %}">
|
<td class="text-right align-middle font-italic {% if liabilities.amount|add:owners_equity.amount < 0 %} text-danger {% endif %}">
|
||||||
{{ liabilities.balance|add:owners_equity.balance|accounting_amount }}
|
{{ liabilities.amount|add:owners_equity.amount|accounting_amount }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -236,8 +236,8 @@ First written: 2020/7/20
|
|||||||
<a class="list-group-item-action" href="{{ item.url }}">
|
<a class="list-group-item-action" href="{{ item.url }}">
|
||||||
{{ item.title|title }}
|
{{ item.title|title }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if item.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
<span class="badge {% if item.amount < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
||||||
{{ item.balance|accounting_amount }}
|
{{ item.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@ -246,8 +246,8 @@ First written: 2020/7/20
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center grand-total">
|
<li class="list-group-item d-flex justify-content-between align-items-center grand-total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<span class="badge {% if assets.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if assets.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ assets.balance|accounting_amount }}
|
{{ assets.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -267,8 +267,8 @@ First written: 2020/7/20
|
|||||||
<a class="list-group-item-action" href="{{ item.url }}">
|
<a class="list-group-item-action" href="{{ item.url }}">
|
||||||
{{ item.title|title }}
|
{{ item.title|title }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if item.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
<span class="badge {% if item.amount < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
||||||
{{ item.balance|accounting_amount }}
|
{{ item.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@ -277,8 +277,8 @@ First written: 2020/7/20
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<span class="badge {% if liabilities.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if liabilities.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ liabilities.balance|accounting_amount }}
|
{{ liabilities.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -297,8 +297,8 @@ First written: 2020/7/20
|
|||||||
<a class="list-group-item-action" href="{{ item.url }}">
|
<a class="list-group-item-action" href="{{ item.url }}">
|
||||||
{{ item.title|title }}
|
{{ item.title|title }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if item.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
<span class="badge {% if item.amount < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
||||||
{{ item.balance|accounting_amount }}
|
{{ item.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@ -307,8 +307,8 @@ First written: 2020/7/20
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<span class="badge {% if owners_equity.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if owners_equity.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ owners_equity.balance|accounting_amount }}
|
{{ owners_equity.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -316,8 +316,8 @@ First written: 2020/7/20
|
|||||||
<ul class="list-group balance-sheet-list">
|
<ul class="list-group balance-sheet-list">
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center grand-total">
|
<li class="list-group-item d-flex justify-content-between align-items-center grand-total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<span class="badge {% if liabilities.balance|add:owners_equity.balance < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if liabilities.amount|add:owners_equity.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ liabilities.balance|add:owners_equity.balance|accounting_amount }}
|
{{ liabilities.amount|add:owners_equity.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -106,7 +106,7 @@ First written: 2020/7/19
|
|||||||
{% for item in group.details %}
|
{% for item in group.details %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div class="account">{{ item.title|title }}</div></td>
|
<td><div class="account">{{ item.title|title }}</div></td>
|
||||||
<td class="amount {% if item.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
|
<td class="amount {% if item.amount < 0 %} text-danger {% endif %}">{{ item.amount|accounting_amount }}</td>
|
||||||
<td class="amount"></td>
|
<td class="amount"></td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
|
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
|
||||||
@ -119,7 +119,7 @@ First written: 2020/7/19
|
|||||||
<tr class="total">
|
<tr class="total">
|
||||||
<td><div>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</div></td>
|
<td><div>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</div></td>
|
||||||
<td class="amount"></td>
|
<td class="amount"></td>
|
||||||
<td class="amount {% if group.total < 0 %} text-danger {% endif %}">{{ group.total|accounting_amount }}</td>
|
<td class="amount {% if group.amount < 0 %} text-danger {% endif %}">{{ group.amount|accounting_amount }}</td>
|
||||||
<td class="actions"></td>
|
<td class="actions"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -135,7 +135,7 @@ First written: 2020/7/19
|
|||||||
<tr class="cumulative-total">
|
<tr class="cumulative-total">
|
||||||
<td><div>{{ section.cumulative_total.title|title }}</div></td>
|
<td><div>{{ section.cumulative_total.title|title }}</div></td>
|
||||||
<td class="amount"></td>
|
<td class="amount"></td>
|
||||||
<td class="amount {% if section.cumulative_total.total < 0 %} text-danger {% endif %}">{{ section.cumulative_total.total|accounting_amount }}</td>
|
<td class="amount {% if section.cumulative_total.amount < 0 %} text-danger {% endif %}">{{ section.cumulative_total.amount|accounting_amount }}</td>
|
||||||
<td class="actions"></td>
|
<td class="actions"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -172,8 +172,8 @@ First written: 2020/7/19
|
|||||||
<a class="list-group-item-action" href="{% url "accounting:ledger" item period %}">
|
<a class="list-group-item-action" href="{% url "accounting:ledger" item period %}">
|
||||||
{{ item.title|title }}
|
{{ item.title|title }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if item.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
<span class="badge {% if item.amount < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
|
||||||
{{ item.balance|accounting_amount }}
|
{{ item.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@ -182,8 +182,8 @@ First written: 2020/7/19
|
|||||||
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if group.total < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if group.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ group.total|accounting_amount }}
|
{{ group.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@ -192,7 +192,7 @@ First written: 2020/7/19
|
|||||||
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
<li class="list-group-item d-flex justify-content-between align-items-center total">
|
||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if group.total < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">-</span>
|
<span class="badge {% if group.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">-</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -200,8 +200,8 @@ First written: 2020/7/19
|
|||||||
<li class="list-group-item d-flex justify-content-between align-items-center cumulative-total">
|
<li class="list-group-item d-flex justify-content-between align-items-center cumulative-total">
|
||||||
{{ section.cumulative_total.title|title }}
|
{{ section.cumulative_total.title|title }}
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span class="badge {% if section.cumulative_total.total < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
<span class="badge {% if section.cumulative_total.amount < 0 %} badge-danger {% else %} badge-info {% endif %} badge-pill">
|
||||||
{{ section.cumulative_total.total|accounting_amount }}
|
{{ section.cumulative_total.amount|accounting_amount }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -95,8 +95,8 @@ First written: 2020/7/19
|
|||||||
{% for item in item_list %}
|
{% for item in item_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ item.title|title }}</td>
|
<td>{{ item.title|title }}</td>
|
||||||
<td class="amount">{{ item.debit|accounting_amount }}</td>
|
<td class="amount">{{ item.debit_amount|accounting_amount }}</td>
|
||||||
<td class="amount">{{ item.credit|accounting_amount }}</td>
|
<td class="amount">{{ item.credit_amount|accounting_amount }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
|
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
@ -109,8 +109,8 @@ First written: 2020/7/19
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
<td>{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}</td>
|
||||||
<td class="amount">{{ total_item.debit|accounting_amount }}</td>
|
<td class="amount">{{ total_item.debit_amount|accounting_amount }}</td>
|
||||||
<td class="amount">{{ total_item.credit|accounting_amount }}</td>
|
<td class="amount">{{ total_item.credit_amount|accounting_amount }}</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -133,14 +133,14 @@ First written: 2020/7/19
|
|||||||
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" item period %}">
|
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" item period %}">
|
||||||
{{ item.title|title }}
|
{{ item.title|title }}
|
||||||
<div>
|
<div>
|
||||||
{% if item.debit is not None %}
|
{% if item.debit_amount is not None %}
|
||||||
<span class="badge badge-success badge-pill">
|
<span class="badge badge-success badge-pill">
|
||||||
{{ item.debit|intcomma:False }}
|
{{ item.debit_amount|intcomma:False }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.credit is not None %}
|
{% if item.credit_amount is not None %}
|
||||||
<span class="badge badge-warning badge-pill">
|
<span class="badge badge-warning badge-pill">
|
||||||
{{ item.credit|intcomma:False }}
|
{{ item.credit_amount|intcomma:False }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
@ -151,10 +151,10 @@ First written: 2020/7/19
|
|||||||
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
{% trans "Total" context "Accounting|" as text %}{{ text|force_escape }}
|
||||||
<div>
|
<div>
|
||||||
<span class="badge badge-success badge-pill">
|
<span class="badge badge-success badge-pill">
|
||||||
{{ total_item.debit|intcomma:False }}
|
{{ total_item.debit_amount|intcomma:False }}
|
||||||
</span>
|
</span>
|
||||||
<span class="badge badge-warning badge-pill">
|
<span class="badge badge-warning badge-pill">
|
||||||
{{ total_item.credit|intcomma:False }}
|
{{ total_item.credit_amount|intcomma:False }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -514,16 +514,16 @@ def trial_balance(request, period):
|
|||||||
| Q(code__startswith="2")
|
| Q(code__startswith="2")
|
||||||
| Q(code__startswith="3")))
|
| Q(code__startswith="3")))
|
||||||
.annotate(
|
.annotate(
|
||||||
balance=Sum(Case(
|
amount=Sum(Case(
|
||||||
When(record__is_credit=True, then=-1),
|
When(record__is_credit=True, then=-1),
|
||||||
default=1) * F("record__amount")))
|
default=1) * F("record__amount")))
|
||||||
.filter(balance__isnull=False)
|
.filter(amount__isnull=False)
|
||||||
.annotate(
|
.annotate(
|
||||||
debit=Case(
|
debit_amount=Case(
|
||||||
When(balance__gt=0, then=F("balance")),
|
When(amount__gt=0, then=F("amount")),
|
||||||
default=None),
|
default=None),
|
||||||
credit=Case(
|
credit_amount=Case(
|
||||||
When(balance__lt=0, then=-F("balance")),
|
When(amount__lt=0, then=-F("amount")),
|
||||||
default=None))
|
default=None))
|
||||||
.order_by("code"))
|
.order_by("code"))
|
||||||
real = list(
|
real = list(
|
||||||
@ -535,16 +535,16 @@ def trial_balance(request, period):
|
|||||||
| Q(code__startswith="3")),
|
| Q(code__startswith="3")),
|
||||||
~Q(code=Account.ACCUMULATED_BALANCE))
|
~Q(code=Account.ACCUMULATED_BALANCE))
|
||||||
.annotate(
|
.annotate(
|
||||||
balance=Sum(Case(
|
amount=Sum(Case(
|
||||||
When(record__is_credit=True, then=-1),
|
When(record__is_credit=True, then=-1),
|
||||||
default=1) * F("record__amount")))
|
default=1) * F("record__amount")))
|
||||||
.filter(balance__isnull=False)
|
.filter(amount__isnull=False)
|
||||||
.annotate(
|
.annotate(
|
||||||
debit=Case(
|
debit_amount=Case(
|
||||||
When(balance__gt=0, then=F("balance")),
|
When(amount__gt=0, then=F("amount")),
|
||||||
default=None),
|
default=None),
|
||||||
credit=Case(
|
credit_amount=Case(
|
||||||
When(balance__lt=0, then=-F("balance")),
|
When(amount__lt=0, then=-F("amount")),
|
||||||
default=None))
|
default=None))
|
||||||
.order_by("code"))
|
.order_by("code"))
|
||||||
balance = Record.objects \
|
balance = Record.objects \
|
||||||
@ -563,20 +563,20 @@ def trial_balance(request, period):
|
|||||||
brought_forward = Account.objects.get(
|
brought_forward = Account.objects.get(
|
||||||
code=Account.ACCUMULATED_BALANCE)
|
code=Account.ACCUMULATED_BALANCE)
|
||||||
if balance > 0:
|
if balance > 0:
|
||||||
brought_forward.debit = balance
|
brought_forward.debit_amount = balance
|
||||||
brought_forward.credit = 0
|
brought_forward.credit_amount = None
|
||||||
else:
|
else:
|
||||||
brought_forward.debit = None
|
brought_forward.debit_amount = None
|
||||||
brought_forward.credit = -balance
|
brought_forward.credit_amount = -balance
|
||||||
real.append(brought_forward)
|
real.append(brought_forward)
|
||||||
accounts = nominal + real
|
accounts = nominal + real
|
||||||
accounts.sort(key=lambda x: x.code)
|
accounts.sort(key=lambda x: x.code)
|
||||||
total_account = Account()
|
total_account = Account()
|
||||||
total_account.title = pgettext("Accounting|", "Total")
|
total_account.title = pgettext("Accounting|", "Total")
|
||||||
total_account.debit = sum([x.debit for x in accounts
|
total_account.debit_amount = sum([x.debit_amount for x in accounts
|
||||||
if x.debit is not None])
|
if x.debit_amount is not None])
|
||||||
total_account.credit = sum([x.credit for x in accounts
|
total_account.credit_amount = sum([x.credit_amount for x in accounts
|
||||||
if x.credit is not None])
|
if x.credit_amount is not None])
|
||||||
return render(request, "accounting/trial-balance.html", {
|
return render(request, "accounting/trial-balance.html", {
|
||||||
"item_list": accounts,
|
"item_list": accounts,
|
||||||
"total_item": total_account,
|
"total_item": total_account,
|
||||||
@ -619,10 +619,10 @@ def income_statement(request, period):
|
|||||||
| Q(code__startswith="2")
|
| Q(code__startswith="2")
|
||||||
| Q(code__startswith="3")))
|
| Q(code__startswith="3")))
|
||||||
.annotate(
|
.annotate(
|
||||||
balance=Sum(Case(
|
amount=Sum(Case(
|
||||||
When(record__is_credit=True, then=1),
|
When(record__is_credit=True, then=1),
|
||||||
default=-1) * F("record__amount")))
|
default=-1) * F("record__amount")))
|
||||||
.filter(balance__isnull=False)
|
.filter(amount__isnull=False)
|
||||||
.order_by("code"))
|
.order_by("code"))
|
||||||
groups = list(Account.objects.filter(
|
groups = list(Account.objects.filter(
|
||||||
code__in=[x.code[:2] for x in accounts]))
|
code__in=[x.code[:2] for x in accounts]))
|
||||||
@ -643,17 +643,14 @@ def income_statement(request, period):
|
|||||||
for group in section.groups:
|
for group in section.groups:
|
||||||
group.details = [x for x in accounts
|
group.details = [x for x in accounts
|
||||||
if x.code[:2] == group.code]
|
if x.code[:2] == group.code]
|
||||||
group.balance = None
|
group.amount = sum([x.amount
|
||||||
group.total = sum([x.balance
|
for x in group.details])
|
||||||
for x in group.details])
|
section.amount = sum([x.amount for x in section.groups])
|
||||||
section.balance = None
|
cumulative_total = cumulative_total + section.amount
|
||||||
section.total = sum([x.total for x in section.groups])
|
|
||||||
cumulative_total = cumulative_total + section.total
|
|
||||||
if section.code in cumulative_accounts:
|
if section.code in cumulative_accounts:
|
||||||
section.cumulative_total \
|
section.cumulative_total \
|
||||||
= cumulative_accounts[section.code]
|
= cumulative_accounts[section.code]
|
||||||
section.cumulative_total.balance = None
|
section.cumulative_total.amount = cumulative_total
|
||||||
section.cumulative_total.total = cumulative_total
|
|
||||||
else:
|
else:
|
||||||
section.cumulative_total = None
|
section.cumulative_total = None
|
||||||
section.has_next = True
|
section.has_next = True
|
||||||
@ -699,10 +696,10 @@ def balance_sheet(request, period):
|
|||||||
| Q(code__startswith="3")),
|
| Q(code__startswith="3")),
|
||||||
~Q(code=Account.ACCUMULATED_BALANCE))
|
~Q(code=Account.ACCUMULATED_BALANCE))
|
||||||
.annotate(
|
.annotate(
|
||||||
balance=Sum(Case(
|
amount=Sum(Case(
|
||||||
When(record__is_credit=True, then=-1),
|
When(record__is_credit=True, then=-1),
|
||||||
default=1) * F("record__amount")))
|
default=1) * F("record__amount")))
|
||||||
.filter(balance__isnull=False)
|
.filter(amount__isnull=False)
|
||||||
.order_by("code"))
|
.order_by("code"))
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
account.url = reverse("accounting:ledger", args=(account, period))
|
account.url = reverse("accounting:ledger", args=(account, period))
|
||||||
@ -720,7 +717,7 @@ def balance_sheet(request, period):
|
|||||||
if balance is not None and balance != 0:
|
if balance is not None and balance != 0:
|
||||||
brought_forward = Account.objects.get(
|
brought_forward = Account.objects.get(
|
||||||
code=Account.ACCUMULATED_BALANCE)
|
code=Account.ACCUMULATED_BALANCE)
|
||||||
brought_forward.balance = balance
|
brought_forward.amount = balance
|
||||||
brought_forward.url = reverse(
|
brought_forward.url = reverse(
|
||||||
"accounting:income-statement", args=(period,))
|
"accounting:income-statement", args=(period,))
|
||||||
accounts.append(brought_forward)
|
accounts.append(brought_forward)
|
||||||
@ -738,12 +735,12 @@ def balance_sheet(request, period):
|
|||||||
default=1) * F("amount")))["balance"]
|
default=1) * F("amount")))["balance"]
|
||||||
if balance is not None and balance != 0:
|
if balance is not None and balance != 0:
|
||||||
net_change = Account.objects.get(code=Account.NET_CHANGE)
|
net_change = Account.objects.get(code=Account.NET_CHANGE)
|
||||||
net_change.balance = balance
|
net_change.amount = balance
|
||||||
net_change.url = reverse(
|
net_change.url = reverse(
|
||||||
"accounting:income-statement", args=(period,))
|
"accounting:income-statement", args=(period,))
|
||||||
accounts.append(net_change)
|
accounts.append(net_change)
|
||||||
for account in [x for x in accounts if x.code[0] in "23"]:
|
for account in [x for x in accounts if x.code[0] in "23"]:
|
||||||
account.balance = -account.balance
|
account.amount = -account.amount
|
||||||
groups = list(Account.objects.filter(
|
groups = list(Account.objects.filter(
|
||||||
code__in=[x.code[:2] for x in accounts]))
|
code__in=[x.code[:2] for x in accounts]))
|
||||||
sections = list(Account.objects.filter(
|
sections = list(Account.objects.filter(
|
||||||
@ -754,9 +751,9 @@ def balance_sheet(request, period):
|
|||||||
for group in section.groups:
|
for group in section.groups:
|
||||||
group.details = [x for x in accounts
|
group.details = [x for x in accounts
|
||||||
if x.code[:2] == group.code]
|
if x.code[:2] == group.code]
|
||||||
group.balance = sum([x.balance
|
group.amount = sum([x.amount
|
||||||
for x in group.details])
|
for x in group.details])
|
||||||
section.balance = sum([x.balance for x in section.groups])
|
section.amount = sum([x.amount for x in section.groups])
|
||||||
by_code = {x.code: x for x in sections}
|
by_code = {x.code: x for x in sections}
|
||||||
return render(request, "accounting/balance-sheet.html", {
|
return render(request, "accounting/balance-sheet.html", {
|
||||||
"assets": by_code["1"],
|
"assets": by_code["1"],
|
||||||
|
Loading…
Reference in New Issue
Block a user