File size: 873 Bytes
2f85c93 8cf77a3 6900003 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from src.manager.utils.singleton import singleton
@singleton
class BudgetManager():
TOTAL_BUDGET = 100
current_expense = 0
def get_total_budget(self):
return self.TOTAL_BUDGET
def get_current_expense(self):
return self.current_expense
def get_current_remaining_budget(self):
return self.TOTAL_BUDGET - self.current_expense
def can_spend(self, cost):
return True if self.current_expense + cost <= self.TOTAL_BUDGET else False
def add_to_expense(self, cost):
if not self.can_spend(cost):
raise Exception("No budget remaining")
self.current_expense += cost
def remove_from_expense(self, cost):
if self.current_expense - cost < 0:
raise Exception("Cannot remove more than current expense")
self.current_expense -= cost |