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

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

View File

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

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.

View File

@ -46,7 +46,7 @@ First written: 2023/3/22
<div class="form-floating mb-3">
<select id="accounting-default-ie-account" class="form-select {% if form.default_ie_account_code.errors %} is-invalid {% endif %}" name="default_ie_account_code">
{% for account in form.ie_accounts %}
{% for account in form.current_accounts %}
<option value="{{ account.code }}" {% if account.code == form.default_ie_account_code.data %} selected="selected" {% endif %}>{{ account }}</option>
{% endfor %}
</select>

View File

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