Added the CurrentAccountExists and AccountNotCurrent validators to the default_ie_account_code field of the OptionForm form, to validate that the current account exists and is a current account.
This commit is contained in:
parent
283758ebe9
commit
7ccc96bda0
@ -32,6 +32,28 @@ from accounting.utils.options import Options
|
|||||||
from accounting.utils.strip_text import strip_text
|
from accounting.utils.strip_text import strip_text
|
||||||
|
|
||||||
|
|
||||||
|
class CurrentAccountExists:
|
||||||
|
"""The validator to check that the current account exists."""
|
||||||
|
|
||||||
|
def __call__(self, form: FlaskForm, field: StringField) -> None:
|
||||||
|
if field.data is None or field.data == CurrentAccount.CURRENT_AL_CODE:
|
||||||
|
return
|
||||||
|
if Account.find_by_code(field.data) is None:
|
||||||
|
raise ValidationError(lazy_gettext(
|
||||||
|
"The current account does not exist."))
|
||||||
|
|
||||||
|
|
||||||
|
class AccountNotCurrent:
|
||||||
|
"""The validator to check that the account is a current account."""
|
||||||
|
|
||||||
|
def __call__(self, form: FlaskForm, field: StringField) -> None:
|
||||||
|
if field.data is None or field.data == CurrentAccount.CURRENT_AL_CODE:
|
||||||
|
return
|
||||||
|
if field.data[:2] not in {"11", "12", "21", "22"}:
|
||||||
|
raise ValidationError(lazy_gettext(
|
||||||
|
"The current account does not exist."))
|
||||||
|
|
||||||
|
|
||||||
class NotStartPayableFromExpense:
|
class NotStartPayableFromExpense:
|
||||||
"""The validator to check that a payable line item does not start from
|
"""The validator to check that a payable line item does not start from
|
||||||
expense."""
|
expense."""
|
||||||
@ -219,7 +241,9 @@ class OptionForm(FlaskForm):
|
|||||||
validators=[
|
validators=[
|
||||||
DataRequired(lazy_gettext(
|
DataRequired(lazy_gettext(
|
||||||
"Please select the default account"
|
"Please select the default account"
|
||||||
" for the income and expenses log."))])
|
" for the income and expenses log.")),
|
||||||
|
CurrentAccountExists(),
|
||||||
|
AccountNotCurrent()])
|
||||||
"""The default account code for the income and expenses log."""
|
"""The default account code for the income and expenses log."""
|
||||||
recurring = FormField(RecurringForm)
|
recurring = FormField(RecurringForm)
|
||||||
"""The recurring expenses and incomes."""
|
"""The recurring expenses and incomes."""
|
||||||
|
Loading…
Reference in New Issue
Block a user