Added the UnappliedAccountConverter path converter to only allow the accounts that need offsets.
This commit is contained in:
parent
c984d2d596
commit
e9824808ec
@ -27,9 +27,11 @@ def init_app(app: Flask, url_prefix: str) -> None:
|
||||
:param url_prefix: The URL prefix of the accounting application.
|
||||
:return: None.
|
||||
"""
|
||||
from .converters import PeriodConverter, CurrentAccountConverter
|
||||
from .converters import PeriodConverter, CurrentAccountConverter, \
|
||||
UnappliedAccountConverter
|
||||
app.url_map.converters["period"] = PeriodConverter
|
||||
app.url_map.converters["currentAccount"] = CurrentAccountConverter
|
||||
app.url_map.converters["unappliedAccount"] = UnappliedAccountConverter
|
||||
|
||||
from .views import bp as report_bp
|
||||
app.register_blueprint(report_bp, url_prefix=url_prefix)
|
||||
|
@ -77,3 +77,29 @@ class CurrentAccountConverter(BaseConverter):
|
||||
:return: Its code.
|
||||
"""
|
||||
return value.code
|
||||
|
||||
|
||||
class UnappliedAccountConverter(BaseConverter):
|
||||
"""The converter to convert the unapplied original line item account code
|
||||
from and to the corresponding account in the routes."""
|
||||
|
||||
def to_python(self, value: str) -> Account:
|
||||
"""Converts an account code to an account.
|
||||
|
||||
:param value: The account code.
|
||||
:return: The corresponding account.
|
||||
"""
|
||||
account: Account | None = Account.find_by_code(value)
|
||||
if account is None:
|
||||
abort(404)
|
||||
if not account.is_need_offset:
|
||||
abort(404)
|
||||
return account
|
||||
|
||||
def to_url(self, value: Account) -> str:
|
||||
"""Converts an account to account code.
|
||||
|
||||
:param value: The account.
|
||||
:return: Its code.
|
||||
"""
|
||||
return value.code
|
||||
|
@ -286,7 +286,7 @@ def __get_balance_sheet(currency: Currency, period: Period) \
|
||||
return report.html()
|
||||
|
||||
|
||||
@bp.get("unapplied/<account:account>", endpoint="unapplied")
|
||||
@bp.get("unapplied/<unappliedAccount:account>", endpoint="unapplied")
|
||||
@has_permission(can_view)
|
||||
def get_unapplied(account: Account) -> str | Response:
|
||||
"""Returns the unapplied original line items.
|
||||
|
Loading…
Reference in New Issue
Block a user