Replaced the if checks with assert in the IsBalanced validator of the currency sub-form of the transaction form, the NoOffsetNominalAccount validator of the account form, and the CodeUnique validator of the currency form.

This commit is contained in:
依瑪貓 2023-03-15 22:25:24 +08:00
parent 954173a2c2
commit 2b2c665eb6
3 changed files with 3 additions and 6 deletions

View File

@ -57,10 +57,9 @@ class NoOffsetNominalAccount:
"""The validator to check nominal account is not to be offset.""" """The validator to check nominal account is not to be offset."""
def __call__(self, form: FlaskForm, field: BooleanField) -> None: def __call__(self, form: FlaskForm, field: BooleanField) -> None:
assert isinstance(form, AccountForm)
if not field.data: if not field.data:
return return
if not isinstance(form, AccountForm):
return
if form.base_code.data is None: if form.base_code.data is None:
return return
if form.base_code.data[0] not in {"1", "2"}: if form.base_code.data[0] not in {"1", "2"}:

View File

@ -32,10 +32,9 @@ class CodeUnique:
"""The validator to check if the code is unique.""" """The validator to check if the code is unique."""
def __call__(self, form: FlaskForm, field: StringField) -> None: def __call__(self, form: FlaskForm, field: StringField) -> None:
assert isinstance(form, CurrencyForm)
if field.data == "": if field.data == "":
return return
if not isinstance(form, CurrencyForm):
return
if form.obj_code is not None and form.obj_code == field.data: if form.obj_code is not None and form.obj_code == field.data:
return return
if db.session.get(Currency, field.data) is not None: if db.session.get(Currency, field.data) is not None:

View File

@ -61,8 +61,7 @@ class IsBalanced:
entries are equal.""" entries are equal."""
def __call__(self, form: FlaskForm, field: BooleanField) -> None: def __call__(self, form: FlaskForm, field: BooleanField) -> None:
if not isinstance(form, TransferCurrencyForm): assert isinstance(form, TransferCurrencyForm)
return
if len(form.debit) == 0 or len(form.credit) == 0: if len(form.debit) == 0 or len(form.credit) == 0:
return return
if form.debit_total != form.credit_total: if form.debit_total != form.credit_total: