Renamed IncomeExpensesAccount to CurrentAccount.
This commit is contained in:
parent
761d5a5824
commit
567004f7d9
@ -28,7 +28,7 @@ from wtforms.validators import DataRequired, ValidationError
|
|||||||
from accounting.forms import CURRENCY_REQUIRED, CurrencyExists
|
from accounting.forms import CURRENCY_REQUIRED, CurrencyExists
|
||||||
from accounting.locale import lazy_gettext
|
from accounting.locale import lazy_gettext
|
||||||
from accounting.models import Account
|
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 accounting.utils.strip_text import strip_text
|
||||||
from .options import Options
|
from .options import Options
|
||||||
|
|
||||||
@ -242,9 +242,9 @@ class OptionForm(FlaskForm):
|
|||||||
obj.recurring_data = self.recurring.form.as_data
|
obj.recurring_data = self.recurring.form.as_data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ie_accounts(self) -> list[IncomeExpensesAccount]:
|
def current_accounts(self) -> list[CurrentAccount]:
|
||||||
"""Returns the accounts for the income and expenses log.
|
"""Returns the current accounts.
|
||||||
|
|
||||||
:return: The accounts for the income and expenses log.
|
:return: The current accounts.
|
||||||
"""
|
"""
|
||||||
return ie_accounts()
|
return current_accounts()
|
||||||
|
@ -23,7 +23,7 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
from accounting import db
|
from accounting import db
|
||||||
from accounting.models import Option, Account
|
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
|
from accounting.utils.user import get_current_user_pk
|
||||||
|
|
||||||
|
|
||||||
@ -108,15 +108,15 @@ class Options:
|
|||||||
self.__set_option("default_ie_account", value)
|
self.__set_option("default_ie_account", value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_ie_account(self) -> IncomeExpensesAccount:
|
def default_ie_account(self) -> CurrentAccount:
|
||||||
"""Returns the default account code for the income and expenses log.
|
"""Returns the default account code for the income and expenses log.
|
||||||
|
|
||||||
:return: 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 \
|
if self.default_ie_account_code \
|
||||||
== IncomeExpensesAccount.CURRENT_AL_CODE:
|
== CurrentAccount.CURRENT_AL_CODE:
|
||||||
return IncomeExpensesAccount.current_assets_and_liabilities()
|
return CurrentAccount.current_assets_and_liabilities()
|
||||||
return IncomeExpensesAccount(
|
return CurrentAccount(
|
||||||
Account.find_by_code(self.default_ie_account_code))
|
Account.find_by_code(self.default_ie_account_code))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -23,7 +23,7 @@ from flask import abort
|
|||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
|
|
||||||
from accounting.models import Account
|
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
|
from .period import Period, get_period
|
||||||
|
|
||||||
|
|
||||||
@ -55,22 +55,22 @@ class IncomeExpensesAccountConverter(BaseConverter):
|
|||||||
"""The supplier converter to convert the income and expenses log pseudo
|
"""The supplier converter to convert the income and expenses log pseudo
|
||||||
account code from and to the corresponding pseudo account in the routes."""
|
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.
|
"""Converts an account code to an account.
|
||||||
|
|
||||||
:param value: The account code.
|
:param value: The account code.
|
||||||
:return: The corresponding account.
|
:return: The corresponding account.
|
||||||
"""
|
"""
|
||||||
if value == IncomeExpensesAccount.CURRENT_AL_CODE:
|
if value == CurrentAccount.CURRENT_AL_CODE:
|
||||||
return IncomeExpensesAccount.current_assets_and_liabilities()
|
return CurrentAccount.current_assets_and_liabilities()
|
||||||
if not re.match("^[12][12]", value):
|
if not re.match("^[12][12]", value):
|
||||||
abort(404)
|
abort(404)
|
||||||
account: Account | None = Account.find_by_code(value)
|
account: Account | None = Account.find_by_code(value)
|
||||||
if account is None:
|
if account is None:
|
||||||
abort(404)
|
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.
|
"""Converts an account to account code.
|
||||||
|
|
||||||
:param value: The account.
|
:param value: The account.
|
||||||
|
@ -38,7 +38,7 @@ from accounting.report.utils.report_chooser import ReportChooser
|
|||||||
from accounting.report.utils.report_type import ReportType
|
from accounting.report.utils.report_type import ReportType
|
||||||
from accounting.report.utils.urls import income_expenses_url
|
from accounting.report.utils.urls import income_expenses_url
|
||||||
from accounting.utils.cast import be
|
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
|
from accounting.utils.pagination import Pagination
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class ReportLineItem:
|
|||||||
class LineItemCollector:
|
class LineItemCollector:
|
||||||
"""The line item collector."""
|
"""The line item collector."""
|
||||||
|
|
||||||
def __init__(self, currency: Currency, account: IncomeExpensesAccount,
|
def __init__(self, currency: Currency, account: CurrentAccount,
|
||||||
period: Period):
|
period: Period):
|
||||||
"""Constructs the line item collector.
|
"""Constructs the line item collector.
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class LineItemCollector:
|
|||||||
"""
|
"""
|
||||||
self.__currency: Currency = currency
|
self.__currency: Currency = currency
|
||||||
"""The currency."""
|
"""The currency."""
|
||||||
self.__account: IncomeExpensesAccount = account
|
self.__account: CurrentAccount = account
|
||||||
"""The account."""
|
"""The account."""
|
||||||
self.__period: Period = period
|
self.__period: Period = period
|
||||||
"""The period"""
|
"""The period"""
|
||||||
@ -173,7 +173,7 @@ class LineItemCollector:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def __account_condition(self) -> sa.BinaryExpression:
|
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"),
|
return sa.or_(Account.base_code.startswith("11"),
|
||||||
Account.base_code.startswith("12"),
|
Account.base_code.startswith("12"),
|
||||||
Account.base_code.startswith("21"),
|
Account.base_code.startswith("21"),
|
||||||
@ -264,7 +264,7 @@ class PageParams(BasePageParams):
|
|||||||
"""The HTML page parameters."""
|
"""The HTML page parameters."""
|
||||||
|
|
||||||
def __init__(self, currency: Currency,
|
def __init__(self, currency: Currency,
|
||||||
account: IncomeExpensesAccount,
|
account: CurrentAccount,
|
||||||
period: Period,
|
period: Period,
|
||||||
has_data: bool,
|
has_data: bool,
|
||||||
pagination: Pagination[ReportLineItem],
|
pagination: Pagination[ReportLineItem],
|
||||||
@ -283,7 +283,7 @@ class PageParams(BasePageParams):
|
|||||||
"""
|
"""
|
||||||
self.currency: Currency = currency
|
self.currency: Currency = currency
|
||||||
"""The currency."""
|
"""The currency."""
|
||||||
self.account: IncomeExpensesAccount = account
|
self.account: CurrentAccount = account
|
||||||
"""The account."""
|
"""The account."""
|
||||||
self.period: Period = period
|
self.period: Period = period
|
||||||
"""The period."""
|
"""The period."""
|
||||||
@ -341,8 +341,8 @@ class PageParams(BasePageParams):
|
|||||||
|
|
||||||
:return: The account options.
|
:return: The account options.
|
||||||
"""
|
"""
|
||||||
current_al: IncomeExpensesAccount \
|
current_al: CurrentAccount \
|
||||||
= IncomeExpensesAccount.current_assets_and_liabilities()
|
= CurrentAccount.current_assets_and_liabilities()
|
||||||
options: list[OptionLink] \
|
options: list[OptionLink] \
|
||||||
= [OptionLink(str(current_al),
|
= [OptionLink(str(current_al),
|
||||||
income_expenses_url(self.currency, current_al,
|
income_expenses_url(self.currency, current_al,
|
||||||
@ -360,7 +360,7 @@ class PageParams(BasePageParams):
|
|||||||
options.extend([OptionLink(str(x),
|
options.extend([OptionLink(str(x),
|
||||||
income_expenses_url(
|
income_expenses_url(
|
||||||
self.currency,
|
self.currency,
|
||||||
IncomeExpensesAccount(x),
|
CurrentAccount(x),
|
||||||
self.period),
|
self.period),
|
||||||
x.id == self.account.id)
|
x.id == self.account.id)
|
||||||
for x in Account.query.filter(Account.id.in_(in_use))
|
for x in Account.query.filter(Account.id.in_(in_use))
|
||||||
@ -371,7 +371,7 @@ class PageParams(BasePageParams):
|
|||||||
class IncomeExpenses(BaseReport):
|
class IncomeExpenses(BaseReport):
|
||||||
"""The income and expenses log."""
|
"""The income and expenses log."""
|
||||||
|
|
||||||
def __init__(self, currency: Currency, account: IncomeExpensesAccount,
|
def __init__(self, currency: Currency, account: CurrentAccount,
|
||||||
period: Period):
|
period: Period):
|
||||||
"""Constructs an income and expenses log.
|
"""Constructs an income and expenses log.
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ class IncomeExpenses(BaseReport):
|
|||||||
"""
|
"""
|
||||||
self.__currency: Currency = currency
|
self.__currency: Currency = currency
|
||||||
"""The currency."""
|
"""The currency."""
|
||||||
self.__account: IncomeExpensesAccount = account
|
self.__account: CurrentAccount = account
|
||||||
"""The account."""
|
"""The account."""
|
||||||
self.__period: Period = period
|
self.__period: Period = period
|
||||||
"""The period."""
|
"""The period."""
|
||||||
|
@ -30,7 +30,7 @@ from accounting.locale import gettext
|
|||||||
from accounting.models import Currency, Account
|
from accounting.models import Currency, Account
|
||||||
from accounting.report.period import Period, get_period
|
from accounting.report.period import Period, get_period
|
||||||
from accounting.template_globals import default_currency_code
|
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 .option_link import OptionLink
|
||||||
from .report_type import ReportType
|
from .report_type import ReportType
|
||||||
from .urls import journal_url, ledger_url, income_expenses_url, \
|
from .urls import journal_url, ledger_url, income_expenses_url, \
|
||||||
@ -113,7 +113,7 @@ class ReportChooser:
|
|||||||
account: Account = Account.cash()
|
account: Account = Account.cash()
|
||||||
return OptionLink(gettext("Income and Expenses Log"),
|
return OptionLink(gettext("Income and Expenses Log"),
|
||||||
income_expenses_url(self.__currency,
|
income_expenses_url(self.__currency,
|
||||||
IncomeExpensesAccount(account),
|
CurrentAccount(account),
|
||||||
self.__period),
|
self.__period),
|
||||||
self.__active_report == ReportType.INCOME_EXPENSES,
|
self.__active_report == ReportType.INCOME_EXPENSES,
|
||||||
fa_icon="fa-solid fa-money-bill-wave")
|
fa_icon="fa-solid fa-money-bill-wave")
|
||||||
|
@ -23,7 +23,7 @@ from accounting.models import Currency, Account
|
|||||||
from accounting.option.options import options
|
from accounting.option.options import options
|
||||||
from accounting.report.period import Period
|
from accounting.report.period import Period
|
||||||
from accounting.template_globals import default_currency_code
|
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) \
|
def journal_url(period: Period) \
|
||||||
@ -55,7 +55,7 @@ def ledger_url(currency: Currency, account: Account, period: Period) \
|
|||||||
period=period)
|
period=period)
|
||||||
|
|
||||||
|
|
||||||
def income_expenses_url(currency: Currency, account: IncomeExpensesAccount,
|
def income_expenses_url(currency: Currency, account: CurrentAccount,
|
||||||
period: Period) -> str:
|
period: Period) -> str:
|
||||||
"""Returns the URL of an income and expenses log.
|
"""Returns the URL of an income and expenses log.
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from accounting.models import Currency, Account
|
|||||||
from accounting.option.options import options
|
from accounting.option.options import options
|
||||||
from accounting.report.period import Period, get_period
|
from accounting.report.period import Period, get_period
|
||||||
from accounting.template_globals import default_currency_code
|
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 accounting.utils.permission import has_permission, can_view
|
||||||
from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \
|
from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \
|
||||||
IncomeStatement, BalanceSheet, Search
|
IncomeStatement, BalanceSheet, Search
|
||||||
@ -127,8 +127,7 @@ def __get_ledger(currency: Currency, account: Account, period: Period) \
|
|||||||
@bp.get("income-expenses/<currency:currency>/<ieAccount:account>",
|
@bp.get("income-expenses/<currency:currency>/<ieAccount:account>",
|
||||||
endpoint="income-expenses-default")
|
endpoint="income-expenses-default")
|
||||||
@has_permission(can_view)
|
@has_permission(can_view)
|
||||||
def get_default_income_expenses(currency: Currency,
|
def get_default_income_expenses(currency: Currency, account: CurrentAccount) \
|
||||||
account: IncomeExpensesAccount) \
|
|
||||||
-> str | Response:
|
-> str | Response:
|
||||||
"""Returns the income and expenses log in the default period.
|
"""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>",
|
"income-expenses/<currency:currency>/<ieAccount:account>/<period:period>",
|
||||||
endpoint="income-expenses")
|
endpoint="income-expenses")
|
||||||
@has_permission(can_view)
|
@has_permission(can_view)
|
||||||
def get_income_expenses(currency: Currency, account: IncomeExpensesAccount,
|
def get_income_expenses(currency: Currency, account: CurrentAccount,
|
||||||
period: Period) -> str | Response:
|
period: Period) -> str | Response:
|
||||||
"""Returns the income and expenses log.
|
"""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)
|
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:
|
period: Period) -> str | Response:
|
||||||
"""Returns the income and expenses log.
|
"""Returns the income and expenses log.
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ First written: 2023/3/22
|
|||||||
|
|
||||||
<div class="form-floating mb-3">
|
<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">
|
<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>
|
<option value="{{ account.code }}" {% if account.code == form.default_ie_account_code.data %} selected="selected" {% endif %}>{{ account }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""The pseudo account for the income and expenses log.
|
"""The current account.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import typing as t
|
import typing as t
|
||||||
@ -25,15 +25,15 @@ from accounting.models import Account
|
|||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
class IncomeExpensesAccount:
|
class CurrentAccount:
|
||||||
"""The pseudo account for the income and expenses log."""
|
"""The current account."""
|
||||||
CURRENT_AL_CODE: str = "0000-000"
|
CURRENT_AL_CODE: str = "0000-000"
|
||||||
"""The account code for the current assets and liabilities."""
|
"""The account code for the current assets and liabilities."""
|
||||||
|
|
||||||
def __init__(self, account: Account | None = None):
|
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.account: Account | None = account
|
||||||
self.id: int = -1 if account is None else account.id
|
self.id: int = -1 if account is None else account.id
|
||||||
@ -66,14 +66,14 @@ class IncomeExpensesAccount:
|
|||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
def ie_accounts() -> list[IncomeExpensesAccount]:
|
def current_accounts() -> list[CurrentAccount]:
|
||||||
"""Returns accounts for the income and expenses log.
|
"""Returns accounts for the income and expenses log.
|
||||||
|
|
||||||
:return: The accounts for the income and expenses log.
|
:return: The accounts for the income and expenses log.
|
||||||
"""
|
"""
|
||||||
accounts: list[IncomeExpensesAccount] \
|
accounts: list[CurrentAccount] \
|
||||||
= [IncomeExpensesAccount.current_assets_and_liabilities()]
|
= [CurrentAccount.current_assets_and_liabilities()]
|
||||||
accounts.extend([IncomeExpensesAccount(x)
|
accounts.extend([CurrentAccount(x)
|
||||||
for x in db.session.query(Account)
|
for x in db.session.query(Account)
|
||||||
.filter(sa.or_(Account.base_code.startswith("11"),
|
.filter(sa.or_(Account.base_code.startswith("11"),
|
||||||
Account.base_code.startswith("12"),
|
Account.base_code.startswith("12"),
|
Loading…
Reference in New Issue
Block a user