Added the default report view as the income and expenses log with the default currency, default account and default period. Changed the previous default journal links to the current default.

This commit is contained in:
2023-03-09 20:37:39 +08:00
parent ec257a4b57
commit 05ac5158f8
11 changed files with 56 additions and 12 deletions

View File

@ -19,6 +19,8 @@
"""
import typing as t
from flask import current_app
from accounting.locale import gettext
from accounting.models import Account
@ -62,3 +64,23 @@ class IncomeExpensesAccount:
account.title = gettext("current assets and liabilities")
account.str = account.title
return account
def default_io_account_code() -> str:
"""Returns the default account code for the income and expenses log.
:return: The default account code for the income and expenses log.
"""
with current_app.app_context():
return current_app.config.get("DEFAULT_IO_ACCOUNT", Account.CASH_CODE)
def default_io_account() -> IncomeExpensesAccount:
"""Returns the default account for the income and expenses log.
:return: The default account for the income and expenses log.
"""
code: str = default_io_account_code()
if code == IncomeExpensesAccount.CURRENT_AL_CODE:
return IncomeExpensesAccount.current_assets_and_liabilities()
return IncomeExpensesAccount(Account.find_by_code(code))

View File

@ -21,7 +21,9 @@ from flask import url_for
from accounting.models import Currency, Account
from accounting.report.period import Period
from .income_expense_account import IncomeExpensesAccount
from accounting.template_globals import default_currency_code
from .income_expense_account import IncomeExpensesAccount, \
default_io_account_code
def journal_url(period: Period) \
@ -62,6 +64,10 @@ def income_expenses_url(currency: Currency, account: IncomeExpensesAccount,
:param period: The period.
:return: The URL of the income and expenses log.
"""
if currency.code == default_currency_code() \
and account.code == default_io_account_code() \
and period.is_default:
return url_for("accounting.report.default")
if period.is_default:
return url_for("accounting.report.income-expenses-default",
currency=currency, account=account)