Renamed IncomeExpensesAccount to CurrentAccount.

This commit is contained in:
2023-03-22 15:42:44 +08:00
parent 761d5a5824
commit 567004f7d9
9 changed files with 45 additions and 46 deletions

View File

@ -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.

View File

@ -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."""

View File

@ -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")

View File

@ -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.

View File

@ -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/<currency:currency>/<ieAccount:account>",
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/<currency:currency>/<ieAccount:account>/<period:period>",
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.