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() %}
  • - + {{ A_("Settings") }} diff --git a/src/accounting/templates/accounting/option/detail.html b/src/accounting/templates/accounting/option/detail.html new file mode 100644 index 0000000..89b7634 --- /dev/null +++ b/src/accounting/templates/accounting/option/detail.html @@ -0,0 +1,63 @@ +{# +The Mia! Accounting Flask Project +detail.html: The option detail + + Copyright (c) 2023 imacat. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Author: imacat@mail.imacat.idv.tw (imacat) +First written: 2023/3/22 +#} +{% extends "accounting/base.html" %} + +{% block header %}{% block title %}{{ A_("Settings") }}{% endblock %}{% endblock %} + +{% block content %} + +
    + + + {{ A_("Edit") }} + +
    + +
    + + + +
    + +
    + +
    {{ obj.default_currency_text }}
    +
    + +
    + +
    {{ obj.default_ie_account_code_text }}
    +
    + +{% with expense_income = "expense", + label = A_("Expense"), + recurring_items = obj.recurring.expenses %} + {% include "accounting/option/include/detail-recurring-expense-income.html" %} +{% endwith %} + +{% with expense_income = "income", + label = A_("Income"), + recurring_items = obj.recurring.incomes %} + {% include "accounting/option/include/detail-recurring-expense-income.html" %} +{% endwith %} + +{% endblock %} diff --git a/src/accounting/templates/accounting/option/form.html b/src/accounting/templates/accounting/option/form.html index 1d9faa4..7ae26a9 100644 --- a/src/accounting/templates/accounting/option/form.html +++ b/src/accounting/templates/accounting/option/form.html @@ -29,7 +29,14 @@ First written: 2023/3/22 {% block content %} -
    + + + {{ form.csrf_token }} {% if request.args.next %} diff --git a/src/accounting/templates/accounting/option/include/detail-recurring-expense-income.html b/src/accounting/templates/accounting/option/include/detail-recurring-expense-income.html new file mode 100644 index 0000000..b1aac4b --- /dev/null +++ b/src/accounting/templates/accounting/option/include/detail-recurring-expense-income.html @@ -0,0 +1,29 @@ +{# +The Mia! Accounting Flask Project +detail-recurring-expense-income.html: The recurring expense or income in the option detail + + Copyright (c) 2023 imacat. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Author: imacat@mail.imacat.idv.tw (imacat) +First written: 2023/3/22 +#} +
    + +
      + {% for item in recurring_items %} + {% include "accounting/option/include/detail-recurring-item.html" %} + {% endfor %} +
    +
    diff --git a/src/accounting/templates/accounting/option/include/detail-recurring-item.html b/src/accounting/templates/accounting/option/include/detail-recurring-item.html new file mode 100644 index 0000000..580ed12 --- /dev/null +++ b/src/accounting/templates/accounting/option/include/detail-recurring-item.html @@ -0,0 +1,28 @@ +{# +The Mia! Accounting Flask Project +detail-recurring-item.html: The recurring item in the option detail + + Copyright (c) 2023 imacat. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Author: imacat@mail.imacat.idv.tw (imacat) +First written: 2023/3/22 +#} +{# For SonarQube not to complain about incorrect HTML #}