From 656762850c3532236d7e7a6d397bc705d488c200 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 07:24:41 +0800 Subject: [PATCH] Moved the IncomeExpensesAccount data model from the "accounting.report.utils.ie_account" module to the "accounting.utils.ie_account" module. --- src/accounting/report/converters.py | 2 +- .../report/reports/income_expenses.py | 2 +- src/accounting/report/utils/ie_account.py | 45 +------------ src/accounting/report/utils/report_chooser.py | 2 +- src/accounting/report/utils/urls.py | 3 +- src/accounting/report/views.py | 3 +- src/accounting/utils/ie_account.py | 64 +++++++++++++++++++ 7 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 src/accounting/utils/ie_account.py diff --git a/src/accounting/report/converters.py b/src/accounting/report/converters.py index 64ccf00..753a45c 100644 --- a/src/accounting/report/converters.py +++ b/src/accounting/report/converters.py @@ -23,8 +23,8 @@ from flask import abort from werkzeug.routing import BaseConverter from accounting.models import Account +from accounting.utils.ie_account import IncomeExpensesAccount from .period import Period, get_period -from .utils.ie_account import IncomeExpensesAccount class PeriodConverter(BaseConverter): diff --git a/src/accounting/report/reports/income_expenses.py b/src/accounting/report/reports/income_expenses.py index b2ead32..acdcaad 100644 --- a/src/accounting/report/reports/income_expenses.py +++ b/src/accounting/report/reports/income_expenses.py @@ -33,12 +33,12 @@ from accounting.report.utils.base_page_params import BasePageParams from accounting.report.utils.base_report import BaseReport from accounting.report.utils.csv_export import BaseCSVRow, csv_download, \ period_spec -from accounting.report.utils.ie_account import IncomeExpensesAccount from accounting.report.utils.option_link import OptionLink 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.pagination import Pagination diff --git a/src/accounting/report/utils/ie_account.py b/src/accounting/report/utils/ie_account.py index cb37dc8..ec2062a 100644 --- a/src/accounting/report/utils/ie_account.py +++ b/src/accounting/report/utils/ie_account.py @@ -17,53 +17,10 @@ """The pseudo account for the income and expenses log. """ -import typing as t - from flask import current_app -from accounting.locale import gettext from accounting.models import Account - - -class IncomeExpensesAccount: - """The pseudo account for the income and expenses log.""" - 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. - - :param account: The actual account. - """ - self.account: Account | None = account - self.id: int = -1 if account is None else account.id - """The ID.""" - self.code: str = "" if account is None else account.code - """The code.""" - self.title: str = "" if account is None else account.title - """The title.""" - self.str: str = "" if account is None else str(account) - """The string representation of the account.""" - - def __str__(self) -> str: - """Returns the string representation of the account. - - :return: The string representation of the account. - """ - return self.str - - @classmethod - def current_assets_and_liabilities(cls) -> t.Self: - """Returns the pseudo account for current assets and liabilities. - - :return: The pseudo account for current assets and liabilities. - """ - account: cls = cls() - account.id = 0 - account.code = cls.CURRENT_AL_CODE - account.title = gettext("current assets and liabilities") - account.str = account.title - return account +from accounting.utils.ie_account import IncomeExpensesAccount def default_ie_account_code() -> str: diff --git a/src/accounting/report/utils/report_chooser.py b/src/accounting/report/utils/report_chooser.py index cfdc6b3..bef3044 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 .ie_account import IncomeExpensesAccount +from accounting.utils.ie_account import IncomeExpensesAccount from .option_link import OptionLink from .report_type import ReportType from .urls import journal_url, ledger_url, income_expenses_url, \ diff --git a/src/accounting/report/utils/urls.py b/src/accounting/report/utils/urls.py index 4b7987b..212a88a 100644 --- a/src/accounting/report/utils/urls.py +++ b/src/accounting/report/utils/urls.py @@ -21,8 +21,9 @@ from flask import url_for from accounting.models import Currency, Account from accounting.report.period import Period +from accounting.report.utils.ie_account import default_ie_account_code from accounting.template_globals import default_currency_code -from .ie_account import IncomeExpensesAccount, default_ie_account_code +from accounting.utils.ie_account import IncomeExpensesAccount def journal_url(period: Period) \ diff --git a/src/accounting/report/views.py b/src/accounting/report/views.py index 2401b16..c28824a 100644 --- a/src/accounting/report/views.py +++ b/src/accounting/report/views.py @@ -23,11 +23,12 @@ from accounting import db 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.permission import has_permission, can_view from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \ IncomeStatement, BalanceSheet, Search from .template_filters import format_amount -from .utils.ie_account import IncomeExpensesAccount, default_ie_account +from .utils.ie_account import default_ie_account bp: Blueprint = Blueprint("report", __name__) """The view blueprint for the reports.""" diff --git a/src/accounting/utils/ie_account.py b/src/accounting/utils/ie_account.py new file mode 100644 index 0000000..575e777 --- /dev/null +++ b/src/accounting/utils/ie_account.py @@ -0,0 +1,64 @@ +# The Mia! Accounting Flask Project. +# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/22 + +# Copyright (c) 2023 imacat. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +""" +import typing as t + +from accounting.locale import gettext +from accounting.models import Account + + +class IncomeExpensesAccount: + """The pseudo account for the income and expenses log.""" + 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. + + :param account: The actual account. + """ + self.account: Account | None = account + self.id: int = -1 if account is None else account.id + """The ID.""" + self.code: str = "" if account is None else account.code + """The code.""" + self.title: str = "" if account is None else account.title + """The title.""" + self.str: str = "" if account is None else str(account) + """The string representation of the account.""" + + def __str__(self) -> str: + """Returns the string representation of the account. + + :return: The string representation of the account. + """ + return self.str + + @classmethod + def current_assets_and_liabilities(cls) -> t.Self: + """Returns the pseudo account for current assets and liabilities. + + :return: The pseudo account for current assets and liabilities. + """ + account: cls = cls() + account.id = 0 + account.code = cls.CURRENT_AL_CODE + account.title = gettext("current assets and liabilities") + account.str = account.title + return account