diff --git a/src/accounting/report/utils/income_expense_account.py b/src/accounting/report/utils/income_expense_account.py index dd7a75e..5d8cbef 100644 --- a/src/accounting/report/utils/income_expense_account.py +++ b/src/accounting/report/utils/income_expense_account.py @@ -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)) diff --git a/src/accounting/report/utils/urls.py b/src/accounting/report/utils/urls.py index 8ecbc58..d8ae3f3 100644 --- a/src/accounting/report/utils/urls.py +++ b/src/accounting/report/utils/urls.py @@ -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) diff --git a/src/accounting/report/views.py b/src/accounting/report/views.py index 2bac806..ee5f8a9 100644 --- a/src/accounting/report/views.py +++ b/src/accounting/report/views.py @@ -19,19 +19,35 @@ """ from flask import Blueprint, request, Response +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.permission import has_permission, can_view from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \ IncomeStatement, BalanceSheet, Search from .template_filters import format_amount -from .utils.income_expense_account import IncomeExpensesAccount +from .utils.income_expense_account import IncomeExpensesAccount, \ + default_io_account bp: Blueprint = Blueprint("report", __name__) """The view blueprint for the reports.""" bp.add_app_template_filter(format_amount, "accounting_report_format_amount") +@bp.get("", endpoint="default") +@has_permission(can_view) +def get_default_report() -> str | Response: + """Returns the income and expenses log in the default period. + + :return: The income and expenses log in the default period. + """ + return __get_income_expenses_list( + db.session.get(Currency, default_currency_code()), + default_io_account(), + get_period()) + + @bp.get("journal", endpoint="journal-default") @has_permission(can_view) def get_default_journal_list() -> str | Response: diff --git a/src/accounting/templates/accounting/include/nav.html b/src/accounting/templates/accounting/include/nav.html index 75de574..a590d8f 100644 --- a/src/accounting/templates/accounting/include/nav.html +++ b/src/accounting/templates/accounting/include/nav.html @@ -28,7 +28,7 @@ First written: 2023/1/26