Replaced the account and period template variables with the resolver matches from the request, reducing the variables passed from the view to the templates in the accounting application.

This commit is contained in:
依瑪貓 2020-08-08 13:43:11 +08:00
parent d23d7a9c60
commit c7e1fd323d
9 changed files with 72 additions and 70 deletions

View File

@ -27,7 +27,7 @@ First written: 2020/7/20
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with prep_period=period.prep_desc %}Balance Sheet {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with prep_period=request.resolver_match.kwargs.period.prep_desc %}Balance Sheet {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,17 +53,19 @@ First written: 2020/7/20
</a>
</div>
</div>
{% with current_report_icon="fas fa-balance-scale" current_report_title=_("Balance Sheet") period=period %}
{% with current_report_icon="fas fa-balance-scale" current_report_title=_("Balance Sheet") period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{# The table for large screens #}
<div class="d-none d-lg-block report-block report-block-lg">

View File

@ -27,7 +27,7 @@ First written: 2020/7/15
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with account=account.title %}Cash Summary for {{ account }}{% endblocktrans %}
{% blocktrans asvar title with account=request.resolver_match.kwargs.account.title %}Cash Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
@ -52,25 +52,25 @@ First written: 2020/7/15
</a>
</div>
</div>
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Summary") cash_account=account %}
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Summary") cash_account=request.resolver_match.kwargs.account %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ account.title|title_case }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.account.title|title_case }}</span>
<span class="d-md-none">{{ _("Account")|force_escape }}</span>
</button>
<div class="dropdown-menu account-picker">
<div class="dropdown-header">{{ _("Shortcuts")|force_escape }}</div>
{% for x in shortcut_accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" x %}">
{{ x.title|title_case }}
{% for account in shortcut_accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account %}">
{{ account.title|title_case }}
</a>
{% endfor %}
<div class="dropdown-header">{{ _("All")|force_escape }}</div>
{% for x in all_accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" x %}">
{{ x.code }} {{ x.title|title_case }}
{% for account in all_accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}>" href="{% url "accounting:cash-summary" account %}">
{{ account.code }} {{ account.title|title_case }}
</a>
{% endfor %}
</div>
@ -102,7 +102,7 @@ First written: 2020/7/15
<td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td>
<td class="actions">
{% if item.month is not None %}
<a class="btn btn-info" role="button" href="{% url "accounting:cash" account item.month|date:"Y-m" %}">
<a class="btn btn-info" role="button" href="{% url "accounting:cash" request.resolver_match.kwargs.account item.month|date:"Y-m" %}">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -118,7 +118,7 @@ First written: 2020/7/15
{% for item in item_list %}
<li class="list-group-item {% if item.balance < 0 %} list-group-item-danger {% endif %}">
{% if item.month is not None %}
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:cash" account item.month|date:"Y-m" %}">
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:cash" request.resolver_match.kwargs.account item.month|date:"Y-m" %}">
{{ item.label }}
<div>
<span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/1
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with account=account.title prep_period=period.prep_desc %}Cash Account for {{ account }} {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with account=request.resolver_match.kwargs.account.title prep_period=request.resolver_match.kwargs.period.prep_desc %}Cash Account for {{ account }} {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,37 +53,39 @@ First written: 2020/7/1
</a>
</div>
</div>
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Account") cash_account=account period=period %}
{% with current_report_icon="fas fa-money-bill-wave" current_report_title=_("Cash Account") cash_account=request.resolver_match.kwargs.account period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ account.title|title_case }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.account.title|title_case }}</span>
<span class="d-md-none">{{ _("Account")|force_escape }}</span>
</button>
<div class="dropdown-menu account-picker">
<div class="dropdown-header">{{ _("Shortcuts")|force_escape }}</div>
{% for x in shortcut_accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}>" href="{% url "accounting:cash" x period %}">
{{ x.title|title_case }}
{% for account in shortcut_accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}>" href="{% url "accounting:cash" account request.resolver_match.kwargs.period %}">
{{ account.title|title_case }}
</a>
{% endfor %}
<div class="dropdown-header">{{ _("All")|force_escape }}</div>
{% for x in all_accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}>" href="{% url "accounting:cash" x period %}">
{{ x.code }} {{ x.title|title_case }}
{% for account in all_accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}>" href="{% url "accounting:cash" account request.resolver_match.kwargs.period %}">
{{ account.code }} {{ account.title|title_case }}
</a>
{% endfor %}
</div>
</div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{% if item_list %}
{% include "mia_core/include/pagination.html" %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/19
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with prep_period=period.prep_desc %}Income Statement {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with prep_period=request.resolver_match.kwargs.period.prep_desc %}Income Statement {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,17 +53,19 @@ First written: 2020/7/19
</a>
</div>
</div>
{% with current_report_icon="fas fa-file-invoice" current_report_title=_("Income Statement") period=period %}
{% with current_report_icon="fas fa-file-invoice" current_report_title=_("Income Statement") period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{# The table for large screens #}
<div class="d-none d-sm-block report-block report-block-lg">
@ -103,7 +105,7 @@ First written: 2020/7/19
<td class="amount {% if item.amount < 0 %} text-danger {% endif %}">{{ item.amount|accounting_amount }}</td>
<td class="amount"></td>
<td class="actions">
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
<a href="{% url "accounting:ledger" item request.resolver_match.kwargs.period %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -163,7 +165,7 @@ First written: 2020/7/19
</li>
{% for item in group.details %}
<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 period %}">
<a class="list-group-item-action" href="{% url "accounting:ledger" item request.resolver_match.kwargs.period %}">
{{ item.title|title_case }}
<div class="float-right">
<span class="badge {% if item.amount < 0 %} badge-warning {% else %} badge-secondary {% endif %} badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/17
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with prep_period=period.prep_desc %}Journal {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with prep_period=request.resolver_match.kwargs.period.prep_desc %}Journal {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,17 +53,19 @@ First written: 2020/7/17
</a>
</div>
</div>
{% with current_report_icon="fas fa-book" current_report_title=_("Journal") period=period %}
{% with current_report_icon="fas fa-book" current_report_title=_("Journal") period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{% if item_list %}
{% include "mia_core/include/pagination.html" %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with account=account.title %}Ledger Summary for {{ account }}{% endblocktrans %}
{% blocktrans asvar title with account=request.resolver_match.kwargs.account.title %}Ledger Summary for {{ account }}{% endblocktrans %}
{% setvar "title" title %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
{% endblock %}
@ -52,18 +52,18 @@ First written: 2020/7/16
</a>
</div>
</div>
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger Summary") ledger_account=account %}
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger Summary") ledger_account=request.resolver_match.kwargs.account %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ account.title|title_case }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.account.title|title_case }}</span>
<span class="d-md-none">{{ _("Account")|force_escape }}</span>
</button>
<div class="dropdown-menu account-picker">
{% for x in accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" x %}">
{{ x.title|title_case }}
{% for account in accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}>" href="{% url "accounting:ledger-summary" account %}">
{{ account.title|title_case }}
</a>
{% endfor %}
</div>
@ -87,7 +87,7 @@ First written: 2020/7/16
</thead>
<tbody>
{% for item in item_list %}
<tr class="{% if account.code|first in "12" and item.balance < 0 %} table-danger {% endif %}">
<tr class="{% if request.resolver_match.kwargs.account.code|first in "12" and item.balance < 0 %} table-danger {% endif %}">
<td>{{ item.label }}</td>
<td class="amount">{{ item.debit|accounting_amount }}</td>
<td class="amount">{{ item.credit|accounting_amount }}</td>
@ -95,7 +95,7 @@ First written: 2020/7/16
<td class="amount {% if item.cumulative_balance < 0 %} text-danger {% endif %}">{{ item.cumulative_balance|accounting_amount }}</td>
<td class="actions">
{% if item.month is not None %}
<a class="btn btn-info" role="button" href="{% url "accounting:ledger" account item.month|date:"Y-m" %}">
<a class="btn btn-info" role="button" href="{% url "accounting:ledger" request.resolver_match.kwargs.account item.month|date:"Y-m" %}">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -109,9 +109,9 @@ First written: 2020/7/16
{# The list for small screens #}
<ul class="list-group d-sm-none">
{% for item in item_list %}
<li class="list-group-item {% if account.code|first in "12" and item.balance < 0 %} list-group-item-danger {% endif %}">
<li class="list-group-item {% if request.resolver_match.kwargs.account.code|first in "12" and item.balance < 0 %} list-group-item-danger {% endif %}">
{% if item.month is not None %}
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" account item.month|date:"Y-m" %}">
<a class="list-group-item-action d-flex justify-content-between align-items-center" href="{% url "accounting:ledger" request.resolver_match.kwargs.account item.month|date:"Y-m" %}">
{{ item.label }}
<div>
<span class="badge badge-success badge-pill">

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with account=account.title prep_period=period.prep_desc %}Ledger for {{ account }} {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with account=request.resolver_match.kwargs.account.title prep_period=request.resolver_match.kwargs.period.prep_desc %}Ledger for {{ account }} {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,30 +53,32 @@ First written: 2020/7/16
</a>
</div>
</div>
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger") ledger_account=account period=period %}
{% with current_report_icon="fas fa-file-invoice-dollar" current_report_title=_("Ledger") ledger_account=request.resolver_match.kwargs.account period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="d-none d-md-inline">{{ account.title|title_case }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.account.title|title_case }}</span>
<span class="d-md-none">{{ _("Account")|force_escape }}</span>
</button>
<div class="dropdown-menu account-picker">
{% for x in accounts %}
<a class="dropdown-item {% if x.code == account.code %} active {% endif %}" href="{% url "accounting:ledger" x period %}">
{{ x.code }} {{ x.title|title_case }}
{% for account in accounts %}
<a class="dropdown-item {% if account.code == request.resolver_match.kwargs.account.code %} active {% endif %}" href="{% url "accounting:ledger" account request.resolver_match.kwargs.period %}">
{{ account.code }} {{ account.title|title_case }}
</a>
{% endfor %}
</div>
</div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{% if item_list %}
{% include "mia_core/include/pagination.html" %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/19
{% load accounting %}
{% block settings %}
{% blocktrans asvar title with prep_period=period.prep_desc %}Trial Balance {{ prep_period }}{% endblocktrans %}
{% blocktrans asvar title with prep_period=request.resolver_match.kwargs.period.prep_desc %}Trial Balance {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %}
{% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %}
@ -53,17 +53,19 @@ First written: 2020/7/19
</a>
</div>
</div>
{% with current_report_icon="fas fa-balance-scale-right" current_report_title=_("Trial Balance") period=period %}
{% with current_report_icon="fas fa-balance-scale-right" current_report_title=_("Trial Balance") period=request.resolver_match.kwargs.period %}
{% include "accounting/include/report-chooser.html" %}
{% endwith %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#period-modal">
<i class="far fa-calendar-alt"></i>
<span class="d-none d-md-inline">{{ period.description }}</span>
<span class="d-none d-md-inline">{{ request.resolver_match.kwargs.period.description }}</span>
<span class="d-md-none">{{ _("Period")|force_escape }}</span>
</button>
</div>
{% include "mia_core/include/period-chooser.html" %}
{% with period=request.resolver_match.kwargs.period %}
{% include "mia_core/include/period-chooser.html" %}
{% endwith %}
{% if item_list %}
{% include "mia_core/include/pagination.html" %}
@ -92,7 +94,7 @@ First written: 2020/7/19
<td class="amount">{{ item.debit_amount|accounting_amount }}</td>
<td class="amount">{{ item.credit_amount|accounting_amount }}</td>
<td class="actions">
<a href="{% url "accounting:ledger" item period %}" class="btn btn-info" role="button">
<a href="{% url "accounting:ledger" item request.resolver_match.kwargs.period %}" class="btn btn-info" role="button">
<i class="fas fa-eye"></i>
<span class="d-none d-lg-inline">{{ _("View")|force_escape }}</span>
</a>
@ -124,7 +126,7 @@ First written: 2020/7/19
<ul class="list-group d-lg-none trial-balance-list">
{% for item in item_list %}
<li class="list-group-item">
<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 request.resolver_match.kwargs.period %}">
{{ item.title|title_case }}
<div>
{% if item.debit_amount is not None %}

View File

@ -162,8 +162,6 @@ def cash(request, account, period):
return render(request, "accounting/cash.html", {
"item_list": records,
"pagination": pagination,
"account": account,
"period": period,
"shortcut_accounts": [x for x in accounts
if x.code in shortcut_accounts],
"all_accounts": [x for x in accounts
@ -262,7 +260,6 @@ def cash_summary(request, account):
return render(request, "accounting/cash-summary.html", {
"item_list": pagination.items,
"pagination": pagination,
"account": account,
"shortcut_accounts": [x for x in accounts if
x.code in shortcut_accounts],
"all_accounts": [x for x in accounts if
@ -344,8 +341,6 @@ def ledger(request, account, period):
return render(request, "accounting/ledger.html", {
"item_list": records,
"pagination": pagination,
"account": account,
"period": period,
"accounts": get_ledger_accounts(),
})
@ -409,7 +404,6 @@ def ledger_summary(request, account):
return render(request, "accounting/ledger-summary.html", {
"item_list": pagination.items,
"pagination": pagination,
"account": account,
"accounts": get_ledger_accounts(),
})
@ -493,7 +487,6 @@ def journal(request, period):
return render(request, "accounting/journal.html", {
"item_list": pagination.items,
"pagination": pagination,
"period": period,
})
@ -597,7 +590,6 @@ def trial_balance(request, period):
return render(request, "accounting/trial-balance.html", {
"item_list": accounts,
"total_item": total_account,
"period": period,
})
@ -673,7 +665,6 @@ def income_statement(request, period):
sections[-1].has_next = False
return render(request, "accounting/income-statement.html", {
"item_list": sections,
"period": period,
})
@ -774,7 +765,6 @@ def balance_sheet(request, period):
"assets": by_code["1"],
"liabilities": by_code["2"],
"owners_equity": by_code["3"],
"period": period,
})