Changed the format_amount_input filter to accept None, and return an empty string if the value is None.
This commit is contained in:
parent
a7bcf4b5c1
commit
bfb08cf5fc
@ -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|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount,
|
||||
entry_errors = entry_form.all_errors %}
|
||||
|
@ -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|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount,
|
||||
entry_errors = entry_form.all_errors %}
|
||||
|
@ -57,7 +57,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|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount,
|
||||
entry_errors = entry_form.all_errors %}
|
||||
@ -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|accounting_txn_format_amount_input,
|
||||
amount_data = entry_form.amount.data|accounting_txn_format_amount_input,
|
||||
amount_errors = entry_form.amount.errors,
|
||||
amount_text = entry_form.amount.data|accounting_format_amount,
|
||||
entry_errors = entry_form.all_errors %}
|
||||
|
@ -57,12 +57,14 @@ def to_transfer(uri: str) -> str:
|
||||
return urlunparse(parts)
|
||||
|
||||
|
||||
def format_amount_input(value: Decimal) -> str:
|
||||
def format_amount_input(value: Decimal | None) -> str:
|
||||
"""Format an amount for an input value.
|
||||
|
||||
:param value: The amount.
|
||||
:return: The formatted amount text for an input value.
|
||||
"""
|
||||
if value is None:
|
||||
return ""
|
||||
whole: int = int(value)
|
||||
frac: Decimal = (value - whole).normalize()
|
||||
return str(whole) + str(frac)[1:]
|
||||
|
Loading…
Reference in New Issue
Block a user