def changeAmount(self, currency, amount): def func(): curr = currency.casefold() value = amount self._amount[curr] += value f.execWithException(self.changeAmount, func, KeyError, ValueError)
def processRequest(self, requestString): args = [arg.strip().casefold() for arg in requestString.split(',')] def func(): if len(args) > 1: self.commands[args[0]](*args[1:]) else: self.commands[args[0]]() try: f.execWithException(self.processRequest, func, KeyError, TypeError) except (KeyError, TypeError): return
def inputTotal(self, *args): def func(): item = args[0] amount = Runtime.reduceAmount(args[1]) if len(args) == 2: currency = 'uah' else: currency = args[2] self.totalLiab.changeItemAmount(item, amount, currency) try: f.execWithException(self.inputTotal, func, ValueError, KeyError, IndexError) except (ValueError, KeyError, IndexError): return
def __init__(self, name): def func(): with open('database\\items_types_groups.pkl', 'rb') as fileDB: itemsTypesGroups = pickle.load(fileDB) self.itemsGroups = {} self.itemsGroups['expenses'] = Expenses( itemsTypesGroups['expenses']) self.itemsGroups['incomes'] = Incomes(itemsTypesGroups['incomes']) self.itemsGroups['liabilities'] = Liabilities( itemsTypesGroups['liabilities']) self.name = name.casefold() try: f.execWithException(self.__init__, func, EOFError) except EOFError: print('ERROR!!! Items types groups are not set') return
def inputCurrent(self, *args): if not self.currentMonth: print('"Current Month" record must be created before filling in.') return def func(): itemsGroupName = args[0] itemName = args[1] amount = Runtime.reduceAmount(args[2]) if len(args) == 3: currency = 'uah' else: currency = args[3] itemsGroup = self.currentMonth.getItemsGroup(itemsGroupName) itemsGroup.changeItemAmount(itemName, amount, currency) itemCorrespondItem = itemsGroup.getItemCorrespondItem(itemName) if itemCorrespondItem and itemsGroupName.casefold( ) != 'liabilities': if itemsGroupName.casefold() == 'expenses': amount *= -1 itemsGroupLiab = self.currentMonth.getItemsGroup('liabilities') itemsGroupLiab.changeItemAmount(itemCorrespondItem, amount, currency) self.totalLiab.changeItemAmount(itemCorrespondItem, amount, currency) if itemsGroupName.casefold() == 'liabilities': self.totalLiab.changeItemAmount(itemName, amount, currency) if len(args) == 3: self.logTransaction(*args, currency) else: self.logTransaction(*args) try: f.execWithException(self.inputCurrent, func, ValueError, IndexError, KeyError) except (ValueError, IndexError, KeyError): return
def getItemsGroup(self, itemsGroup): return f.execWithException( self.getItemsGroup, lambda: self.itemsGroups[itemsGroup.casefold()], KeyError)
def deleteCurrency(self, currency): f.execWithException(self.deleteCurrency, lambda: self._amount.pop(currency.casefold()), KeyError)
def getItemCorrespondItem(self, item): return f.execWithException( self.getItemCorrespondItem, lambda: self.itemsList[item.casefold()].correspondItem, KeyError)
def changeItemAmount(self, item, amount, currency): f.execWithException( self.changeItemAmount, lambda: self.itemsList[item.casefold()].changeAmount( currency, amount), KeyError)
def deleteItemCurrency(self, item, currency): f.execWithException( self.deleteItemCurrency, lambda: self.itemsList[item.casefold()].deleteCurrency(currency), KeyError)
def deleteItem(self, item): f.execWithException(self.deleteItem, lambda: self.itemsList.pop(item.casefold()), KeyError)