basic withdraw and upgrade
This commit is contained in:
26
rowers/credits.py
Normal file
26
rowers/credits.py
Normal 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
|
||||
Reference in New Issue
Block a user