コード例 #1
0
    def changeAmount(self, currency, amount):
        def func():
            curr = currency.casefold()
            value = amount
            self._amount[curr] += value

        f.execWithException(self.changeAmount, func, KeyError, ValueError)
コード例 #2
0
    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
コード例 #3
0
    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
コード例 #4
0
ファイル: month.py プロジェクト: SerhiiH/personal_bookkeeper
    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
コード例 #5
0
    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
コード例 #6
0
ファイル: month.py プロジェクト: SerhiiH/personal_bookkeeper
 def getItemsGroup(self, itemsGroup):
     return f.execWithException(
         self.getItemsGroup,
         lambda: self.itemsGroups[itemsGroup.casefold()], KeyError)
コード例 #7
0
 def deleteCurrency(self, currency):
     f.execWithException(self.deleteCurrency,
                         lambda: self._amount.pop(currency.casefold()),
                         KeyError)
コード例 #8
0
 def getItemCorrespondItem(self, item):
     return f.execWithException(
         self.getItemCorrespondItem,
         lambda: self.itemsList[item.casefold()].correspondItem, KeyError)
コード例 #9
0
 def changeItemAmount(self, item, amount, currency):
     f.execWithException(
         self.changeItemAmount,
         lambda: self.itemsList[item.casefold()].changeAmount(
             currency, amount), KeyError)
コード例 #10
0
 def deleteItemCurrency(self, item, currency):
     f.execWithException(
         self.deleteItemCurrency,
         lambda: self.itemsList[item.casefold()].deleteCurrency(currency),
         KeyError)
コード例 #11
0
 def deleteItem(self, item):
     f.execWithException(self.deleteItem,
                         lambda: self.itemsList.pop(item.casefold()),
                         KeyError)