diff --git a/src/accounting/option/options.py b/src/accounting/option/options.py index 9d09324..ac7d75e 100644 --- a/src/accounting/option/options.py +++ b/src/accounting/option/options.py @@ -22,7 +22,7 @@ import json import sqlalchemy as sa from accounting import db -from accounting.models import Option, Account +from accounting.models import Option, Account, Currency from accounting.utils.current_account import CurrentAccount from accounting.utils.user import get_current_user_pk @@ -42,6 +42,14 @@ class RecurringItem: self.account_code: str = account_code self.description_template: str = description_template + @property + def account_text(self) -> str: + """Returns the account text. + + :return: The account text. + """ + return str(Account.find_by_code(self.account_code)) + class Recurring: """The recurring expenses or incomes.""" @@ -90,6 +98,14 @@ class Options: """ self.__set_option("default_currency", value) + @property + def default_currency_text(self) -> str: + """Returns the text of the default currency code. + + :return: The text of the default currency code. + """ + return str(db.session.get(Currency, self.default_currency)) + @property def default_ie_account_code(self) -> str: """Returns the default account code for the income and expenses log. @@ -107,6 +123,17 @@ class Options: """ self.__set_option("default_ie_account", value) + @property + def default_ie_account_code_text(self) -> str: + """Returns the text of the default currency code. + + :return: The text of the default currency code. + """ + code: str = self.default_ie_account_code + if code == CurrentAccount.CURRENT_AL_CODE: + return str(CurrentAccount.current_assets_and_liabilities()) + return str(CurrentAccount(db.session.get(Account, code))) + @property def default_ie_account(self) -> CurrentAccount: """Returns the default account code for the income and expenses log. diff --git a/src/accounting/option/views.py b/src/accounting/option/views.py index e931488..5913507 100644 --- a/src/accounting/option/views.py +++ b/src/accounting/option/views.py @@ -35,7 +35,17 @@ bp: Blueprint = Blueprint("option", __name__) """The view blueprint for the currency management.""" -@bp.get("", endpoint="form") +@bp.get("", endpoint="detail") +@has_permission(can_admin) +def show_options() -> str: + """Shows the options. + + :return: The options. + """ + return render_template("accounting/option/detail.html", obj=options) + + +@bp.get("edit", endpoint="edit") @has_permission(can_admin) def show_option_form() -> str: """Shows the option form. @@ -52,7 +62,7 @@ def show_option_form() -> str: return render_template("accounting/option/form.html", form=form) -@bp.post("", endpoint="update") +@bp.post("update", endpoint="update") @has_permission(can_admin) def update_options() -> redirect: """Updates the options. @@ -63,7 +73,7 @@ def update_options() -> redirect: form.populate_obj(options) if not options.is_modified: flash(s(lazy_gettext("The options were not modified.")), "success") - return redirect(inherit_next(url_for("accounting.option.form"))) + return redirect(inherit_next(url_for("accounting.option.detail"))) options.commit() flash(s(lazy_gettext("The options are saved successfully.")), "success") - return redirect(inherit_next(url_for("accounting.option.form"))) + return redirect(inherit_next(url_for("accounting.option.detail"))) diff --git a/src/accounting/templates/accounting/include/nav.html b/src/accounting/templates/accounting/include/nav.html index 1251ff1..ff47f1a 100644 --- a/src/accounting/templates/accounting/include/nav.html +++ b/src/accounting/templates/accounting/include/nav.html @@ -53,7 +53,7 @@ First written: 2023/1/26 {% if accounting_can_admin() %}