Changed the IsBalanced validator from an inner class inside the TransferCurrencyForm form to an independent class.
This commit is contained in:
parent
965e78d8ad
commit
53565eb9e6
@ -59,6 +59,19 @@ class NeedSomeJournalEntries:
|
|||||||
"Please add some journal entries."))
|
"Please add some journal entries."))
|
||||||
|
|
||||||
|
|
||||||
|
class IsBalanced:
|
||||||
|
"""The validator to check that the total amount of the debit and credit
|
||||||
|
entries are equal."""
|
||||||
|
|
||||||
|
def __call__(self, form: TransferCurrencyForm, field: BooleanField)\
|
||||||
|
-> None:
|
||||||
|
if len(form.debit) == 0 or len(form.credit) == 0:
|
||||||
|
return
|
||||||
|
if form.debit_total != form.credit_total:
|
||||||
|
raise ValidationError(lazy_gettext(
|
||||||
|
"The totals of the debit and credit amounts do not match."))
|
||||||
|
|
||||||
|
|
||||||
class CurrencyForm(FlaskForm):
|
class CurrencyForm(FlaskForm):
|
||||||
"""The form to create or edit a currency in a transaction."""
|
"""The form to create or edit a currency in a transaction."""
|
||||||
no = IntegerField()
|
no = IntegerField()
|
||||||
@ -141,19 +154,6 @@ class ExpenseCurrencyForm(CurrencyForm):
|
|||||||
|
|
||||||
class TransferCurrencyForm(CurrencyForm):
|
class TransferCurrencyForm(CurrencyForm):
|
||||||
"""The form to create or edit a currency in a transfer transaction."""
|
"""The form to create or edit a currency in a transfer transaction."""
|
||||||
|
|
||||||
class IsBalanced:
|
|
||||||
"""The validator to check that the total amount of the debit and credit
|
|
||||||
entries are equal."""
|
|
||||||
def __call__(self, form: TransferCurrencyForm, field: BooleanField)\
|
|
||||||
-> None:
|
|
||||||
if len(form.debit) == 0 or len(form.credit) == 0:
|
|
||||||
return
|
|
||||||
if form.debit_total != form.credit_total:
|
|
||||||
raise ValidationError(lazy_gettext(
|
|
||||||
"The totals of the debit and credit amounts do not"
|
|
||||||
" match."))
|
|
||||||
|
|
||||||
no = IntegerField()
|
no = IntegerField()
|
||||||
"""The order in the transaction."""
|
"""The order in the transaction."""
|
||||||
code = StringField(
|
code = StringField(
|
||||||
|
Loading…
Reference in New Issue
Block a user