From d2ef02c2aff5369000eecad737d96ffa7649ba64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 27 Nov 2021 00:36:28 +0100 Subject: [PATCH] [balance] add correct notification --- flaschengeist/plugins/balance/__init__.py | 1 + .../plugins/balance/balance_controller.py | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/flaschengeist/plugins/balance/__init__.py b/flaschengeist/plugins/balance/__init__.py index a7558f9..cb4d929 100644 --- a/flaschengeist/plugins/balance/__init__.py +++ b/flaschengeist/plugins/balance/__init__.py @@ -14,6 +14,7 @@ from . import permissions, models class BalancePlugin(Plugin): name = "balance" + id = "dev.flaschengeist.balance" blueprint = Blueprint(name, __name__) permissions = permissions.permissions plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][BalancePlugin.name]) diff --git a/flaschengeist/plugins/balance/balance_controller.py b/flaschengeist/plugins/balance/balance_controller.py index 9925b44..e11b6b7 100644 --- a/flaschengeist/plugins/balance/balance_controller.py +++ b/flaschengeist/plugins/balance/balance_controller.py @@ -2,7 +2,7 @@ # Haben -> Zugang aufs Konto # English: Debit -> from account # Credit -> to account - +from enum import IntEnum from sqlalchemy import func, case, and_ from sqlalchemy.ext.hybrid import hybrid_property from datetime import datetime @@ -17,6 +17,11 @@ from . import permissions, BalancePlugin __attribute_limit = "balance_limit" +class NotifyType(IntEnum): + SEND_TO = 0x01 + SEND_FROM = 0x02 + + def set_limit(user: User, limit: float, override=True): if override or not user.has_attribute(__attribute_limit): user.set_attribute(__attribute_limit, limit) @@ -175,9 +180,20 @@ def send(sender: User, receiver, amount: float, author: User): db.session.add(transaction) db.session.commit() if sender is not None and sender.id_ != author.id_: - BalancePlugin.plugin.notify(sender, "Neue Transaktion") + BalancePlugin.plugin.notify( + sender, + "Neue Transaktion", + { + "type": NotifyType.SEND_FROM, + "receiver_id": receiver.userid, + "author_id": author.userid, + "amount": amount, + }, + ) if receiver is not None and receiver.id_ != author.id_: - BalancePlugin.plugin.notify(receiver, "Neue Transaktion") + BalancePlugin.plugin.notify( + receiver, "Neue Transaktion", {"type": NotifyType.SEND_TO, "sender_id": sender.userid, "amount": amount} + ) return transaction