route for baruser to storno, ##164

This commit is contained in:
Tim Gröger 2020-02-19 23:11:24 +01:00
parent 0035a2517d
commit 7038928e49
1 changed files with 31 additions and 0 deletions

View File

@ -95,6 +95,37 @@ def _getUsers(**kwargs):
retVal = ldap.getAllUser() retVal = ldap.getAllUser()
return jsonify(retVal) return jsonify(retVal)
@baruser.route("/bar/storno", methods=['POST'])
@login_required(groups=[BAR])
def _storno(**kwargs):
""" Function for Baruser to storno amount
This function added to the user with the posted userID the posted amount.
Returns:
JSON-File with userID and the amount
or ERROR 401 Permission Denied
"""
data = request.get_json()
userID = data['userId']
amount = int(data['amount'])
date = datetime.now()
userController.addCredit(userID, amount, year=date.year, month=date.month)
user = userController.getUser(userID)
geruecht = user.getGeruecht(year=date.year)
month = geruecht.getMonth(month=date.month)
amount = abs(month[0] - month[1])
all = geruecht.getSchulden()
if all >= 0:
type = 'credit'
else:
type = 'amount'
dic = user.toJSON()
dic['amount'] = abs(all)
dic['type'] = type
return jsonify(dic)
@baruser.route("/barGetUser", methods=['POST']) @baruser.route("/barGetUser", methods=['POST'])
@login_required(groups=[BAR]) @login_required(groups=[BAR])