diff --git a/src/accounting/forms.py b/src/accounting/forms.py index 026130f..7aa5e28 100644 --- a/src/accounting/forms.py +++ b/src/accounting/forms.py @@ -53,14 +53,11 @@ class AccountExists: class IsDebitAccount: """The validator to check if the account is for debit line items.""" - def __init__(self, message: str | LazyString | None = None): + def __init__(self, message: str | LazyString): """Constructs the validator. - :param message: The optional custom error message. + :param message: The error message. """ - if message is None: - message = lazy_gettext( - "This account is not for debit line items.") self.__message: str | LazyString = message def __call__(self, form: FlaskForm, field: StringField) -> None: @@ -76,14 +73,11 @@ class IsDebitAccount: class IsCreditAccount: """The validator to check if the account is for credit line items.""" - def __init__(self, message: str | LazyString | None = None): + def __init__(self, message: str | LazyString): """Constructs the validator. - :param message: The optional custom error message. + :param message: The error message. """ - if message is None: - message = lazy_gettext( - "This account is not for credit line items.") self.__message: str | LazyString = message def __call__(self, form: FlaskForm, field: StringField) -> None: diff --git a/src/accounting/journal_entry/forms/line_item.py b/src/accounting/journal_entry/forms/line_item.py index ddf198b..0f4cf37 100644 --- a/src/accounting/journal_entry/forms/line_item.py +++ b/src/accounting/journal_entry/forms/line_item.py @@ -413,12 +413,14 @@ class DebitLineItemForm(LineItemForm): """The ID of the original line item.""" account_code = StringField( filters=[strip_text], - validators=[ACCOUNT_REQUIRED, - AccountExists(), - IsDebitAccount(), - SameAccountAsOriginalLineItem(), - KeepAccountWhenHavingOffset(), - NotStartPayableFromDebit()]) + validators=[ + ACCOUNT_REQUIRED, + AccountExists(), + IsDebitAccount(lazy_gettext( + "This account is not for debit line items.")), + SameAccountAsOriginalLineItem(), + KeepAccountWhenHavingOffset(), + NotStartPayableFromDebit()]) """The account code.""" description = StringField(filters=[strip_text]) """The description.""" @@ -463,12 +465,14 @@ class CreditLineItemForm(LineItemForm): """The ID of the original line item.""" account_code = StringField( filters=[strip_text], - validators=[ACCOUNT_REQUIRED, - AccountExists(), - IsCreditAccount(), - SameAccountAsOriginalLineItem(), - KeepAccountWhenHavingOffset(), - NotStartReceivableFromCredit()]) + validators=[ + ACCOUNT_REQUIRED, + AccountExists(), + IsCreditAccount(lazy_gettext( + "This account is not for credit line items.")), + SameAccountAsOriginalLineItem(), + KeepAccountWhenHavingOffset(), + NotStartReceivableFromCredit()]) """The account code.""" description = StringField(filters=[strip_text]) """The description."""