[balance] add correct notification

This commit is contained in:
Tim Gröger 2021-11-27 00:36:28 +01:00
parent 079fbafb97
commit d2ef02c2af
2 changed files with 20 additions and 3 deletions

View File

@ -14,6 +14,7 @@ from . import permissions, models
class BalancePlugin(Plugin): class BalancePlugin(Plugin):
name = "balance" name = "balance"
id = "dev.flaschengeist.balance"
blueprint = Blueprint(name, __name__) blueprint = Blueprint(name, __name__)
permissions = permissions.permissions permissions = permissions.permissions
plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][BalancePlugin.name]) plugin = LocalProxy(lambda: current_app.config["FG_PLUGINS"][BalancePlugin.name])

View File

@ -2,7 +2,7 @@
# Haben -> Zugang aufs Konto # Haben -> Zugang aufs Konto
# English: Debit -> from account # English: Debit -> from account
# Credit -> to account # Credit -> to account
from enum import IntEnum
from sqlalchemy import func, case, and_ from sqlalchemy import func, case, and_
from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.ext.hybrid import hybrid_property
from datetime import datetime from datetime import datetime
@ -17,6 +17,11 @@ from . import permissions, BalancePlugin
__attribute_limit = "balance_limit" __attribute_limit = "balance_limit"
class NotifyType(IntEnum):
SEND_TO = 0x01
SEND_FROM = 0x02
def set_limit(user: User, limit: float, override=True): def set_limit(user: User, limit: float, override=True):
if override or not user.has_attribute(__attribute_limit): if override or not user.has_attribute(__attribute_limit):
user.set_attribute(__attribute_limit, 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.add(transaction)
db.session.commit() db.session.commit()
if sender is not None and sender.id_ != author.id_: 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_: 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 return transaction