Moved getting the ReportUrl utility from the views to the report chooser template, to simplify the view in the accounting application.

This commit is contained in:
依瑪貓 2020-08-07 10:25:29 +08:00
parent 45ed53b085
commit 4f02dd88da
12 changed files with 25 additions and 30 deletions

View File

@ -37,7 +37,6 @@ First written: 2020/7/1
<i class="fas fa-plus"></i> <i class="fas fa-plus"></i>
{{ _("New")|force_escape }} {{ _("New")|force_escape }}
</a> </a>
{% report_url as reports %}
{% with current_report_icon="fas fa-list-ol" current_report_title=_("Accounts") %} {% with current_report_icon="fas fa-list-ol" current_report_title=_("Accounts") %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}

View File

@ -53,7 +53,7 @@ First written: 2020/7/20
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-balance-scale" current_report_title=_("Balance Sheet") %} {% with current_report_icon="fas fa-balance-scale" current_report_title=_("Balance Sheet") period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">

View File

@ -52,7 +52,7 @@ First written: 2020/7/15
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Summary") %} {% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Summary") cash_account=account %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">

View File

@ -53,7 +53,7 @@ First written: 2020/7/1
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Account") %} {% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Account") cash_account=account period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">

View File

@ -20,6 +20,7 @@ Author: imacat@mail.imacat.idv.tw (imacat)
First written: 2020/7/9 First written: 2020/7/9
{% endcomment %} {% endcomment %}
{% load i18n %} {% load i18n %}
{% load accounting %}
<!-- the accounting record search dialog --> <!-- the accounting record search dialog -->
<form action="{% url "accounting:search" %}" method="GET"> <form action="{% url "accounting:search" %}" method="GET">
@ -61,36 +62,37 @@ First written: 2020/7/9
</span> </span>
<span class="d-md-none">{{ _("Book")|force_escape }}</span> <span class="d-md-none">{{ _("Book")|force_escape }}</span>
</button> </button>
{% report_url cash_account=cash_account ledger_account=ledger_account period=period as report_url %}
<div class="dropdown-menu account-picker"> <div class="dropdown-menu account-picker">
<a class="dropdown-item {% if request.resolver_match.url_name == "cash" %} active {% endif %}" href="{{ reports.cash }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "cash" %} active {% endif %}" href="{{ report_url.cash }}">
<i class="fas fa-money-bill-wave"></i> <i class="fas fa-money-bill-wave"></i>
{{ _("Cash Account")|force_escape }} {{ _("Cash Account")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "cash-summary" %} active {% endif %}" href="{{ reports.cash_summary }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "cash-summary" %} active {% endif %}" href="{{ report_url.cash_summary }}">
<i class="fas fa-money-bill-wave"></i> <i class="fas fa-money-bill-wave"></i>
{{ _("Cash Summary")|force_escape }} {{ _("Cash Summary")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "ledger" %} active {% endif %}" href="{{ reports.ledger }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "ledger" %} active {% endif %}" href="{{ report_url.ledger }}">
<i class="fas fa-file-invoice-dollar"></i> <i class="fas fa-file-invoice-dollar"></i>
{{ _("Ledger")|force_escape }} {{ _("Ledger")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "ledger-summary" %} active {% endif %}" href="{{ reports.ledger_summary }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "ledger-summary" %} active {% endif %}" href="{{ report_url.ledger_summary }}">
<i class="fas fa-file-invoice-dollar"></i> <i class="fas fa-file-invoice-dollar"></i>
{{ _("Ledger Summary")|force_escape }} {{ _("Ledger Summary")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "journal" %} active {% endif %}" href="{{ reports.journal }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "journal" %} active {% endif %}" href="{{ report_url.journal }}">
<i class="fas fa-book"></i> <i class="fas fa-book"></i>
{{ _("Journal")|force_escape }} {{ _("Journal")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "trial-balance" %} active {% endif %}" href="{{ reports.trial_balance }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "trial-balance" %} active {% endif %}" href="{{ report_url.trial_balance }}">
<i class="fas fa-balance-scale-right"></i> <i class="fas fa-balance-scale-right"></i>
{{ _("Trial Balance")|force_escape }} {{ _("Trial Balance")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "income-statement" %} active {% endif %}" href="{{ reports.income_statement }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "income-statement" %} active {% endif %}" href="{{ report_url.income_statement }}">
<i class="fas fa-file-invoice"></i> <i class="fas fa-file-invoice"></i>
{{ _("Income Statement")|force_escape }} {{ _("Income Statement")|force_escape }}
</a> </a>
<a class="dropdown-item {% if request.resolver_match.url_name == "balance-sheet" %} active {% endif %}" href="{{ reports.balance_sheet }}"> <a class="dropdown-item {% if request.resolver_match.url_name == "balance-sheet" %} active {% endif %}" href="{{ report_url.balance_sheet }}">
<i class="fas fa-balance-scale"></i> <i class="fas fa-balance-scale"></i>
{{ _("Balance Sheet")|force_escape }} {{ _("Balance Sheet")|force_escape }}
</a> </a>

View File

@ -53,7 +53,7 @@ First written: 2020/7/19
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-file-invoice" current_report_title=_("Income Statement") %} {% with current_report_icon="fas fa-file-invoice" current_report_title=_("Income Statement") period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">

View File

@ -53,7 +53,7 @@ First written: 2020/7/17
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-book" current_report_title=_("Journal") %} {% with current_report_icon="fas fa-book" current_report_title=_("Journal") period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">

View File

@ -52,7 +52,7 @@ First written: 2020/7/16
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger Summary") %} {% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger Summary") ledger_account=account %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">

View File

@ -53,7 +53,7 @@ First written: 2020/7/16
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger") %} {% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger") ledger_account=account period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<div class="btn-group"> <div class="btn-group">

View File

@ -53,7 +53,7 @@ First written: 2020/7/19
</a> </a>
</div> </div>
</div> </div>
{% with current_report_icon="fas fa-balance-scale-right" current_report_title=_("Trial Balance") %} {% with current_report_icon="fas fa-balance-scale-right" current_report_title=_("Trial Balance") period=period %}
{% include "accounting/include/report-chooser.html" %} {% include "accounting/include/report-chooser.html" %}
{% endwith %} {% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">

View File

@ -47,15 +47,18 @@ def accounting_amount(value):
@register.simple_tag @register.simple_tag
def report_url(cash=None, ledger=None, period=None): def report_url(cash_account, ledger_account, period):
"""Returns accounting report URL helper. """Returns accounting report URL helper.
Args: Args:
cash (Account): The current cash account. cash_account (Account): The current cash account.
ledger (Account): The current ledger account. ledger_account (Account): The current ledger account.
period (Period): The period. period (Period): The period.
Returns: Returns:
ReportUrl: The accounting report URL helper. ReportUrl: The accounting report URL helper.
""" """
return ReportUrl(cash=cash, ledger=ledger, period=period) return ReportUrl(
cash=cash_account or None,
ledger=ledger_account or None,
period=period or None)

View File

@ -163,7 +163,6 @@ def cash(request, account, period):
"pagination": pagination, "pagination": pagination,
"account": account, "account": account,
"period": period, "period": period,
"reports": ReportUrl(cash=account, period=period),
"shortcut_accounts": [x for x in accounts "shortcut_accounts": [x for x in accounts
if x.code in shortcut_accounts], if x.code in shortcut_accounts],
"all_accounts": [x for x in accounts "all_accounts": [x for x in accounts
@ -263,7 +262,6 @@ def cash_summary(request, account):
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"account": account, "account": account,
"reports": ReportUrl(cash=account),
"shortcut_accounts": [x for x in accounts if "shortcut_accounts": [x for x in accounts if
x.code in shortcut_accounts], x.code in shortcut_accounts],
"all_accounts": [x for x in accounts if "all_accounts": [x for x in accounts if
@ -347,7 +345,6 @@ def ledger(request, account, period):
"pagination": pagination, "pagination": pagination,
"account": account, "account": account,
"period": period, "period": period,
"reports": ReportUrl(ledger=account, period=period),
"accounts": get_ledger_accounts(), "accounts": get_ledger_accounts(),
}) })
@ -412,7 +409,6 @@ def ledger_summary(request, account):
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"account": account, "account": account,
"reports": ReportUrl(ledger=account),
"accounts": get_ledger_accounts(), "accounts": get_ledger_accounts(),
}) })
@ -496,7 +492,6 @@ def journal(request, period):
return render(request, "accounting/journal.html", { return render(request, "accounting/journal.html", {
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"reports": ReportUrl(period=period),
"period": period, "period": period,
}) })
@ -601,7 +596,6 @@ def trial_balance(request, period):
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,
"reports": ReportUrl(period=period),
"period": period, "period": period,
}) })
@ -678,7 +672,6 @@ def income_statement(request, period):
sections[-1].has_next = False sections[-1].has_next = False
return render(request, "accounting/income-statement.html", { return render(request, "accounting/income-statement.html", {
"item_list": sections, "item_list": sections,
"reports": ReportUrl(period=period),
"period": period, "period": period,
}) })
@ -780,7 +773,6 @@ def balance_sheet(request, period):
"assets": by_code["1"], "assets": by_code["1"],
"liabilities": by_code["2"], "liabilities": by_code["2"],
"owners_equity": by_code["3"], "owners_equity": by_code["3"],
"reports": ReportUrl(period=period),
"period": period, "period": period,
}) })
@ -813,7 +805,6 @@ def search(request):
return render(request, "accounting/search.html", { return render(request, "accounting/search.html", {
"item_list": pagination.items, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"reports": ReportUrl(),
}) })