From df53f060946a46eb5726a6011dc0ecf2c5466590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 9 Mar 2023 11:50:02 +0800 Subject: [PATCH] Renamed the "accounting.report.reports.utils.get_url" module to "accounting.report.reports.utils.urls", and shortened the names of the utilities, for readability. --- .../report/reports/balance_sheet.py | 15 +++++------ .../report/reports/income_expenses.py | 10 +++---- .../report/reports/income_statement.py | 11 ++++---- src/accounting/report/reports/ledger.py | 8 +++--- .../report/reports/trial_balance.py | 10 +++---- .../report/reports/utils/period_choosers.py | 17 ++++++------ .../report/reports/utils/report_chooser.py | 27 ++++++++----------- .../reports/utils/{get_url.py => urls.py} | 14 +++++----- 8 files changed, 51 insertions(+), 61 deletions(-) rename src/accounting/report/reports/utils/{get_url.py => urls.py} (88%) diff --git a/src/accounting/report/reports/balance_sheet.py b/src/accounting/report/reports/balance_sheet.py index aab8570..e9b9ea0 100644 --- a/src/accounting/report/reports/balance_sheet.py +++ b/src/accounting/report/reports/balance_sheet.py @@ -30,12 +30,11 @@ from accounting.report.period import Period from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport 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.period_choosers import BalanceSheetPeriodChooser from .utils.report_chooser import ReportChooser from .utils.report_type import ReportType +from .utils.urls import ledger_url, balance_sheet_url, income_statement_url class ReportAccount: @@ -149,9 +148,9 @@ class AccountCollector: self.accounts: list[ReportAccount] \ = [ReportAccount(account=account_by_id[x.id], amount=x.balance, - url=get_ledger_url(self.__currency, - account_by_id[x.id], - self.__period)) + url=ledger_url(self.__currency, + account_by_id[x.id], + self.__period)) for x in account_balances] self.__add_accumulated() self.__add_current_period() @@ -169,7 +168,7 @@ class AccountCollector: self.__add_owner_s_equity( Account.ACCUMULATED_CHANGE_CODE, 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: """Queries and returns the accumulated profit or loss. @@ -191,7 +190,7 @@ class AccountCollector: self.__add_owner_s_equity( Account.NET_CHANGE_CODE, 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: """Queries and returns the net income or loss for current period. @@ -348,7 +347,7 @@ class PageParams(BasePageParams): :return: The 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): diff --git a/src/accounting/report/reports/income_expenses.py b/src/accounting/report/reports/income_expenses.py index 31e9632..9db70c0 100644 --- a/src/accounting/report/reports/income_expenses.py +++ b/src/accounting/report/reports/income_expenses.py @@ -33,7 +33,7 @@ from accounting.utils.pagination import Pagination from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport 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.period_choosers import IncomeExpensesPeriodChooser from .utils.report_chooser import ReportChooser @@ -324,7 +324,7 @@ class PageParams(BasePageParams): :return: The 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) @property @@ -337,8 +337,8 @@ class PageParams(BasePageParams): = IncomeExpensesAccount.current_assets_and_liabilities() options: list[OptionLink] \ = [OptionLink(str(current_al), - get_income_expenses_url(self.currency, current_al, - self.period), + income_expenses_url(self.currency, current_al, + self.period), self.account.id == 0)] in_use: sa.Select = sa.Select(JournalEntry.account_id)\ .join(Account)\ @@ -349,7 +349,7 @@ class PageParams(BasePageParams): Account.base_code.startswith("22")))\ .group_by(JournalEntry.account_id) options.extend([OptionLink(str(x), - get_income_expenses_url( + income_expenses_url( self.currency, IncomeExpensesAccount(x), self.period), diff --git a/src/accounting/report/reports/income_statement.py b/src/accounting/report/reports/income_statement.py index f053d03..2363e4f 100644 --- a/src/accounting/report/reports/income_statement.py +++ b/src/accounting/report/reports/income_statement.py @@ -30,7 +30,7 @@ from accounting.report.period import Period from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport 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.period_choosers import IncomeStatementPeriodChooser from .utils.report_chooser import ReportChooser @@ -188,8 +188,7 @@ class PageParams(BasePageParams): :return: The currency options. """ return self._get_currency_options( - lambda x: get_income_statement_url(x, self.period), - self.currency) + lambda x: income_statement_url(x, self.period), self.currency) class IncomeStatement(BaseReport): @@ -276,9 +275,9 @@ class IncomeStatement(BaseReport): .filter(Account.id.in_([x.id for x in balances])).all()} return [ReportAccount(account=accounts[x.id], amount=x.balance, - url=get_ledger_url(self.__currency, - accounts[x.id], - self.__period)) + url=ledger_url(self.__currency, + accounts[x.id], + self.__period)) for x in balances] def csv(self) -> Response: diff --git a/src/accounting/report/reports/ledger.py b/src/accounting/report/reports/ledger.py index e89adc4..3fcda4b 100644 --- a/src/accounting/report/reports/ledger.py +++ b/src/accounting/report/reports/ledger.py @@ -32,7 +32,7 @@ from accounting.utils.pagination import Pagination from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport 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.period_choosers import LedgerPeriodChooser from .utils.report_chooser import ReportChooser @@ -292,8 +292,7 @@ class PageParams(BasePageParams): :return: The currency options. """ return self._get_currency_options( - lambda x: get_ledger_url(x, self.account, self.period), - self.currency) + lambda x: ledger_url(x, self.account, self.period), self.currency) @property def account_options(self) -> list[OptionLink]: @@ -304,8 +303,7 @@ class PageParams(BasePageParams): in_use: sa.Select = sa.Select(JournalEntry.account_id)\ .filter(JournalEntry.currency_code == self.currency.code)\ .group_by(JournalEntry.account_id) - return [OptionLink(str(x), get_ledger_url(self.currency, x, - self.period), + return [OptionLink(str(x), ledger_url(self.currency, x, self.period), x.id == self.account.id) for x in Account.query.filter(Account.id.in_(in_use)) .order_by(Account.base_code, Account.no).all()] diff --git a/src/accounting/report/reports/trial_balance.py b/src/accounting/report/reports/trial_balance.py index b0dbfd8..1944548 100644 --- a/src/accounting/report/reports/trial_balance.py +++ b/src/accounting/report/reports/trial_balance.py @@ -29,7 +29,7 @@ from accounting.report.period import Period from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport 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.period_choosers import TrialBalancePeriodChooser from .utils.report_chooser import ReportChooser @@ -150,7 +150,7 @@ class PageParams(BasePageParams): :return: The 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): @@ -197,9 +197,9 @@ class TrialBalance(BaseReport): .filter(Account.id.in_([x.id for x in balances])).all()} self.__accounts = [ReportAccount(account=accounts[x.id], amount=x.balance, - url=get_ledger_url(self.__currency, - accounts[x.id], - self.__period)) + url=ledger_url(self.__currency, + accounts[x.id], + self.__period)) for x in balances] self.__total = Total( sum([x.debit for x in self.__accounts if x.debit is not None]), diff --git a/src/accounting/report/reports/utils/period_choosers.py b/src/accounting/report/reports/utils/period_choosers.py index 5d896e1..f34ee73 100644 --- a/src/accounting/report/reports/utils/period_choosers.py +++ b/src/accounting/report/reports/utils/period_choosers.py @@ -28,9 +28,8 @@ from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import YearPeriod, Period, ThisMonth, \ LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \ TemplatePeriod -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 .urls import journal_url, ledger_url, income_expenses_url, \ + trial_balance_url, income_statement_url, balance_sheet_url class PeriodChooser(ABC): @@ -113,7 +112,7 @@ class JournalPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) def _url_for(self, period: Period) -> str: - return get_journal_url(period) + return journal_url(period) class LedgerPeriodChooser(PeriodChooser): @@ -130,7 +129,7 @@ class LedgerPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) 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): @@ -147,7 +146,7 @@ class IncomeExpensesPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) 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): @@ -162,7 +161,7 @@ class TrialBalancePeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) 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): @@ -177,7 +176,7 @@ class IncomeStatementPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) 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): @@ -192,4 +191,4 @@ class BalanceSheetPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) def _url_for(self, period: Period) -> str: - return get_balance_sheet_url(self.currency, period) + return balance_sheet_url(self.currency, period) diff --git a/src/accounting/report/reports/utils/report_chooser.py b/src/accounting/report/reports/utils/report_chooser.py index 02c3154..1d52b90 100644 --- a/src/accounting/report/reports/utils/report_chooser.py +++ b/src/accounting/report/reports/utils/report_chooser.py @@ -31,11 +31,10 @@ from accounting.models import Currency, Account from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import Period 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 .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: @@ -88,7 +87,7 @@ class ReportChooser: :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, fa_icon="fa-solid fa-book") @@ -99,8 +98,8 @@ class ReportChooser: :return: The ledger. """ return OptionLink(gettext("Ledger"), - get_ledger_url(self.__currency, self.__account, - self.__period), + ledger_url(self.__currency, self.__account, + self.__period), self.__active_report == ReportType.LEDGER, fa_icon="fa-solid fa-clipboard") @@ -114,10 +113,9 @@ class ReportChooser: if not re.match(r"[12][12]", account.base_code): account: Account = Account.cash() return OptionLink(gettext("Income and Expenses Log"), - get_income_expenses_url( - self.__currency, - IncomeExpensesAccount(account), - self.__period), + income_expenses_url(self.__currency, + IncomeExpensesAccount(account), + self.__period), self.__active_report == ReportType.INCOME_EXPENSES, fa_icon="fa-solid fa-money-bill-wave") @@ -128,8 +126,7 @@ class ReportChooser: :return: The trial balance. """ return OptionLink(gettext("Trial Balance"), - get_trial_balance_url(self.__currency, - self.__period), + trial_balance_url(self.__currency, self.__period), self.__active_report == ReportType.TRIAL_BALANCE, fa_icon="fa-solid fa-scale-unbalanced") @@ -140,8 +137,7 @@ class ReportChooser: :return: The income statement. """ return OptionLink(gettext("Income Statement"), - get_income_statement_url(self.__currency, - self.__period), + income_statement_url(self.__currency, self.__period), self.__active_report == ReportType.INCOME_STATEMENT, fa_icon="fa-solid fa-file-invoice-dollar") @@ -152,8 +148,7 @@ class ReportChooser: :return: The balance sheet. """ return OptionLink(gettext("Balance Sheet"), - get_balance_sheet_url(self.__currency, - self.__period), + balance_sheet_url(self.__currency, self.__period), self.__active_report == ReportType.BALANCE_SHEET, fa_icon="fa-solid fa-scale-balanced") diff --git a/src/accounting/report/reports/utils/get_url.py b/src/accounting/report/reports/utils/urls.py similarity index 88% rename from src/accounting/report/reports/utils/get_url.py rename to src/accounting/report/reports/utils/urls.py index 61c99d8..4d22d49 100644 --- a/src/accounting/report/reports/utils/get_url.py +++ b/src/accounting/report/reports/utils/urls.py @@ -24,7 +24,7 @@ from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import Period -def get_journal_url(period: Period) \ +def journal_url(period: Period) \ -> str: """Returns the URL of a journal. @@ -36,7 +36,7 @@ def get_journal_url(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: """Returns the URL of a ledger. @@ -53,8 +53,8 @@ def get_ledger_url(currency: Currency, account: Account, period: Period) \ period=period) -def get_income_expenses_url(currency: Currency, account: IncomeExpensesAccount, - period: Period) -> str: +def income_expenses_url(currency: Currency, account: IncomeExpensesAccount, + period: Period) -> str: """Returns the URL of an income and expenses log. :param currency: The currency. @@ -70,7 +70,7 @@ def get_income_expenses_url(currency: Currency, account: IncomeExpensesAccount, 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. :param currency: The currency. @@ -84,7 +84,7 @@ def get_trial_balance_url(currency: Currency, period: Period) -> str: 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. :param currency: The currency. @@ -98,7 +98,7 @@ def get_income_statement_url(currency: Currency, period: Period) -> str: 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. :param currency: The currency.