Renamed the TrialBalanceAccount, IncomeStatementAccount, and BalanceSheetAccount classes to ReportAccount, to be short and clear.

This commit is contained in:
依瑪貓 2023-03-08 17:55:34 +08:00
parent c8230c949d
commit 729a7fd107
3 changed files with 34 additions and 34 deletions

View File

@ -36,11 +36,11 @@ from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
class BalanceSheetAccount: class ReportAccount:
"""An account in the balance sheet.""" """An account in the report."""
def __init__(self, account: Account, amount: Decimal, url: str): def __init__(self, account: Account, amount: Decimal, url: str):
"""Constructs an account in the balance sheet. """Constructs an account in the report.
:param account: The account. :param account: The account.
:param amount: The amount. :param amount: The amount.
@ -64,7 +64,7 @@ class Subsection:
""" """
self.title: BaseAccount = title self.title: BaseAccount = title
"""The title account.""" """The title account."""
self.accounts: list[BalanceSheetAccount] = [] self.accounts: list[ReportAccount] = []
"""The accounts in the subsection.""" """The accounts in the subsection."""
@property @property
@ -111,10 +111,10 @@ class AccountCollector:
"""The currency.""" """The currency."""
self.__period: Period = period self.__period: Period = period
"""The period.""" """The period."""
self.accounts: list[BalanceSheetAccount] = self.__query_balances() self.accounts: list[ReportAccount] = self.__query_balances()
"""The balance sheet accounts.""" """The balance sheet accounts."""
def __query_balances(self) -> list[BalanceSheetAccount]: def __query_balances(self) -> list[ReportAccount]:
"""Queries and returns the balances. """Queries and returns the balances.
:return: The balances. :return: The balances.
@ -158,10 +158,10 @@ class AccountCollector:
currency=self.__currency, account=account, currency=self.__currency, account=account,
period=self.__period) period=self.__period)
self.accounts: list[BalanceSheetAccount] \ self.accounts: list[ReportAccount] \
= [BalanceSheetAccount(account=account_by_id[x.id], = [ReportAccount(account=account_by_id[x.id],
amount=x.balance, amount=x.balance,
url=get_url(account_by_id[x.id])) url=get_url(account_by_id[x.id]))
for x in account_balances] for x in account_balances]
self.__add_accumulated() self.__add_accumulated()
self.__add_current_period() self.__add_current_period()
@ -240,10 +240,10 @@ class AccountCollector:
:return: None. :return: None.
""" """
# There is an existing balance. # There is an existing balance.
account_balance_by_code: dict[str, BalanceSheetAccount] \ account_balance_by_code: dict[str, ReportAccount] \
= {x.account.code: x for x in self.accounts} = {x.account.code: x for x in self.accounts}
if code in account_balance_by_code: if code in account_balance_by_code:
balance: BalanceSheetAccount = account_balance_by_code[code] balance: ReportAccount = account_balance_by_code[code]
balance.url = url balance.url = url
if amount is not None: if amount is not None:
balance.amount = balance.amount + amount balance.amount = balance.amount + amount
@ -253,9 +253,9 @@ class AccountCollector:
return return
account_by_code: dict[str, Account] \ account_by_code: dict[str, Account] \
= {x.code: x for x in self.__all_accounts} = {x.code: x for x in self.__all_accounts}
self.accounts.append(BalanceSheetAccount(account=account_by_code[code], self.accounts.append(ReportAccount(account=account_by_code[code],
amount=amount, amount=amount,
url=url)) url=url))
class CSVHalfRow: class CSVHalfRow:
@ -399,7 +399,7 @@ class BalanceSheet(BaseReport):
:return: None. :return: None.
""" """
balances: list[BalanceSheetAccount] = AccountCollector( balances: list[ReportAccount] = AccountCollector(
self.__currency, self.__period).accounts self.__currency, self.__period).accounts
titles: list[BaseAccount] = BaseAccount.query\ titles: list[BaseAccount] = BaseAccount.query\

View File

@ -36,11 +36,11 @@ from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
class IncomeStatementAccount: class ReportAccount:
"""An account in the income statement.""" """An account in the report."""
def __init__(self, account: Account, amount: Decimal, url: str): def __init__(self, account: Account, amount: Decimal, url: str):
"""Constructs an account in the income statement. """Constructs an account in the report.
:param account: The account. :param account: The account.
:param amount: The amount. :param amount: The amount.
@ -78,7 +78,7 @@ class Subsection:
""" """
self.title: BaseAccount = title self.title: BaseAccount = title
"""The title account.""" """The title account."""
self.accounts: list[IncomeStatementAccount] = [] self.accounts: list[ReportAccount] = []
"""The accounts in the subsection.""" """The accounts in the subsection."""
@property @property
@ -225,7 +225,7 @@ class IncomeStatement(BaseReport):
:return: None. :return: None.
""" """
balances: list[IncomeStatementAccount] = self.__query_balances() balances: list[ReportAccount] = self.__query_balances()
titles: list[BaseAccount] = BaseAccount.query\ titles: list[BaseAccount] = BaseAccount.query\
.filter(BaseAccount.code.in_({"4", "5", "6", "7", "8", "9"})).all() .filter(BaseAccount.code.in_({"4", "5", "6", "7", "8", "9"})).all()
@ -257,7 +257,7 @@ class IncomeStatement(BaseReport):
total = total + section.total total = total + section.total
section.accumulated.amount = total section.accumulated.amount = total
def __query_balances(self) -> list[IncomeStatementAccount]: def __query_balances(self) -> list[ReportAccount]:
"""Queries and returns the balances. """Queries and returns the balances.
:return: The balances. :return: The balances.
@ -298,9 +298,9 @@ class IncomeStatement(BaseReport):
currency=self.__currency, account=account, currency=self.__currency, account=account,
period=self.__period) period=self.__period)
return [IncomeStatementAccount(account=accounts[x.account_id], return [ReportAccount(account=accounts[x.account_id],
amount=x.balance, amount=x.balance,
url=get_url(accounts[x.account_id])) url=get_url(accounts[x.account_id]))
for x in balances] for x in balances]
def csv(self) -> Response: def csv(self) -> Response:

View File

@ -35,11 +35,11 @@ from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
class TrialBalanceAccount: class ReportAccount:
"""An account in the trial balance.""" """An account in the report."""
def __init__(self, account: Account, amount: Decimal, url: str): def __init__(self, account: Account, amount: Decimal, url: str):
"""Constructs an account in the trial balance. """Constructs an account in the report.
:param account: The account. :param account: The account.
:param amount: The amount. :param amount: The amount.
@ -103,7 +103,7 @@ class PageParams(BasePageParams):
def __init__(self, currency: Currency, def __init__(self, currency: Currency,
period: Period, period: Period,
accounts: list[TrialBalanceAccount], accounts: list[ReportAccount],
total: TrialBalanceTotal): total: TrialBalanceTotal):
"""Constructs the HTML page parameters. """Constructs the HTML page parameters.
@ -116,7 +116,7 @@ class PageParams(BasePageParams):
"""The currency.""" """The currency."""
self.period: Period = period self.period: Period = period
"""The period.""" """The period."""
self.accounts: list[TrialBalanceAccount] = accounts self.accounts: list[ReportAccount] = accounts
"""The accounts in the trial balance.""" """The accounts in the trial balance."""
self.total: TrialBalanceTotal = total self.total: TrialBalanceTotal = total
"""The total of the trial balance.""" """The total of the trial balance."""
@ -176,7 +176,7 @@ class TrialBalance(BaseReport):
"""The currency.""" """The currency."""
self.__period: Period = period self.__period: Period = period
"""The period.""" """The period."""
self.__accounts: list[TrialBalanceAccount] self.__accounts: list[ReportAccount]
"""The accounts in the trial balance.""" """The accounts in the trial balance."""
self.__total: TrialBalanceTotal self.__total: TrialBalanceTotal
"""The total of the trial balance.""" """The total of the trial balance."""
@ -220,9 +220,9 @@ class TrialBalance(BaseReport):
currency=self.__currency, account=account, currency=self.__currency, account=account,
period=self.__period) period=self.__period)
self.__accounts = [TrialBalanceAccount(account=accounts[x.id], self.__accounts = [ReportAccount(account=accounts[x.id],
amount=x.balance, amount=x.balance,
url=get_url(accounts[x.id])) url=get_url(accounts[x.id]))
for x in balances] for x in balances]
self.__total = TrialBalanceTotal( self.__total = TrialBalanceTotal(
sum([x.debit for x in self.__accounts if x.debit is not None]), sum([x.debit for x in self.__accounts if x.debit is not None]),