Simplified the parameter passed to the "form-line-item.html" template for the line item subform of the voucher form, to be less error-prone.

This commit is contained in:
依瑪貓 2023-03-20 18:48:12 +08:00
parent d18dd7d4d2
commit e4cc61552e
6 changed files with 30 additions and 94 deletions

View File

@ -49,25 +49,8 @@ First written: 2023/2/25
{% with currency_index = currency_index,
side = "debit",
line_item_index = loop.index,
line_item_id = line_item_form.form.eid.data,
only_one_line_item_form = debit_forms|length == 1,
account_code_data = line_item_form.form.account_code.data|accounting_default,
account_code_error = line_item_form.form.account_code.errors,
account_text = line_item_form.form.account_text,
description_data = line_item_form.form.description.data|accounting_default,
description_errors = line_item_form.form.description.errors,
original_line_item_id_data = line_item_form.form.original_line_item_id.data|accounting_default,
original_line_item_date = line_item_form.form.original_line_item_date|accounting_default,
original_line_item_text = line_item_form.form.original_line_item_text|accounting_default,
is_need_offset = line_item_form.form.is_need_offset,
offset_items = line_item_form.form.offsets,
offset_total = line_item_form.form.offset_total|accounting_default("0"),
net_balance_data = line_item_form.form.net_balance,
net_balance_text = line_item_form.form.net_balance|accounting_format_amount,
amount_data = line_item_form.form.amount.data|accounting_voucher_format_amount_input,
amount_errors = line_item_form.form.amount.errors,
amount_text = line_item_form.form.amount.data|accounting_format_amount,
line_item_errors = line_item_form.form.all_errors %}
form = line_item_form.form %}
{% include "accounting/voucher/include/form-line-item.html" %}
{% endwith %}
{% endfor %}

View File

@ -20,39 +20,39 @@ Author: imacat@mail.imacat.idv.tw (imacat)
First written: 2023/2/25
#}
{# <ul> For SonarQube not to complain about incorrect HTML #}
<li id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}" class="list-group-item list-group-item-action d-flex justify-content-between accounting-currency-{{ currency_index }}-{{ side }} {% if offset_items %} accounting-matched-line-item {% endif %}" data-currency-index="{{ currency_index }}" data-side="{{ side }}" data-line-item-index="{{ line_item_index }}" {% if is_need_offset %} data-is-need-offset="true" {% endif %}>
{% if line_item_id %}
<input type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-eid" value="{{ line_item_id }}">
<li id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}" class="list-group-item list-group-item-action d-flex justify-content-between accounting-currency-{{ currency_index }}-{{ side }} {% if form.offsets %} accounting-matched-line-item {% endif %}" data-currency-index="{{ currency_index }}" data-side="{{ side }}" data-line-item-index="{{ line_item_index }}" {% if form.is_need_offset %} data-is-need-offset="true" {% endif %}>
{% if form.eid.data %}
<input type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-eid" value="{{ form.eid.data }}">
{% endif %}
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-no" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-no" value="{{ line_item_index }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original-line-item-id" class="accounting-original-line-item-id" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original_line_item_id" value="{{ original_line_item_id_data }}" data-date="{{ original_line_item_date }}" data-text="{{ original_line_item_text }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account-code" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account_code" value="{{ account_code_data }}" data-text="{{ account_text }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description" value="{{ description_data }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount" value="{{ amount_data }}" data-min="{{ offset_total }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original-line-item-id" class="accounting-original-line-item-id" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original_line_item_id" value="{{ form.original_line_item_id.data|accounting_default }}" data-date="{{ form.original_line_item_date|accounting_default }}" data-text="{{ form.original_line_item_text|accounting_default }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account-code" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account_code" value="{{ form.account_code.data|accounting_default }}" data-text="{{ form.account_text }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description" value="{{ form.description.data|accounting_default }}">
<input id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount" type="hidden" name="currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount" value="{{ form.amount.data|accounting_voucher_format_amount_input }}" data-min="{{ form.offset_total|accounting_default("0") }}">
<div class="accounting-line-item-content">
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-control" class="form-control clickable d-flex justify-content-between {% if line_item_errors %} is-invalid {% endif %}" data-bs-toggle="modal" data-bs-target="#accounting-line-item-editor-modal">
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-control" class="form-control clickable d-flex justify-content-between {% if form.all_errors %} is-invalid {% endif %}" data-bs-toggle="modal" data-bs-target="#accounting-line-item-editor-modal">
<div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account-text" class="small">{{ account_text }}</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description-text">{{ description_data }}</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original-line-item-text" class="fst-italic small accounting-original-line-item {% if not original_line_item_text %} d-none {% endif %}">
{% if original_line_item_text %}{{ A_("Offset %(item)s", item=original_line_item_text) }}{% endif %}
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-account-text" class="small">{{ form.account_text }}</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-description-text">{{ form.description.data|accounting_default }}</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-original-line-item-text" class="fst-italic small accounting-original-line-item {% if not form.original_line_item_id.data %} d-none {% endif %}">
{% if form.original_line_item_id.data %}{{ A_("Offset %(item)s", item=form.original_line_item_text|accounting_default) }}{% endif %}
</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-offsets" class="fst-italic small accounting-offset-line-items {% if not is_need_offset %} d-none {% endif %}">
{% if offset_items %}
<div class="d-flex justify-content-between {% if not offset_items %} d-none {% endif %}">
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-offsets" class="fst-italic small accounting-offset-line-items {% if not form.is_need_offset %} d-none {% endif %}">
{% if form.offsets %}
<div class="d-flex justify-content-between {% if not form.offsets %} d-none {% endif %}">
<div>{{ A_("Offsets") }}</div>
<ul class="ms-2 ps-0">
{% for offset in offset_items %}
{% for offset in form.offsets %}
<li>{{ offset.voucher.date|accounting_format_date }} {{ offset.amount|accounting_format_amount }}</li>
{% endfor %}
</ul>
</div>
{% if net_balance_data == 0 %}
{% if form.net_balance == 0 %}
<div>{{ A_("Fully offset") }}</div>
{% else %}
<div class="d-flex justify-content-between">
<div>{{ A_("Net balance") }}</div>
<div>{{ net_balance_text }}</div>
<div>{{ form.net_balance|accounting_format_amount }}</div>
</div>
{% endif %}
{% else %}
@ -60,13 +60,13 @@ First written: 2023/2/25
{% endif %}
</div>
</div>
<div><span id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount-text" class="badge rounded-pill bg-primary">{{ amount_text }}</span></div>
<div><span id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-amount-text" class="badge rounded-pill bg-primary">{{ form.amount.data|accounting_format_amount }}</span></div>
</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-error" class="invalid-feedback">{% if line_item_errors %}{{ line_item_errors[0] }}{% endif %}</div>
<div id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-error" class="invalid-feedback">{% if form.all_errors %}{{ form.all_errors[0] }}{% endif %}</div>
</div>
<div>
<button id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-delete" class="btn btn-danger rounded-circle {% if only_one_line_item_form or offset_items %} d-none {% endif %}" type="button" data-target="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}">
<button id="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}-delete" class="btn btn-danger rounded-circle {% if only_one_form or form.offsets %} d-none {% endif %}" type="button" data-target="accounting-currency-{{ currency_index }}-{{ side }}-{{ line_item_index }}">
<i class="fas fa-minus"></i>
</button>
</div>

View File

@ -50,24 +50,7 @@ First written: 2023/2/25
side = "credit",
line_item_index = loop.index,
only_one_line_item_form = credit_forms|length == 1,
line_item_id = line_item_form.form.eid.data,
account_code_data = line_item_form.form.account_code.data|accounting_default,
account_code_error = line_item_form.form.account_code.errors,
account_text = line_item_form.form.account_text,
description_data = line_item_form.form.description.data|accounting_default,
description_errors = line_item_form.form.description.errors,
original_line_item_id_data = line_item_form.form.original_line_item_id.data|accounting_default,
original_line_item_date = line_item_form.form.original_line_item_date|accounting_default,
original_line_item_text = line_item_form.form.original_line_item_text|accounting_default,
is_need_offset = line_item_form.form.is_need_offset,
offset_items = line_item_form.form.offsets,
offset_total = line_item_form.form.offset_total|accounting_default("0"),
net_balance_data = line_item_form.form.net_balance,
net_balance_text = line_item_form.form.net_balance|accounting_format_amount,
amount_data = line_item_form.form.amount.data|accounting_voucher_format_amount_input,
amount_errors = line_item_form.form.amount.errors,
amount_text = line_item_form.form.amount.data|accounting_format_amount,
line_item_errors = line_item_form.form.all_errors %}
form = line_item_form.form %}
{% include "accounting/voucher/include/form-line-item.html" %}
{% endwith %}
{% endfor %}

