Renamed the debit and credit methods in the Account data model to selectable_debit and selectable_credit, to be clear.

This commit is contained in:
依瑪貓 2023-03-22 20:21:52 +08:00
parent 5f88260507
commit 68c810d492
3 changed files with 12 additions and 10 deletions

View File

@ -220,7 +220,7 @@ class JournalEntryForm(FlaskForm):
:return: The selectable debit accounts. :return: The selectable debit accounts.
""" """
accounts: list[AccountOption] \ 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)] if not (x.code[0] == "2" and x.is_need_offset)]
in_use: set[int] = set(db.session.scalars( in_use: set[int] = set(db.session.scalars(
sa.select(JournalEntryLineItem.account_id) sa.select(JournalEntryLineItem.account_id)
@ -237,7 +237,7 @@ class JournalEntryForm(FlaskForm):
:return: The selectable credit accounts. :return: The selectable credit accounts.
""" """
accounts: list[AccountOption] \ 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)] if not (x.code[0] == "1" and x.is_need_offset)]
in_use: set[int] = set(db.session.scalars( in_use: set[int] = set(db.session.scalars(
sa.select(JournalEntryLineItem.account_id) sa.select(JournalEntryLineItem.account_id)

View File

@ -269,10 +269,11 @@ class Account(db.Model):
cls.no == int(m.group(2))).first() cls.no == int(m.group(2))).first()
@classmethod @classmethod
def debit(cls) -> list[t.Self]: def selectable_debit(cls) -> list[t.Self]:
"""Returns the debit accounts. """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"), return cls.query.filter(sa.or_(cls.base_code.startswith("1"),
sa.and_(cls.base_code.startswith("2"), sa.and_(cls.base_code.startswith("2"),
@ -291,10 +292,11 @@ class Account(db.Model):
.order_by(cls.base_code, cls.no).all() .order_by(cls.base_code, cls.no).all()
@classmethod @classmethod
def credit(cls) -> list[t.Self]: def selectable_credit(cls) -> list[t.Self]:
"""Returns the debit accounts. """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"), return cls.query.filter(sa.or_(sa.and_(cls.base_code.startswith("1"),
sa.not_(cls.is_need_offset)), sa.not_(cls.is_need_offset)),

View File

@ -202,7 +202,7 @@ class RecurringForm(RecurringItemForm):
:return: None. :return: None.
""" """
return Account.debit() return Account.selectable_debit()
@property @property
def income_accounts(self) -> list[Account]: def income_accounts(self) -> list[Account]:
@ -210,7 +210,7 @@ class RecurringForm(RecurringItemForm):
:return: None. :return: None.
""" """
return Account.credit() return Account.selectable_credit()
@property @property
def as_data(self) -> dict[str, list[tuple[str, str, str]]]: def as_data(self) -> dict[str, list[tuple[str, str, str]]]: