[Plugin]balance: Fixed typo in function name and fixed db model

This commit is contained in:
Ferdinand Thiessen 2020-11-25 20:35:11 +01:00
parent 4534d0ff15
commit 991ffb2766
3 changed files with 5 additions and 3 deletions

View File

@ -164,7 +164,7 @@ def change_balance(userid, current_session: Session):
if (sender == current_session._user and sender.has_permission(permissions.SEND)) or ( if (sender == current_session._user and sender.has_permission(permissions.SEND)) or (
sender != current_session._user and current_session._user.has_permission(permissions.SEND_OTHER) sender != current_session._user and current_session._user.has_permission(permissions.SEND_OTHER)
): ):
return HTTP.created(balance_controller.send(sender, user, data["amount"], current_session._user)) return HTTP.created(balance_controller.send(sender, user, amount, current_session._user))
elif ( elif (
amount < 0 amount < 0

View File

@ -71,7 +71,7 @@ def send(sender: User, receiver, amount: float, author: User):
raise BadRequest raise BadRequest
if sender and sender.has_attribute(__attribute_limit): if sender and sender.has_attribute(__attribute_limit):
if (get(sender)[2] - amount) < sender.get_attribute(__attribute_limit) and not author.has_permission( if (get_balance(sender)[2] - amount) < sender.get_attribute(__attribute_limit) and not author.has_permission(
permissions.EXCEED_LIMIT permissions.EXCEED_LIMIT
): ):
raise BadRequest("Limit exceeded") raise BadRequest("Limit exceeded")

View File

@ -19,7 +19,9 @@ class Transaction(db.Model, ModelSerializeMixin):
id: int = db.Column("id", db.Integer, primary_key=True) id: int = db.Column("id", db.Integer, primary_key=True)
time: datetime = db.Column(UtcDateTime, nullable=False, default=UtcDateTime.current_utc) time: datetime = db.Column(UtcDateTime, nullable=False, default=UtcDateTime.current_utc)
amount: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False) amount: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False)
reversal: Optional["Transaction"] = db.relationship("Transaction", foreign_keys=[_reversal_id]) reversal: Optional["Transaction"] = db.relationship(
"Transaction", uselist=False, post_update=True, foreign_keys=[_reversal_id]
)
# Dummy properties used for JSON serialization (userid instead of full user) # Dummy properties used for JSON serialization (userid instead of full user)
sender_id: Optional[str] = "" sender_id: Optional[str] = ""