Added the accounting_txn_format_amount_input template filter to properly format the decimal amount for the number input fields.
This commit is contained in:
parent
59c55ef574
commit
d67c57056b
@ -55,7 +55,7 @@ First written: 2023/2/25
|
|||||||
account_text = entry_form.account_text,
|
account_text = entry_form.account_text,
|
||||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||||
summary_errors = entry_form.summary.errors,
|
summary_errors = entry_form.summary.errors,
|
||||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data,
|
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||||
amount_errors = entry_form.amount.errors,
|
amount_errors = entry_form.amount.errors,
|
||||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||||
entry_errors = entry_form.all_errors %}
|
entry_errors = entry_form.all_errors %}
|
||||||
|
@ -55,7 +55,7 @@ First written: 2023/2/25
|
|||||||
account_text = entry_form.account_text,
|
account_text = entry_form.account_text,
|
||||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||||
summary_errors = entry_form.summary.errors,
|
summary_errors = entry_form.summary.errors,
|
||||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data,
|
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||||
amount_errors = entry_form.amount.errors,
|
amount_errors = entry_form.amount.errors,
|
||||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||||
entry_errors = entry_form.all_errors %}
|
entry_errors = entry_form.all_errors %}
|
||||||
|
@ -97,7 +97,7 @@ First written: 2023/2/25
|
|||||||
account_text = entry_form.account_text,
|
account_text = entry_form.account_text,
|
||||||
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
summary_data = "" if entry_form.summary.data is none else entry_form.summary.data,
|
||||||
summary_errors = entry_form.summary.errors,
|
summary_errors = entry_form.summary.errors,
|
||||||
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data,
|
amount_data = "" if entry_form.amount.data is none else entry_form.amount.data|accounting_txn_format_amount_input,
|
||||||
amount_errors = entry_form.amount.errors,
|
amount_errors = entry_form.amount.errors,
|
||||||
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
amount_text = entry_form.amount.data|accounting_txn_format_amount,
|
||||||
entry_errors = entry_form.all_errors %}
|
entry_errors = entry_form.all_errors %}
|
||||||
|
@ -60,6 +60,17 @@ def format_amount(value: Decimal | None) -> str:
|
|||||||
return "{:,}".format(whole) + str(frac)[1:]
|
return "{:,}".format(whole) + str(frac)[1:]
|
||||||
|
|
||||||
|
|
||||||
|
def format_amount_input(value: Decimal) -> str:
|
||||||
|
"""Format an amount for an input value.
|
||||||
|
|
||||||
|
:param value: The amount.
|
||||||
|
:return: The formatted amount text for an input value.
|
||||||
|
"""
|
||||||
|
whole: int = int(value)
|
||||||
|
frac: Decimal = (value - whole).normalize()
|
||||||
|
return str(whole) + str(frac)[1:]
|
||||||
|
|
||||||
|
|
||||||
def format_date(value: date) -> str:
|
def format_date(value: date) -> str:
|
||||||
"""Formats a date to be human-friendly.
|
"""Formats a date to be human-friendly.
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ from accounting.utils.pagination import Pagination
|
|||||||
from accounting.utils.permission import has_permission, can_view, can_edit
|
from accounting.utils.permission import has_permission, can_view, can_edit
|
||||||
from accounting.utils.user import get_current_user_pk
|
from accounting.utils.user import get_current_user_pk
|
||||||
from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ
|
from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ
|
||||||
from .template import with_type, format_amount, format_date, text2html, \
|
from .template import with_type, format_amount, format_amount_input, \
|
||||||
currency_options, default_currency_code
|
format_date, text2html, currency_options, default_currency_code
|
||||||
from .forms import sort_transactions_in, TransactionReorderForm
|
from .forms import sort_transactions_in, TransactionReorderForm
|
||||||
from .query import get_transaction_query
|
from .query import get_transaction_query
|
||||||
|
|
||||||
@ -43,6 +43,8 @@ bp: Blueprint = Blueprint("transaction", __name__)
|
|||||||
"""The view blueprint for the transaction management."""
|
"""The view blueprint for the transaction management."""
|
||||||
bp.add_app_template_filter(with_type, "accounting_txn_with_type")
|
bp.add_app_template_filter(with_type, "accounting_txn_with_type")
|
||||||
bp.add_app_template_filter(format_amount, "accounting_txn_format_amount")
|
bp.add_app_template_filter(format_amount, "accounting_txn_format_amount")
|
||||||
|
bp.add_app_template_filter(format_amount_input,
|
||||||
|
"accounting_txn_format_amount_input")
|
||||||
bp.add_app_template_filter(format_date, "accounting_txn_format_date")
|
bp.add_app_template_filter(format_date, "accounting_txn_format_date")
|
||||||
bp.add_app_template_filter(text2html, "accounting_txn_text2html")
|
bp.add_app_template_filter(text2html, "accounting_txn_text2html")
|
||||||
bp.add_app_template_global(currency_options, "accounting_txn_currency_options")
|
bp.add_app_template_global(currency_options, "accounting_txn_currency_options")
|
||||||
|
Loading…
Reference in New Issue
Block a user