Added the __get_detail_uri function to the "accounting.currency.views" module, for simplicity.
This commit is contained in:
parent
515d39e61c
commit
cb622f4bad
@ -89,8 +89,7 @@ def add_currency() -> redirect:
|
|||||||
db.session.add(currency)
|
db.session.add(currency)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(lazy_gettext("The currency is added successfully"), "success")
|
flash(lazy_gettext("The currency is added successfully"), "success")
|
||||||
return redirect(inherit_next(url_for("accounting.currency.detail",
|
return redirect(inherit_next(__get_detail_uri(currency)))
|
||||||
currency=currency)))
|
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/<currency:currency>", endpoint="detail")
|
@bp.get("/<currency:currency>", endpoint="detail")
|
||||||
@ -143,14 +142,12 @@ def update_currency(currency: Currency) -> redirect:
|
|||||||
form.populate_obj(currency)
|
form.populate_obj(currency)
|
||||||
if not currency.is_modified:
|
if not currency.is_modified:
|
||||||
flash(lazy_gettext("The currency was not modified."), "success")
|
flash(lazy_gettext("The currency was not modified."), "success")
|
||||||
return redirect(inherit_next(url_for("accounting.currency.detail",
|
return redirect(inherit_next(__get_detail_uri(currency)))
|
||||||
currency=currency)))
|
|
||||||
currency.updated_by_id = get_current_user_pk()
|
currency.updated_by_id = get_current_user_pk()
|
||||||
currency.updated_at = sa.func.now()
|
currency.updated_at = sa.func.now()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(lazy_gettext("The currency is updated successfully."), "success")
|
flash(lazy_gettext("The currency is updated successfully."), "success")
|
||||||
return redirect(inherit_next(url_for("accounting.currency.detail",
|
return redirect(inherit_next(__get_detail_uri(currency)))
|
||||||
currency=currency)))
|
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/<currency:currency>/delete", endpoint="delete")
|
@bp.post("/<currency:currency>/delete", endpoint="delete")
|
||||||
@ -176,3 +173,13 @@ def exists_code() -> dict[str, bool]:
|
|||||||
:return: Whether the currency code exists.
|
:return: Whether the currency code exists.
|
||||||
"""
|
"""
|
||||||
return {"exists": db.session.get(Currency, request.args["q"]) is not None}
|
return {"exists": db.session.get(Currency, request.args["q"]) is not None}
|
||||||
|
|
||||||
|
|
||||||
|
def __get_detail_uri(currency: Currency) -> str:
|
||||||
|
"""Returns the detail URI of a currency.
|
||||||
|
|
||||||
|
:param currency: The currency.
|
||||||
|
:return: The detail URI of the currency.
|
||||||
|
"""
|
||||||
|
return url_for("accounting.currency.detail", currency=currency)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user