From 567004f7d9f1249822b79b7c4e2f157b2e39c459 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 15:42:44 +0800 Subject: [PATCH] Renamed IncomeExpensesAccount to CurrentAccount. --- src/accounting/option/forms.py | 10 ++++----- src/accounting/option/options.py | 10 ++++----- src/accounting/report/converters.py | 12 +++++----- .../report/reports/income_expenses.py | 22 +++++++++---------- src/accounting/report/utils/report_chooser.py | 4 ++-- src/accounting/report/utils/urls.py | 4 ++-- src/accounting/report/views.py | 9 ++++---- .../templates/accounting/option/form.html | 2 +- .../{ie_account.py => current_account.py} | 18 +++++++-------- 9 files changed, 45 insertions(+), 46 deletions(-) rename src/accounting/utils/{ie_account.py => current_account.py} (84%) diff --git a/src/accounting/option/forms.py b/src/accounting/option/forms.py index ae8b5f0..29f732b 100644 --- a/src/accounting/option/forms.py +++ b/src/accounting/option/forms.py @@ -28,7 +28,7 @@ from wtforms.validators import DataRequired, ValidationError from accounting.forms import CURRENCY_REQUIRED, CurrencyExists from accounting.locale import lazy_gettext from accounting.models import Account -from accounting.utils.ie_account import IncomeExpensesAccount, ie_accounts +from accounting.utils.current_account import CurrentAccount, current_accounts from accounting.utils.strip_text import strip_text from .options import Options @@ -242,9 +242,9 @@ class OptionForm(FlaskForm): obj.recurring_data = self.recurring.form.as_data @property - def ie_accounts(self) -> list[IncomeExpensesAccount]: - """Returns the accounts for the income and expenses log. + def current_accounts(self) -> list[CurrentAccount]: + """Returns the current accounts. - :return: The accounts for the income and expenses log. + :return: The current accounts. """ - return ie_accounts() + return current_accounts() diff --git a/src/accounting/option/options.py b/src/accounting/option/options.py index b899d52..9d09324 100644 --- a/src/accounting/option/options.py +++ b/src/accounting/option/options.py @@ -23,7 +23,7 @@ import sqlalchemy as sa from accounting import db from accounting.models import Option, Account -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount from accounting.utils.user import get_current_user_pk @@ -108,15 +108,15 @@ class Options: self.__set_option("default_ie_account", value) @property - def default_ie_account(self) -> IncomeExpensesAccount: + def default_ie_account(self) -> CurrentAccount: """Returns the default account code for the income and expenses log. :return: The default account code for the income and expenses log. """ if self.default_ie_account_code \ - == IncomeExpensesAccount.CURRENT_AL_CODE: - return IncomeExpensesAccount.current_assets_and_liabilities() - return IncomeExpensesAccount( + == CurrentAccount.CURRENT_AL_CODE: + return CurrentAccount.current_assets_and_liabilities() + return CurrentAccount( Account.find_by_code(self.default_ie_account_code)) @property diff --git a/src/accounting/report/converters.py b/src/accounting/report/converters.py index 753a45c..a92af0b 100644 --- a/src/accounting/report/converters.py +++ b/src/accounting/report/converters.py @@ -23,7 +23,7 @@ from flask import abort from werkzeug.routing import BaseConverter from accounting.models import Account -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount from .period import Period, get_period @@ -55,22 +55,22 @@ class IncomeExpensesAccountConverter(BaseConverter): """The supplier converter to convert the income and expenses log pseudo account code from and to the corresponding pseudo account in the routes.""" - def to_python(self, value: str) -> IncomeExpensesAccount: + def to_python(self, value: str) -> CurrentAccount: """Converts an account code to an account. :param value: The account code. :return: The corresponding account. """ - if value == IncomeExpensesAccount.CURRENT_AL_CODE: - return IncomeExpensesAccount.current_assets_and_liabilities() + if value == CurrentAccount.CURRENT_AL_CODE: + return CurrentAccount.current_assets_and_liabilities() if not re.match("^[12][12]", value): abort(404) account: Account | None = Account.find_by_code(value) if account is None: abort(404) - return IncomeExpensesAccount(account) + return CurrentAccount(account) - def to_url(self, value: IncomeExpensesAccount) -> str: + def to_url(self, value: CurrentAccount) -> str: """Converts an account to account code. :param value: The account. diff --git a/src/accounting/report/reports/income_expenses.py b/src/accounting/report/reports/income_expenses.py index acdcaad..cd5f5a0 100644 --- a/src/accounting/report/reports/income_expenses.py +++ b/src/accounting/report/reports/income_expenses.py @@ -38,7 +38,7 @@ from accounting.report.utils.report_chooser import ReportChooser from accounting.report.utils.report_type import ReportType from accounting.report.utils.urls import income_expenses_url from accounting.utils.cast import be -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount from accounting.utils.pagination import Pagination @@ -84,7 +84,7 @@ class ReportLineItem: class LineItemCollector: """The line item collector.""" - def __init__(self, currency: Currency, account: IncomeExpensesAccount, + def __init__(self, currency: Currency, account: CurrentAccount, period: Period): """Constructs the line item collector. @@ -94,7 +94,7 @@ class LineItemCollector: """ self.__currency: Currency = currency """The currency.""" - self.__account: IncomeExpensesAccount = account + self.__account: CurrentAccount = account """The account.""" self.__period: Period = period """The period""" @@ -173,7 +173,7 @@ class LineItemCollector: @property def __account_condition(self) -> sa.BinaryExpression: - if self.__account.code == IncomeExpensesAccount.CURRENT_AL_CODE: + if self.__account.code == CurrentAccount.CURRENT_AL_CODE: return sa.or_(Account.base_code.startswith("11"), Account.base_code.startswith("12"), Account.base_code.startswith("21"), @@ -264,7 +264,7 @@ class PageParams(BasePageParams): """The HTML page parameters.""" def __init__(self, currency: Currency, - account: IncomeExpensesAccount, + account: CurrentAccount, period: Period, has_data: bool, pagination: Pagination[ReportLineItem], @@ -283,7 +283,7 @@ class PageParams(BasePageParams): """ self.currency: Currency = currency """The currency.""" - self.account: IncomeExpensesAccount = account + self.account: CurrentAccount = account """The account.""" self.period: Period = period """The period.""" @@ -341,8 +341,8 @@ class PageParams(BasePageParams): :return: The account options. """ - current_al: IncomeExpensesAccount \ - = IncomeExpensesAccount.current_assets_and_liabilities() + current_al: CurrentAccount \ + = CurrentAccount.current_assets_and_liabilities() options: list[OptionLink] \ = [OptionLink(str(current_al), income_expenses_url(self.currency, current_al, @@ -360,7 +360,7 @@ class PageParams(BasePageParams): options.extend([OptionLink(str(x), income_expenses_url( self.currency, - IncomeExpensesAccount(x), + CurrentAccount(x), self.period), x.id == self.account.id) for x in Account.query.filter(Account.id.in_(in_use)) @@ -371,7 +371,7 @@ class PageParams(BasePageParams): class IncomeExpenses(BaseReport): """The income and expenses log.""" - def __init__(self, currency: Currency, account: IncomeExpensesAccount, + def __init__(self, currency: Currency, account: CurrentAccount, period: Period): """Constructs an income and expenses log. @@ -381,7 +381,7 @@ class IncomeExpenses(BaseReport): """ self.__currency: Currency = currency """The currency.""" - self.__account: IncomeExpensesAccount = account + self.__account: CurrentAccount = account """The account.""" self.__period: Period = period """The period.""" diff --git a/src/accounting/report/utils/report_chooser.py b/src/accounting/report/utils/report_chooser.py index bef3044..2eb0c08 100644 --- a/src/accounting/report/utils/report_chooser.py +++ b/src/accounting/report/utils/report_chooser.py @@ -30,7 +30,7 @@ from accounting.locale import gettext from accounting.models import Currency, Account from accounting.report.period import Period, get_period from accounting.template_globals import default_currency_code -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount from .option_link import OptionLink from .report_type import ReportType from .urls import journal_url, ledger_url, income_expenses_url, \ @@ -113,7 +113,7 @@ class ReportChooser: account: Account = Account.cash() return OptionLink(gettext("Income and Expenses Log"), income_expenses_url(self.__currency, - IncomeExpensesAccount(account), + CurrentAccount(account), self.__period), self.__active_report == ReportType.INCOME_EXPENSES, fa_icon="fa-solid fa-money-bill-wave") diff --git a/src/accounting/report/utils/urls.py b/src/accounting/report/utils/urls.py index 8943142..efc0ec8 100644 --- a/src/accounting/report/utils/urls.py +++ b/src/accounting/report/utils/urls.py @@ -23,7 +23,7 @@ from accounting.models import Currency, Account from accounting.option.options import options from accounting.report.period import Period from accounting.template_globals import default_currency_code -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount def journal_url(period: Period) \ @@ -55,7 +55,7 @@ def ledger_url(currency: Currency, account: Account, period: Period) \ period=period) -def income_expenses_url(currency: Currency, account: IncomeExpensesAccount, +def income_expenses_url(currency: Currency, account: CurrentAccount, period: Period) -> str: """Returns the URL of an income and expenses log. diff --git a/src/accounting/report/views.py b/src/accounting/report/views.py index 0d72f0f..a1aefee 100644 --- a/src/accounting/report/views.py +++ b/src/accounting/report/views.py @@ -24,7 +24,7 @@ from accounting.models import Currency, Account from accounting.option.options import options from accounting.report.period import Period, get_period from accounting.template_globals import default_currency_code -from accounting.utils.ie_account import IncomeExpensesAccount +from accounting.utils.current_account import CurrentAccount from accounting.utils.permission import has_permission, can_view from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \ IncomeStatement, BalanceSheet, Search @@ -127,8 +127,7 @@ def __get_ledger(currency: Currency, account: Account, period: Period) \ @bp.get("income-expenses//", endpoint="income-expenses-default") @has_permission(can_view) -def get_default_income_expenses(currency: Currency, - account: IncomeExpensesAccount) \ +def get_default_income_expenses(currency: Currency, account: CurrentAccount) \ -> str | Response: """Returns the income and expenses log in the default period. @@ -143,7 +142,7 @@ def get_default_income_expenses(currency: Currency, "income-expenses///", endpoint="income-expenses") @has_permission(can_view) -def get_income_expenses(currency: Currency, account: IncomeExpensesAccount, +def get_income_expenses(currency: Currency, account: CurrentAccount, period: Period) -> str | Response: """Returns the income and expenses log. @@ -155,7 +154,7 @@ def get_income_expenses(currency: Currency, account: IncomeExpensesAccount, return __get_income_expenses(currency, account, period) -def __get_income_expenses(currency: Currency, account: IncomeExpensesAccount, +def __get_income_expenses(currency: Currency, account: CurrentAccount, period: Period) -> str | Response: """Returns the income and expenses log. diff --git a/src/accounting/templates/accounting/option/form.html b/src/accounting/templates/accounting/option/form.html index bfb5fd9..1d9faa4 100644 --- a/src/accounting/templates/accounting/option/form.html +++ b/src/accounting/templates/accounting/option/form.html @@ -46,7 +46,7 @@ First written: 2023/3/22
diff --git a/src/accounting/utils/ie_account.py b/src/accounting/utils/current_account.py similarity index 84% rename from src/accounting/utils/ie_account.py rename to src/accounting/utils/current_account.py index 406c6aa..ce489c3 100644 --- a/src/accounting/utils/ie_account.py +++ b/src/accounting/utils/current_account.py @@ -14,7 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""The pseudo account for the income and expenses log. +"""The current account. """ import typing as t @@ -25,15 +25,15 @@ from accounting.models import Account import sqlalchemy as sa -class IncomeExpensesAccount: - """The pseudo account for the income and expenses log.""" +class CurrentAccount: + """The current account.""" CURRENT_AL_CODE: str = "0000-000" """The account code for the current assets and liabilities.""" def __init__(self, account: Account | None = None): - """Constructs the pseudo account for the income and expenses log. + """Constructs the current account. - :param account: The actual account. + :param account: The account. """ self.account: Account | None = account self.id: int = -1 if account is None else account.id @@ -66,14 +66,14 @@ class IncomeExpensesAccount: return account -def ie_accounts() -> list[IncomeExpensesAccount]: +def current_accounts() -> list[CurrentAccount]: """Returns accounts for the income and expenses log. :return: The accounts for the income and expenses log. """ - accounts: list[IncomeExpensesAccount] \ - = [IncomeExpensesAccount.current_assets_and_liabilities()] - accounts.extend([IncomeExpensesAccount(x) + accounts: list[CurrentAccount] \ + = [CurrentAccount.current_assets_and_liabilities()] + accounts.extend([CurrentAccount(x) for x in db.session.query(Account) .filter(sa.or_(Account.base_code.startswith("11"), Account.base_code.startswith("12"),