View File

@ -52,24 +52,7 @@ First written: 2023/2/25
side = "debit",
line_item_index = loop.index,
only_one_line_item_form = debit_forms|length == 1,
line_item_id = line_item_form.form.eid.data,
account_code_data = line_item_form.form.account_code.data|accounting_default,
account_code_error = line_item_form.form.account_code.errors,
account_text = line_item_form.form.account_text,
description_data = line_item_form.form.description.data|accounting_default,
description_errors = line_item_form.form.description.errors,
original_line_item_id_data = line_item_form.form.original_line_item_id.data|accounting_default,
original_line_item_date = line_item_form.form.original_line_item_date|accounting_default,
original_line_item_text = line_item_form.form.original_line_item_text|accounting_default,
is_need_offset = line_item_form.form.is_need_offset,
offset_items = line_item_form.form.offsets,
offset_total = line_item_form.form.offset_total|accounting_default,
net_balance_data = line_item_form.form.net_balance,
net_balance_text = line_item_form.form.net_balance|accounting_format_amount,
amount_data = line_item_form.form.amount.data|accounting_voucher_format_amount_input,
amount_errors = line_item_form.form.amount.errors,
amount_text = line_item_form.form.amount.data|accounting_format_amount,
line_item_errors = line_item_form.form.all_errors %}
form = line_item_form.form %}
{% include "accounting/voucher/include/form-line-item.html" %}
{% endwith %}
{% endfor %}
@ -100,24 +83,7 @@ First written: 2023/2/25
side = "credit",
line_item_index = loop.index,
only_one_line_item_form = debit_forms|length == 1,
line_item_id = line_item_form.form.eid.data,
account_code_data = line_item_form.form.account_code.data|accounting_default,
account_code_error = line_item_form.form.account_code.errors,
account_text = line_item_form.form.account_text,
description_data = line_item_form.form.description.data|accounting_default,
description_errors = line_item_form.form.description.errors,
original_line_item_id_data = line_item_form.form.original_line_item_id.data|accounting_default,
original_line_item_date = line_item_form.form.original_line_item_date|accounting_default,
original_line_item_text = line_item_form.form.original_line_item_text|accounting_default,
is_need_offset = line_item_form.form.is_need_offset,
offset_items = line_item_form.form.offsets,
offset_total = line_item_form.form.offset_total|accounting_default("0"),
net_balance_data = line_item_form.form.net_balance,
net_balance_text = line_item_form.form.net_balance|accounting_format_amount,
amount_data = line_item_form.form.amount.data|accounting_voucher_format_amount_input,
amount_errors = line_item_form.form.amount.errors,
amount_text = line_item_form.form.amount.data|accounting_format_amount,
line_item_errors = line_item_form.form.all_errors %}
form = line_item_form.form %}
{% include "accounting/voucher/include/form-line-item.html" %}
{% endwith %}
{% endfor %}

View File

@ -289,6 +289,8 @@ class LineItemForm(FlaskForm):
"""The Id of the original line item."""
account_code = StringField()
"""The account code."""
description = StringField()
"""The description."""
amount = DecimalField()
"""The amount."""

View File

@ -28,6 +28,7 @@ from accounting.template_globals import default_currency_code
from accounting.utils.voucher_types import VoucherType
from accounting.voucher.forms import VoucherForm, CashReceiptVoucherForm, \
CashDisbursementVoucherForm, TransferVoucherForm
from accounting.voucher.forms.line_item import LineItemForm
class VoucherOperator(ABC):
@ -87,7 +88,8 @@ class VoucherOperator(ABC):
"accounting/voucher/include/form-line-item.html",
currency_index="CURRENCY_INDEX",
side="SIDE",
line_item_index="LINE_ITEM_INDEX")
line_item_index="LINE_ITEM_INDEX",
form=LineItemForm())
class CashReceiptVoucher(VoucherOperator):