Private
Public Access
1
0

basic withdraw and upgrade

This commit is contained in:
Sander Roosendaal
2021-11-10 21:44:05 +01:00
parent 6efae814af
commit 1926f7073d
5 changed files with 53 additions and 2 deletions

26
rowers/credits.py Normal file
View File

@@ -0,0 +1,26 @@
from rowers.models import Rower
class InsufficientCreditError(Exception):
"""Raised when trying to subtract more than available"""
pass
def upgrade(amount, rower):
if rower.eurocredits > amount:
return rower.eurocredits
else:
rower.eurocredits = amount
rower.save()
return rower.eurocredits
return rower.eurocredits
def withdraw(amount, rower):
if rower.eurocredits < amount:
rower.eurocredits = 0
rower.save()
raise InsufficientCreditError
else:
rower.eurocredits = rower.eurocredits - amount
rower.save()
return rower.eurocredits
return rower.eurocredits