Added the base account detail page that shows its descendant accounts.

This commit is contained in:
2023-02-01 16:54:45 +08:00
parent cb0dea58f1
commit 9b22331a5a
6 changed files with 121 additions and 8 deletions

View File

@ -27,6 +27,9 @@ def init_app(app: Flask, bp: Blueprint) -> None:
:param app: The Flask application.
:return: None.
"""
from .converters import BaseAccountConverter
app.url_map.converters["baseAccount"] = BaseAccountConverter
from .views import bp as base_account_bp
bp.register_blueprint(base_account_bp, url_prefix="/base-accounts")

View File

@ -0,0 +1,48 @@
# The Mia! Accounting Flask Project.
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1
# 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.
"""The path converters for the base account management.
"""
from flask import abort
from werkzeug.routing import BaseConverter
from accounting.database import db
from accounting.models import BaseAccount
class BaseAccountConverter(BaseConverter):
"""The account converter to convert the account code and to the
corresponding base account in the routes."""
def to_python(self, value: str) -> BaseAccount:
"""Converts an account code to a base account.
:param value: The account code.
:return: The corresponding base account.
"""
account: BaseAccount | None = db.session.get(BaseAccount, value)
if account is None:
abort(404)
return account
def to_url(self, value: BaseAccount) -> str:
"""Converts a base account to its code.
:param value: The base account.
:return: The code.
"""
return value.code

View File

@ -39,3 +39,14 @@ def list_accounts() -> str:
pagination: Pagination = Pagination[BaseAccount](accounts)
return render_template("accounting/base-account/list.html",
list=pagination.list, pagination=pagination)
@bp.get("/<baseAccount:account>", endpoint="detail")
@has_permission(can_view)
def show_account_detail(account: BaseAccount) -> str:
"""Shows the account detail.
:return: The account detail.
"""
return render_template("accounting/base-account/detail.html", obj=account)