Beispiel #1
0
    def track_expense(self):
        price = type_input('price', float)
        price = int(price * 100)

        currency = query_choice(self.db.query(Currency))

        cat = query_choice(self.db.query(Category))

        advanced = bool_question('advanced options?', default=False)
        # initialize with simple setup
        issued = dt.datetime.now()
        note = None
        end = None
        repeat = None
        if advanced:
            if bool_question('Not issued right now?', default=False):
                issued = dt_input('Date if issue')

            if bool_question('Do you want to add a note?', default=False):
                note = str_input('Note')

            if bool_question('long term expense?', default=False):
                end = dt_input('End if expense')

            if bool_question('repeat?', default=False):
                repeat = type_input('Repeat this expense every _ months', int,
                                    default=-1)
                if repeat == -1:
                    repeat = None

        eur = to_eur(price, currency.identifier, issued)
        print('That was an expense of {:.2f}€'.format(eur / 100.0))

        expense = Expense(issued=issued,
                          price=price,
                          in_eur=eur,
                          note=note,
                          end=end,
                          repeat_interval=repeat,
                          currency=currency,
                          category=cat)
        self.db.add(expense)
        self.db.commit()

        if bool_question('another expense?', default=True):
            self.track_expense()
Beispiel #2
0
    def stats(self):
        now = dt.datetime.now()
        month = type_input('month', int, default=now.month)
        (categories, repeaters) = statistics(self.db, now.year, month)

        print('\nStatistics for {}'.format(
            dt.datetime(now.year, month, 1).strftime('%B')))

        total = 0
        for key, amount in categories.items():
            total += amount
            amount_str = '{:.2f}'.format(amount / 100.0)
            print('{cat.name:>16}: {amount:>8} €'.format(
                cat=self.db.query(Category).get(key), amount=amount_str))
        print('{:>16}: {:>8} €'.format(
            'TOTAL', '{:.2f}'.format(total / 100.0)))

        print('\nwith these repeating expenses considered')
        for item in repeaters:
            print(item)