From 53565eb9e6cfeff473ecf1a12c15646f79da9506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 11 Mar 2023 19:07:12 +0800 Subject: [PATCH] Changed the IsBalanced validator from an inner class inside the TransferCurrencyForm form to an independent class. --- src/accounting/transaction/forms/currency.py | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/accounting/transaction/forms/currency.py b/src/accounting/transaction/forms/currency.py index 5f8cd30..0af8aa5 100644 --- a/src/accounting/transaction/forms/currency.py +++ b/src/accounting/transaction/forms/currency.py @@ -59,6 +59,19 @@ class NeedSomeJournalEntries: "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): """The form to create or edit a currency in a transaction.""" no = IntegerField() @@ -141,19 +154,6 @@ class ExpenseCurrencyForm(CurrencyForm): class TransferCurrencyForm(CurrencyForm): """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() """The order in the transaction.""" code = StringField(