From 68c810d49264970c236604aa208afb3456b11530 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 20:21:52 +0800 Subject: [PATCH] Renamed the debit and credit methods in the Account data model to selectable_debit and selectable_credit, to be clear. --- .../journal_entry/forms/journal_entry.py | 4 ++-- src/accounting/models.py | 14 ++++++++------ src/accounting/option/forms.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/accounting/journal_entry/forms/journal_entry.py b/src/accounting/journal_entry/forms/journal_entry.py index 7866205..e9ebe19 100644 --- a/src/accounting/journal_entry/forms/journal_entry.py +++ b/src/accounting/journal_entry/forms/journal_entry.py @@ -220,7 +220,7 @@ class JournalEntryForm(FlaskForm): :return: The selectable debit accounts. """ accounts: list[AccountOption] \ - = [AccountOption(x) for x in Account.debit() + = [AccountOption(x) for x in Account.selectable_debit() if not (x.code[0] == "2" and x.is_need_offset)] in_use: set[int] = set(db.session.scalars( sa.select(JournalEntryLineItem.account_id) @@ -237,7 +237,7 @@ class JournalEntryForm(FlaskForm): :return: The selectable credit accounts. """ accounts: list[AccountOption] \ - = [AccountOption(x) for x in Account.credit() + = [AccountOption(x) for x in Account.selectable_credit() if not (x.code[0] == "1" and x.is_need_offset)] in_use: set[int] = set(db.session.scalars( sa.select(JournalEntryLineItem.account_id) diff --git a/src/accounting/models.py b/src/accounting/models.py index 459f3b9..470e148 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -269,10 +269,11 @@ class Account(db.Model): cls.no == int(m.group(2))).first() @classmethod - def debit(cls) -> list[t.Self]: - """Returns the debit accounts. + def selectable_debit(cls) -> list[t.Self]: + """Returns the selectable debit accounts. + Payable line items can not start from debit. - :return: The debit accounts. + :return: The selectable debit accounts. """ return cls.query.filter(sa.or_(cls.base_code.startswith("1"), sa.and_(cls.base_code.startswith("2"), @@ -291,10 +292,11 @@ class Account(db.Model): .order_by(cls.base_code, cls.no).all() @classmethod - def credit(cls) -> list[t.Self]: - """Returns the debit accounts. + def selectable_credit(cls) -> list[t.Self]: + """Returns the selectable debit accounts. + Receivable line items can not start from credit. - :return: The debit accounts. + :return: The selectable debit accounts. """ return cls.query.filter(sa.or_(sa.and_(cls.base_code.startswith("1"), sa.not_(cls.is_need_offset)), diff --git a/src/accounting/option/forms.py b/src/accounting/option/forms.py index 624aa6b..b8824e6 100644 --- a/src/accounting/option/forms.py +++ b/src/accounting/option/forms.py @@ -202,7 +202,7 @@ class RecurringForm(RecurringItemForm): :return: None. """ - return Account.debit() + return Account.selectable_debit() @property def income_accounts(self) -> list[Account]: @@ -210,7 +210,7 @@ class RecurringForm(RecurringItemForm): :return: None. """ - return Account.credit() + return Account.selectable_credit() @property def as_data(self) -> dict[str, list[tuple[str, str, str]]]: