Renamed the "accounting.report.reports.utils.get_url" module to "accounting.report.reports.utils.urls", and shortened the names of the utilities, for readability.

This commit is contained in:
依瑪貓 2023-03-09 11:50:02 +08:00
parent 140d3c6010
commit df53f06094
8 changed files with 51 additions and 61 deletions

View File

@ -30,12 +30,11 @@ from accounting.report.period import Period
from .utils.base_page_params import BasePageParams from .utils.base_page_params import BasePageParams
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.get_url import get_ledger_url, get_balance_sheet_url, \
get_income_statement_url
from .utils.option_link import OptionLink from .utils.option_link import OptionLink
from .utils.period_choosers import BalanceSheetPeriodChooser from .utils.period_choosers import BalanceSheetPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
from .utils.report_type import ReportType from .utils.report_type import ReportType
from .utils.urls import ledger_url, balance_sheet_url, income_statement_url
class ReportAccount: class ReportAccount:
@ -149,7 +148,7 @@ class AccountCollector:
self.accounts: list[ReportAccount] \ self.accounts: list[ReportAccount] \
= [ReportAccount(account=account_by_id[x.id], = [ReportAccount(account=account_by_id[x.id],
amount=x.balance, amount=x.balance,
url=get_ledger_url(self.__currency, url=ledger_url(self.__currency,
account_by_id[x.id], account_by_id[x.id],
self.__period)) self.__period))
for x in account_balances] for x in account_balances]
@ -169,7 +168,7 @@ class AccountCollector:
self.__add_owner_s_equity( self.__add_owner_s_equity(
Account.ACCUMULATED_CHANGE_CODE, Account.ACCUMULATED_CHANGE_CODE,
self.__query_accumulated(), self.__query_accumulated(),
get_income_statement_url(self.__currency, self.__period.before)) income_statement_url(self.__currency, self.__period.before))
def __query_accumulated(self) -> Decimal | None: def __query_accumulated(self) -> Decimal | None:
"""Queries and returns the accumulated profit or loss. """Queries and returns the accumulated profit or loss.
@ -191,7 +190,7 @@ class AccountCollector:
self.__add_owner_s_equity( self.__add_owner_s_equity(
Account.NET_CHANGE_CODE, Account.NET_CHANGE_CODE,
self.__query_currency_period(), self.__query_currency_period(),
get_income_statement_url(self.__currency, self.__period)) income_statement_url(self.__currency, self.__period))
def __query_currency_period(self) -> Decimal | None: def __query_currency_period(self) -> Decimal | None:
"""Queries and returns the net income or loss for current period. """Queries and returns the net income or loss for current period.
@ -348,7 +347,7 @@ class PageParams(BasePageParams):
:return: The currency options. :return: The currency options.
""" """
return self._get_currency_options( return self._get_currency_options(
lambda x: get_balance_sheet_url(x, self.period), self.currency) lambda x: balance_sheet_url(x, self.period), self.currency)
class BalanceSheet(BaseReport): class BalanceSheet(BaseReport):

View File

@ -33,7 +33,7 @@ from accounting.utils.pagination import Pagination
from .utils.base_page_params import BasePageParams from .utils.base_page_params import BasePageParams
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.get_url import get_income_expenses_url from .utils.urls import income_expenses_url
from .utils.option_link import OptionLink from .utils.option_link import OptionLink
from .utils.period_choosers import IncomeExpensesPeriodChooser from .utils.period_choosers import IncomeExpensesPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
@ -324,7 +324,7 @@ class PageParams(BasePageParams):
:return: The currency options. :return: The currency options.
""" """
return self._get_currency_options( return self._get_currency_options(
lambda x: get_income_expenses_url(x, self.account, self.period), lambda x: income_expenses_url(x, self.account, self.period),
self.currency) self.currency)
@property @property
@ -337,7 +337,7 @@ class PageParams(BasePageParams):
= IncomeExpensesAccount.current_assets_and_liabilities() = IncomeExpensesAccount.current_assets_and_liabilities()
options: list[OptionLink] \ options: list[OptionLink] \
= [OptionLink(str(current_al), = [OptionLink(str(current_al),
get_income_expenses_url(self.currency, current_al, income_expenses_url(self.currency, current_al,
self.period), self.period),
self.account.id == 0)] self.account.id == 0)]
in_use: sa.Select = sa.Select(JournalEntry.account_id)\ in_use: sa.Select = sa.Select(JournalEntry.account_id)\
@ -349,7 +349,7 @@ class PageParams(BasePageParams):
Account.base_code.startswith("22")))\ Account.base_code.startswith("22")))\
.group_by(JournalEntry.account_id) .group_by(JournalEntry.account_id)
options.extend([OptionLink(str(x), options.extend([OptionLink(str(x),
get_income_expenses_url( income_expenses_url(
self.currency, self.currency,
IncomeExpensesAccount(x), IncomeExpensesAccount(x),
self.period), self.period),

View File

@ -30,7 +30,7 @@ from accounting.report.period import Period
from .utils.base_page_params import BasePageParams from .utils.base_page_params import BasePageParams
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.get_url import get_ledger_url, get_income_statement_url from .utils.urls import ledger_url, income_statement_url
from .utils.option_link import OptionLink from .utils.option_link import OptionLink
from .utils.period_choosers import IncomeStatementPeriodChooser from .utils.period_choosers import IncomeStatementPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
@ -188,8 +188,7 @@ class PageParams(BasePageParams):
:return: The currency options. :return: The currency options.
""" """
return self._get_currency_options( return self._get_currency_options(
lambda x: get_income_statement_url(x, self.period), lambda x: income_statement_url(x, self.period), self.currency)
self.currency)
class IncomeStatement(BaseReport): class IncomeStatement(BaseReport):
@ -276,7 +275,7 @@ class IncomeStatement(BaseReport):
.filter(Account.id.in_([x.id for x in balances])).all()} .filter(Account.id.in_([x.id for x in balances])).all()}
return [ReportAccount(account=accounts[x.id], return [ReportAccount(account=accounts[x.id],
amount=x.balance, amount=x.balance,
url=get_ledger_url(self.__currency, url=ledger_url(self.__currency,
accounts[x.id], accounts[x.id],
self.__period)) self.__period))
for x in balances] for x in balances]

View File

@ -32,7 +32,7 @@ from accounting.utils.pagination import Pagination
from .utils.base_page_params import BasePageParams from .utils.base_page_params import BasePageParams
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.get_url import get_ledger_url from .utils.urls import ledger_url
from .utils.option_link import OptionLink from .utils.option_link import OptionLink
from .utils.period_choosers import LedgerPeriodChooser from .utils.period_choosers import LedgerPeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
@ -292,8 +292,7 @@ class PageParams(BasePageParams):
:return: The currency options. :return: The currency options.
""" """
return self._get_currency_options( return self._get_currency_options(
lambda x: get_ledger_url(x, self.account, self.period), lambda x: ledger_url(x, self.account, self.period), self.currency)
self.currency)
@property @property
def account_options(self) -> list[OptionLink]: def account_options(self) -> list[OptionLink]:
@ -304,8 +303,7 @@ class PageParams(BasePageParams):
in_use: sa.Select = sa.Select(JournalEntry.account_id)\ in_use: sa.Select = sa.Select(JournalEntry.account_id)\
.filter(JournalEntry.currency_code == self.currency.code)\ .filter(JournalEntry.currency_code == self.currency.code)\
.group_by(JournalEntry.account_id) .group_by(JournalEntry.account_id)
return [OptionLink(str(x), get_ledger_url(self.currency, x, return [OptionLink(str(x), ledger_url(self.currency, x, self.period),
self.period),
x.id == self.account.id) x.id == self.account.id)
for x in Account.query.filter(Account.id.in_(in_use)) for x in Account.query.filter(Account.id.in_(in_use))
.order_by(Account.base_code, Account.no).all()] .order_by(Account.base_code, Account.no).all()]

View File

@ -29,7 +29,7 @@ from accounting.report.period import Period
from .utils.base_page_params import BasePageParams from .utils.base_page_params import BasePageParams
from .utils.base_report import BaseReport from .utils.base_report import BaseReport
from .utils.csv_export import BaseCSVRow, csv_download, period_spec from .utils.csv_export import BaseCSVRow, csv_download, period_spec
from .utils.get_url import get_ledger_url, get_trial_balance_url from .utils.urls import ledger_url, trial_balance_url
from .utils.option_link import OptionLink from .utils.option_link import OptionLink
from .utils.period_choosers import TrialBalancePeriodChooser from .utils.period_choosers import TrialBalancePeriodChooser
from .utils.report_chooser import ReportChooser from .utils.report_chooser import ReportChooser
@ -150,7 +150,7 @@ class PageParams(BasePageParams):
:return: The currency options. :return: The currency options.
""" """
return self._get_currency_options( return self._get_currency_options(
lambda x: get_trial_balance_url(x, self.period), self.currency) lambda x: trial_balance_url(x, self.period), self.currency)
class TrialBalance(BaseReport): class TrialBalance(BaseReport):
@ -197,7 +197,7 @@ class TrialBalance(BaseReport):
.filter(Account.id.in_([x.id for x in balances])).all()} .filter(Account.id.in_([x.id for x in balances])).all()}
self.__accounts = [ReportAccount(account=accounts[x.id], self.__accounts = [ReportAccount(account=accounts[x.id],
amount=x.balance, amount=x.balance,
url=get_ledger_url(self.__currency, url=ledger_url(self.__currency,
accounts[x.id], accounts[x.id],
self.__period)) self.__period))
for x in balances] for x in balances]

View File

@ -28,9 +28,8 @@ from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import YearPeriod, Period, ThisMonth, \ from accounting.report.period import YearPeriod, Period, ThisMonth, \
LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \ LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \
TemplatePeriod TemplatePeriod
from .get_url import get_journal_url, get_ledger_url, \ from .urls import journal_url, ledger_url, income_expenses_url, \
get_income_expenses_url, get_trial_balance_url, get_income_statement_url, \ trial_balance_url, income_statement_url, balance_sheet_url
get_balance_sheet_url
class PeriodChooser(ABC): class PeriodChooser(ABC):
@ -113,7 +112,7 @@ class JournalPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_journal_url(period) return journal_url(period)
class LedgerPeriodChooser(PeriodChooser): class LedgerPeriodChooser(PeriodChooser):
@ -130,7 +129,7 @@ class LedgerPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_ledger_url(self.currency, self.account, period) return ledger_url(self.currency, self.account, period)
class IncomeExpensesPeriodChooser(PeriodChooser): class IncomeExpensesPeriodChooser(PeriodChooser):
@ -147,7 +146,7 @@ class IncomeExpensesPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_income_expenses_url(self.currency, self.account, period) return income_expenses_url(self.currency, self.account, period)
class TrialBalancePeriodChooser(PeriodChooser): class TrialBalancePeriodChooser(PeriodChooser):
@ -162,7 +161,7 @@ class TrialBalancePeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_trial_balance_url(self.currency, period) return trial_balance_url(self.currency, period)
class IncomeStatementPeriodChooser(PeriodChooser): class IncomeStatementPeriodChooser(PeriodChooser):
@ -177,7 +176,7 @@ class IncomeStatementPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_income_statement_url(self.currency, period) return income_statement_url(self.currency, period)
class BalanceSheetPeriodChooser(PeriodChooser): class BalanceSheetPeriodChooser(PeriodChooser):
@ -192,4 +191,4 @@ class BalanceSheetPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
return get_balance_sheet_url(self.currency, period) return balance_sheet_url(self.currency, period)

View File

@ -31,11 +31,10 @@ from accounting.models import Currency, Account
from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import Period from accounting.report.period import Period
from accounting.template_globals import default_currency_code from accounting.template_globals import default_currency_code
from .get_url import get_journal_url, get_ledger_url, \
get_income_expenses_url, get_trial_balance_url, get_income_statement_url, \
get_balance_sheet_url
from .option_link import OptionLink from .option_link import OptionLink
from .report_type import ReportType from .report_type import ReportType
from .urls import journal_url, ledger_url, income_expenses_url, \
trial_balance_url, income_statement_url, balance_sheet_url
class ReportChooser: class ReportChooser:
@ -88,7 +87,7 @@ class ReportChooser:
:return: The journal. :return: The journal.
""" """
return OptionLink(gettext("Journal"), get_journal_url(self.__period), return OptionLink(gettext("Journal"), journal_url(self.__period),
self.__active_report == ReportType.JOURNAL, self.__active_report == ReportType.JOURNAL,
fa_icon="fa-solid fa-book") fa_icon="fa-solid fa-book")
@ -99,7 +98,7 @@ class ReportChooser:
:return: The ledger. :return: The ledger.
""" """
return OptionLink(gettext("Ledger"), return OptionLink(gettext("Ledger"),
get_ledger_url(self.__currency, self.__account, ledger_url(self.__currency, self.__account,
self.__period), self.__period),
self.__active_report == ReportType.LEDGER, self.__active_report == ReportType.LEDGER,
fa_icon="fa-solid fa-clipboard") fa_icon="fa-solid fa-clipboard")
@ -114,8 +113,7 @@ class ReportChooser:
if not re.match(r"[12][12]", account.base_code): if not re.match(r"[12][12]", account.base_code):
account: Account = Account.cash() account: Account = Account.cash()
return OptionLink(gettext("Income and Expenses Log"), return OptionLink(gettext("Income and Expenses Log"),
get_income_expenses_url( income_expenses_url(self.__currency,
self.__currency,
IncomeExpensesAccount(account), IncomeExpensesAccount(account),
self.__period), self.__period),
self.__active_report == ReportType.INCOME_EXPENSES, self.__active_report == ReportType.INCOME_EXPENSES,
@ -128,8 +126,7 @@ class ReportChooser:
:return: The trial balance. :return: The trial balance.
""" """
return OptionLink(gettext("Trial Balance"), return OptionLink(gettext("Trial Balance"),
get_trial_balance_url(self.__currency, trial_balance_url(self.__currency, self.__period),
self.__period),
self.__active_report == ReportType.TRIAL_BALANCE, self.__active_report == ReportType.TRIAL_BALANCE,
fa_icon="fa-solid fa-scale-unbalanced") fa_icon="fa-solid fa-scale-unbalanced")
@ -140,8 +137,7 @@ class ReportChooser:
:return: The income statement. :return: The income statement.
""" """
return OptionLink(gettext("Income Statement"), return OptionLink(gettext("Income Statement"),
get_income_statement_url(self.__currency, income_statement_url(self.__currency, self.__period),
self.__period),
self.__active_report == ReportType.INCOME_STATEMENT, self.__active_report == ReportType.INCOME_STATEMENT,
fa_icon="fa-solid fa-file-invoice-dollar") fa_icon="fa-solid fa-file-invoice-dollar")
@ -152,8 +148,7 @@ class ReportChooser:
:return: The balance sheet. :return: The balance sheet.
""" """
return OptionLink(gettext("Balance Sheet"), return OptionLink(gettext("Balance Sheet"),
get_balance_sheet_url(self.__currency, balance_sheet_url(self.__currency, self.__period),
self.__period),
self.__active_report == ReportType.BALANCE_SHEET, self.__active_report == ReportType.BALANCE_SHEET,
fa_icon="fa-solid fa-scale-balanced") fa_icon="fa-solid fa-scale-balanced")

View File

@ -24,7 +24,7 @@ from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import Period from accounting.report.period import Period
def get_journal_url(period: Period) \ def journal_url(period: Period) \
-> str: -> str:
"""Returns the URL of a journal. """Returns the URL of a journal.
@ -36,7 +36,7 @@ def get_journal_url(period: Period) \
return url_for("accounting.report.journal", period=period) return url_for("accounting.report.journal", period=period)
def get_ledger_url(currency: Currency, account: Account, period: Period) \ def ledger_url(currency: Currency, account: Account, period: Period) \
-> str: -> str:
"""Returns the URL of a ledger. """Returns the URL of a ledger.
@ -53,7 +53,7 @@ def get_ledger_url(currency: Currency, account: Account, period: Period) \
period=period) period=period)
def get_income_expenses_url(currency: Currency, account: IncomeExpensesAccount, def income_expenses_url(currency: Currency, account: IncomeExpensesAccount,
period: Period) -> str: period: Period) -> str:
"""Returns the URL of an income and expenses log. """Returns the URL of an income and expenses log.
@ -70,7 +70,7 @@ def get_income_expenses_url(currency: Currency, account: IncomeExpensesAccount,
period=period) period=period)
def get_trial_balance_url(currency: Currency, period: Period) -> str: def trial_balance_url(currency: Currency, period: Period) -> str:
"""Returns the URL of a trial balance. """Returns the URL of a trial balance.
:param currency: The currency. :param currency: The currency.
@ -84,7 +84,7 @@ def get_trial_balance_url(currency: Currency, period: Period) -> str:
currency=currency, period=period) currency=currency, period=period)
def get_income_statement_url(currency: Currency, period: Period) -> str: def income_statement_url(currency: Currency, period: Period) -> str:
"""Returns the URL of an income statement. """Returns the URL of an income statement.
:param currency: The currency. :param currency: The currency.
@ -98,7 +98,7 @@ def get_income_statement_url(currency: Currency, period: Period) -> str:
currency=currency, period=period) currency=currency, period=period)
def get_balance_sheet_url(currency: Currency, period: Period) -> str: def balance_sheet_url(currency: Currency, period: Period) -> str:
"""Returns the URL of a balance sheet. """Returns the URL of a balance sheet.
:param currency: The currency. :param currency: The currency.