Added the get_balance_sheet_url utility to replace the common codes to retrieve the URL of an income statement.
This commit is contained in:
parent
a65dccac92
commit
140d3c6010
@ -20,7 +20,7 @@
|
||||
from decimal import Decimal
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import url_for, render_template, Response
|
||||
from flask import render_template, Response
|
||||
|
||||
from accounting import db
|
||||
from accounting.locale import gettext
|
||||
@ -30,7 +30,8 @@ from accounting.report.period import Period
|
||||
from .utils.base_page_params import BasePageParams
|
||||
from .utils.base_report import BaseReport
|
||||
from .utils.csv_export import BaseCSVRow, csv_download, period_spec
|
||||
from .utils.get_url import get_ledger_url, get_income_statement_url
|
||||
from .utils.get_url import get_ledger_url, get_balance_sheet_url, \
|
||||
get_income_statement_url
|
||||
from .utils.option_link import OptionLink
|
||||
from .utils.period_choosers import BalanceSheetPeriodChooser
|
||||
from .utils.report_chooser import ReportChooser
|
||||
@ -346,14 +347,8 @@ class PageParams(BasePageParams):
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
def get_url(currency: Currency):
|
||||
if self.period.is_default:
|
||||
return url_for("accounting.report.balance-sheet-default",
|
||||
currency=currency)
|
||||
return url_for("accounting.report.balance-sheet",
|
||||
currency=currency, period=self.period)
|
||||
|
||||
return self._get_currency_options(get_url, self.currency)
|
||||
return self._get_currency_options(
|
||||
lambda x: get_balance_sheet_url(x, self.period), self.currency)
|
||||
|
||||
|
||||
class BalanceSheet(BaseReport):
|
||||
|
@ -96,3 +96,17 @@ def get_income_statement_url(currency: Currency, period: Period) -> str:
|
||||
currency=currency)
|
||||
return url_for("accounting.report.income-statement",
|
||||
currency=currency, period=period)
|
||||
|
||||
|
||||
def get_balance_sheet_url(currency: Currency, period: Period) -> str:
|
||||
"""Returns the URL of a balance sheet.
|
||||
|
||||
:param currency: The currency.
|
||||
:param period: The period.
|
||||
:return: The URL of the balance sheet.
|
||||
"""
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.balance-sheet-default",
|
||||
currency=currency)
|
||||
return url_for("accounting.report.balance-sheet",
|
||||
currency=currency, period=period)
|
||||
|
@ -23,15 +23,14 @@ This file is largely taken from the NanoParma ERP project, first written in
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import date
|
||||
|
||||
from flask import url_for
|
||||
|
||||
from accounting.models import Currency, Account, Transaction
|
||||
from accounting.report.income_expense_account import IncomeExpensesAccount
|
||||
from accounting.report.period import YearPeriod, Period, ThisMonth, \
|
||||
LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \
|
||||
TemplatePeriod
|
||||
from .get_url import get_journal_url, get_ledger_url, \
|
||||
get_income_expenses_url, get_trial_balance_url, get_income_statement_url
|
||||
get_income_expenses_url, get_trial_balance_url, get_income_statement_url, \
|
||||
get_balance_sheet_url
|
||||
|
||||
|
||||
class PeriodChooser(ABC):
|
||||
@ -193,8 +192,4 @@ class BalanceSheetPeriodChooser(PeriodChooser):
|
||||
super().__init__(None if first is None else first.date)
|
||||
|
||||
def _url_for(self, period: Period) -> str:
|
||||
if period.is_default:
|
||||
return url_for("accounting.report.balance-sheet-default",
|
||||
currency=self.currency)
|
||||
return url_for("accounting.report.balance-sheet",
|
||||
currency=self.currency, period=period)
|
||||
return get_balance_sheet_url(self.currency, period)
|
||||
|
@ -23,7 +23,6 @@ This file is largely taken from the NanoParma ERP project, first written in
|
||||
import re
|
||||
import typing as t
|
||||
|
||||
from flask import url_for
|
||||
from flask_babel import LazyString
|
||||
|
||||
from accounting import db
|
||||
@ -33,7 +32,8 @@ from accounting.report.income_expense_account import IncomeExpensesAccount
|
||||
from accounting.report.period import Period
|
||||
from accounting.template_globals import default_currency_code
|
||||
from .get_url import get_journal_url, get_ledger_url, \
|
||||
get_income_expenses_url, get_trial_balance_url, get_income_statement_url
|
||||
get_income_expenses_url, get_trial_balance_url, get_income_statement_url, \
|
||||
get_balance_sheet_url
|
||||
from .option_link import OptionLink
|
||||
from .report_type import ReportType
|
||||
|
||||
@ -151,12 +151,9 @@ class ReportChooser:
|
||||
|
||||
:return: The balance sheet.
|
||||
"""
|
||||
url: str = url_for("accounting.report.balance-sheet-default",
|
||||
currency=self.__currency) \
|
||||
if self.__period.is_default \
|
||||
else url_for("accounting.report.balance-sheet",
|
||||
currency=self.__currency, period=self.__period)
|
||||
return OptionLink(gettext("Balance Sheet"), url,
|
||||
return OptionLink(gettext("Balance Sheet"),
|
||||
get_balance_sheet_url(self.__currency,
|
||||
self.__period),
|
||||
self.__active_report == ReportType.BALANCE_SHEET,
|
||||
fa_icon="fa-solid fa-scale-balanced")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user