Removed the list_transactions view that is not used now.
This commit is contained in:
@ -1,65 +0,0 @@
|
||||
# The Mia! Accounting Flask Project.
|
||||
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/18
|
||||
|
||||
# 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 queries for the transaction management.
|
||||
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import request
|
||||
|
||||
from accounting.models import Transaction
|
||||
from accounting.utils.query import parse_query_keywords
|
||||
|
||||
|
||||
def get_transaction_query() -> list[Transaction]:
|
||||
"""Returns the transactions, optionally filtered by the query.
|
||||
|
||||
:return: The transactions.
|
||||
"""
|
||||
keywords: list[str] = parse_query_keywords(request.args.get("q"))
|
||||
if len(keywords) == 0:
|
||||
return Transaction.query\
|
||||
.order_by(Transaction.date, Transaction.no).all()
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [Transaction.note.contains(k)]
|
||||
date: datetime
|
||||
try:
|
||||
date = datetime.strptime(k, "%Y")
|
||||
sub_conditions.append(
|
||||
sa.extract("year", Transaction.date) == date.year)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
date = datetime.strptime(k, "%Y/%m")
|
||||
sub_conditions.append(sa.and_(
|
||||
sa.extract("year", Transaction.date) == date.year,
|
||||
sa.extract("month", Transaction.date) == date.month))
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
date = datetime.strptime(f"2000/{k}", "%Y/%m/%d")
|
||||
sub_conditions.append(sa.and_(
|
||||
sa.extract("month", Transaction.date) == date.month,
|
||||
sa.extract("day", Transaction.date) == date.day))
|
||||
except ValueError:
|
||||
pass
|
||||
conditions.append(sa.or_(*sub_conditions))
|
||||
return Transaction.query.filter(*conditions)\
|
||||
.order_by(Transaction.date, Transaction.no).all()
|
@ -30,13 +30,11 @@ from accounting.locale import lazy_gettext
|
||||
from accounting.models import Transaction
|
||||
from accounting.utils.flash_errors import flash_form_errors
|
||||
from accounting.utils.next_uri import inherit_next, or_next
|
||||
from accounting.utils.pagination import Pagination
|
||||
from accounting.utils.permission import has_permission, can_view, can_edit
|
||||
from accounting.utils.txn_types import TransactionType
|
||||
from accounting.utils.user import get_current_user_pk
|
||||
from .forms import sort_transactions_in, TransactionReorderForm
|
||||
from .operators import TransactionOperator, TXN_TYPE_TO_OP, get_txn_op
|
||||
from .queries import get_transaction_query
|
||||
from .template_filters import with_type, to_transfer, format_amount_input, \
|
||||
text2html
|
||||
|
||||
@ -49,20 +47,6 @@ bp.add_app_template_filter(format_amount_input,
|
||||
bp.add_app_template_filter(text2html, "accounting_txn_text2html")
|
||||
|
||||
|
||||
@bp.get("", endpoint="list")
|
||||
@has_permission(can_view)
|
||||
def list_transactions() -> str:
|
||||
"""Lists the transactions.
|
||||
|
||||
:return: The transaction list.
|
||||
"""
|
||||
transactions: list[Transaction] = get_transaction_query()
|
||||
pagination: Pagination = Pagination[Transaction](transactions)
|
||||
return render_template("accounting/transaction/list.html",
|
||||
list=pagination.list, pagination=pagination,
|
||||
txn_types=TransactionType)
|
||||
|
||||
|
||||
@bp.get("/create/<transactionType:txn_type>", endpoint="create")
|
||||
@has_permission(can_edit)
|
||||
def show_add_transaction_form(txn_type: TransactionType) -> str:
|
||||
|
Reference in New Issue
Block a user