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)

View File

@ -42,6 +42,8 @@ class BaseAccount(db.Model):
l10n = db.relationship("BaseAccountL10n", back_populates="account",
lazy=False)
"""The localized titles."""
accounts = db.relationship("Account", back_populates="base")
"""The descendant accounts under the base account."""
def __str__(self) -> str:
"""Returns the string representation of the base account.
@ -91,7 +93,7 @@ class Account(db.Model):
ondelete="CASCADE"),
nullable=False)
"""The code of the base account."""
base = db.relationship(BaseAccount)
base = db.relationship(BaseAccount, back_populates="accounts")
"""The base account."""
no = db.Column(db.Integer, nullable=False, default=text("1"))
"""The account number under the base account."""

View File

@ -0,0 +1,49 @@
{#
The Mia! Accounting Flask Project
detail.html: The base account 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/2/1
#}
{% extends "accounting/base.html" %}
{% block header %}{% block title %}{{ obj }}{% endblock %}{% endblock %}
{% block content %}
<div class="btn-group mb-3">
<a class="btn btn-primary" href="{{ url_for("accounting.account.list")|or_next }}">
<i class="fa-solid fa-circle-chevron-left"></i>
{{ A_("Back") }}
</a>
</div>
<div class="account col-sm-6">
<div class="account-title">{{ obj.title }}</div>
<div class="account-code">{{ obj.code }}</div>
{% if obj.accounts %}
<div>
{% for account in obj.accounts %}
<a class="btn btn-primary" href="{{ url_for("accounting.account.detail", account=account)|append_next }}">
{{ account }}
</a>
{% endfor %}
</div>
{% endif %}
</div>
{% endblock %}

View File

@ -44,13 +44,13 @@ First written: 2023/1/26
{% if list %}
{% include "accounting/include/pagination.html" %}
<ul class="list-group">
{% for item in list %}
<li class="list-group-item list-group-item-action">
{{ item }}
</li>
{% endfor %}
</ul>
<div class="list-group">
{% for item in list %}
<a class="list-group-item list-group-item-action" href="{{ url_for("accounting.base-account.detail", account=item)|append_next }}">
{{ item }}
</a>
{% endfor %}
</div>
{% else %}
<p>{{ A_("There is no data.") }}</p>
{% endif %}