From 87fa5aa6bca7403a452e74673bd7529db1980c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 22 Mar 2023 23:23:53 +0800 Subject: [PATCH] Moved the ACCOUNT_REQUIRED validator from the "accounting.journal_entry.forms.line_item" module to the "accounting.forms" module, in order to share it. --- src/accounting/forms.py | 6 ++++++ src/accounting/journal_entry/forms/line_item.py | 9 +++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/accounting/forms.py b/src/accounting/forms.py index 7aa5e28..e70a8e7 100644 --- a/src/accounting/forms.py +++ b/src/accounting/forms.py @@ -22,12 +22,18 @@ import re from flask_babel import LazyString from flask_wtf import FlaskForm from wtforms import StringField, ValidationError +from wtforms.validators import DataRequired from accounting import db from accounting.locale import lazy_gettext from accounting.models import Currency, Account +ACCOUNT_REQUIRED: DataRequired = DataRequired( + lazy_gettext("Please select the account.")) +"""The validator to check if the account code is empty.""" + + class CurrencyExists: """The validator to check if the account exists.""" diff --git a/src/accounting/journal_entry/forms/line_item.py b/src/accounting/journal_entry/forms/line_item.py index 0f4cf37..c72c58a 100644 --- a/src/accounting/journal_entry/forms/line_item.py +++ b/src/accounting/journal_entry/forms/line_item.py @@ -25,10 +25,11 @@ from flask_babel import LazyString from flask_wtf import FlaskForm from sqlalchemy.orm import selectinload from wtforms import StringField, ValidationError, DecimalField, IntegerField -from wtforms.validators import DataRequired, Optional +from wtforms.validators import Optional from accounting import db -from accounting.forms import AccountExists, IsDebitAccount, IsCreditAccount +from accounting.forms import ACCOUNT_REQUIRED, AccountExists, IsDebitAccount, \ + IsCreditAccount from accounting.locale import lazy_gettext from accounting.models import Account, JournalEntryLineItem from accounting.template_filters import format_amount @@ -37,10 +38,6 @@ from accounting.utils.random_id import new_id from accounting.utils.strip_text import strip_text from accounting.utils.user import get_current_user_pk -ACCOUNT_REQUIRED: DataRequired = DataRequired( - lazy_gettext("Please select the account.")) -"""The validator to check if the account code is empty.""" - class OriginalLineItemExists: """The validator to check if the original line item exists."""