Changed the URL of the accounts in the balance sheet so that the net income in the current period links to the income statement in the accounting application.

This commit is contained in:
依瑪貓 2020-07-21 13:38:18 +08:00
parent 3c294ffcb8
commit bbfe9e7892
3 changed files with 24 additions and 7 deletions

View File

@ -67,6 +67,16 @@ class Account(models.Model):
def title(self, value): def title(self, value):
self._title = value self._title = value
_url = None
@property
def url(self):
return self._url
@url.setter
def url(self, value):
self._url = value
class Meta: class Meta:
db_table = "accounting_accounts" db_table = "accounting_accounts"
ordering = ["code"] ordering = ["code"]

View File

@ -100,7 +100,7 @@ First written: 2020/7/20
<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.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" 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>
{% trans "View" context "Accounting|" as text %}{{ text|force_escape }} {% trans "View" context "Accounting|" as text %}{{ text|force_escape }}
</a> </a>
@ -131,7 +131,7 @@ First written: 2020/7/20
<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.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" 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>
{% trans "View" context "Accounting|" as text %}{{ text|force_escape }} {% trans "View" context "Accounting|" as text %}{{ text|force_escape }}
</a> </a>
@ -168,7 +168,7 @@ First written: 2020/7/20
<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.balance < 0 %} text-danger {% endif %}">{{ item.balance|accounting_amount }}</td>
<td class="actions"> <td class="actions">
<a href="{% url "accounting:ledger" item.code period.spec %}" 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>
{% trans "View" context "Accounting|" as text %}{{ text|force_escape }} {% trans "View" context "Accounting|" as text %}{{ text|force_escape }}
</a> </a>
@ -236,7 +236,7 @@ First written: 2020/7/20
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center account"> <li class="list-group-item d-flex justify-content-between align-items-center account">
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <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.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
@ -267,7 +267,7 @@ First written: 2020/7/20
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center account"> <li class="list-group-item d-flex justify-content-between align-items-center account">
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <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.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">
@ -296,8 +296,8 @@ First written: 2020/7/20
</li> </li>
{% for item in group.details %} {% for item in group.details %}
<li class="list-group-item d-flex justify-content-between align-items-center account"> <li class="list-group-item d-flex justify-content-between align-items-center account">
{# TODO: Link to the income statement for account #3353 #} {# TODO: Link to the income statement for account #3351 #}
<a class="list-group-item-action" href="{% url "accounting:ledger" item.code period.spec %}"> <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.balance < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">

View File

@ -738,6 +738,9 @@ def balance_sheet(request, period_spec):
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(balance__isnull=False))
for account in accounts:
account.url = reverse(
"accounting:ledger", args=[account.code, period.spec])
balance = Record.objects\ balance = Record.objects\
.filter( .filter(
Q(transaction__date__lt=period.start) Q(transaction__date__lt=period.start)
@ -752,6 +755,8 @@ def balance_sheet(request, period_spec):
if balance is not None and balance != 0: if balance is not None and balance != 0:
brought_forward = Account.objects.get(code="3351") brought_forward = Account.objects.get(code="3351")
brought_forward.balance = -balance brought_forward.balance = -balance
brought_forward.url = reverse(
"accounting:income-statement", args=[period.spec])
accounts.append(brought_forward) accounts.append(brought_forward)
balance = Record.objects\ balance = Record.objects\
.filter( .filter(
@ -768,6 +773,8 @@ def balance_sheet(request, period_spec):
if balance is not None and balance != 0: if balance is not None and balance != 0:
net_income = Account.objects.get(code="3353") net_income = Account.objects.get(code="3353")
net_income.balance = -balance net_income.balance = -balance
net_income.url = reverse(
"accounting:income-statement", args=[period.spec])
accounts.append(net_income) accounts.append(net_income)
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]))