diff --git a/src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html b/src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html index bc9d4e6..543360b 100644 --- a/src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html +++ b/src/accounting/templates/accounting/transaction/expense/include/form-currency-item.html @@ -55,7 +55,7 @@ First written: 2023/2/25 account_text = entry_form.account_text, summary_data = "" if entry_form.summary.data is none else entry_form.summary.data, 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_text = entry_form.amount.data|accounting_txn_format_amount, entry_errors = entry_form.all_errors %} diff --git a/src/accounting/templates/accounting/transaction/income/include/form-currency-item.html b/src/accounting/templates/accounting/transaction/income/include/form-currency-item.html index 25c82f5..9569007 100644 --- a/src/accounting/templates/accounting/transaction/income/include/form-currency-item.html +++ b/src/accounting/templates/accounting/transaction/income/include/form-currency-item.html @@ -55,7 +55,7 @@ First written: 2023/2/25 account_text = entry_form.account_text, summary_data = "" if entry_form.summary.data is none else entry_form.summary.data, 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_text = entry_form.amount.data|accounting_txn_format_amount, entry_errors = entry_form.all_errors %} diff --git a/src/accounting/templates/accounting/transaction/transfer/include/form-currency-item.html b/src/accounting/templates/accounting/transaction/transfer/include/form-currency-item.html index 8fb4592..6ea3e40 100644 --- a/src/accounting/templates/accounting/transaction/transfer/include/form-currency-item.html +++ b/src/accounting/templates/accounting/transaction/transfer/include/form-currency-item.html @@ -97,7 +97,7 @@ First written: 2023/2/25 account_text = entry_form.account_text, summary_data = "" if entry_form.summary.data is none else entry_form.summary.data, 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_text = entry_form.amount.data|accounting_txn_format_amount, entry_errors = entry_form.all_errors %} diff --git a/src/accounting/transaction/template.py b/src/accounting/transaction/template.py index 7451491..a792382 100644 --- a/src/accounting/transaction/template.py +++ b/src/accounting/transaction/template.py @@ -60,6 +60,17 @@ def format_amount(value: Decimal | None) -> str: 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: """Formats a date to be human-friendly. diff --git a/src/accounting/transaction/views.py b/src/accounting/transaction/views.py index 394de0c..f5fc03c 100644 --- a/src/accounting/transaction/views.py +++ b/src/accounting/transaction/views.py @@ -34,8 +34,8 @@ from accounting.utils.pagination import Pagination from accounting.utils.permission import has_permission, can_view, can_edit from accounting.utils.user import get_current_user_pk from .dispatcher import TransactionType, get_txn_type, TXN_TYPE_OBJ -from .template import with_type, format_amount, format_date, text2html, \ - currency_options, default_currency_code +from .template import with_type, format_amount, format_amount_input, \ + format_date, text2html, currency_options, default_currency_code from .forms import sort_transactions_in, TransactionReorderForm from .query import get_transaction_query @@ -43,6 +43,8 @@ bp: Blueprint = Blueprint("transaction", __name__) """The view blueprint for the transaction management.""" 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_input, + "accounting_txn_format_amount_input") bp.add_app_template_filter(format_date, "accounting_txn_format_date") bp.add_app_template_filter(text2html, "accounting_txn_text2html") bp.add_app_template_global(currency_options, "accounting_txn_currency_options")