From 47c8121a04e43581061e00cfbd9abd5d9d5f3f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 17 Apr 2021 20:37:53 +0200 Subject: [PATCH] [balance] add sorting of transaction --- flaschengeist/plugins/balance/balance_controller.py | 9 +++++++-- flaschengeist/plugins/balance/routes.py | 12 +++++++++++- flaschengeist/plugins/pricelist/__init__.py | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/flaschengeist/plugins/balance/balance_controller.py b/flaschengeist/plugins/balance/balance_controller.py index 0ab282f..58b1152 100644 --- a/flaschengeist/plugins/balance/balance_controller.py +++ b/flaschengeist/plugins/balance/balance_controller.py @@ -113,7 +113,9 @@ def get_transaction(transaction_id) -> Transaction: return transaction -def get_transactions(user, start=None, end=None, limit=None, offset=None, show_reversal=False, show_cancelled=True): +def get_transactions( + user, start=None, end=None, limit=None, offset=None, show_reversal=False, show_cancelled=True, descending=False +): count = None query = Transaction.query.filter((Transaction.sender_ == user) | (Transaction.receiver_ == user)) if start: @@ -125,7 +127,10 @@ def get_transactions(user, start=None, end=None, limit=None, offset=None, show_r query = query.filter(Transaction.original_ == None) if not show_cancelled: query = query.filter(Transaction.reversal_id.is_(None)) - query = query.order_by(Transaction.time) + if descending: + query = query.order_by(Transaction.time.desc()) + else: + query = query.order_by(Transaction.time) if limit is not None: count = query.count() query = query.limit(limit) diff --git a/flaschengeist/plugins/balance/routes.py b/flaschengeist/plugins/balance/routes.py index d28f913..1341e6e 100644 --- a/flaschengeist/plugins/balance/routes.py +++ b/flaschengeist/plugins/balance/routes.py @@ -170,6 +170,7 @@ def get_transactions(userid, current_session: Session): show_cancelled = request.args.get("showCancelled", True) limit = request.args.get("limit") offset = request.args.get("offset") + descending = request.args.get("descending", False) try: if limit is not None: limit = int(limit) @@ -179,11 +180,20 @@ def get_transactions(userid, current_session: Session): show_reversals = str2bool(show_reversals) if not isinstance(show_cancelled, bool): show_cancelled = str2bool(show_cancelled) + if not isinstance(descending, bool): + descending = str2bool(descending) except ValueError: raise BadRequest transactions, count = balance_controller.get_transactions( - user, start, end, limit, offset, show_reversal=show_reversals, show_cancelled=show_cancelled + user, + start, + end, + limit, + offset, + show_reversal=show_reversals, + show_cancelled=show_cancelled, + descending=descending, ) return {"transactions": transactions, "count": count} diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index ef19807..b4df1ac 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -567,6 +567,7 @@ def get_columns(userid, current_session): userController.persist() return no_content() + @PriceListPlugin.blueprint.route("/users//pricecalc_columns_order", methods=["GET", "PUT"]) @login_required() def get_columns_order(userid, current_session):