Пример #1
0
 def edit_categories(self):
     menu = list_choice(['add', 'edit', 'delete', 'back'])
     if menu == 'add':
         new = Category(name=str_input('Name'))
         self.db.add(new)
     elif menu == 'edit':
         edit = query_choice(self.db.query(Category))
         edit.name = str_input('New name')
     elif menu == 'delete':
         rm = query_choice(self.db.query(Category))
         self.db.delete(rm)
     self.db.commit()
Пример #2
0
    def __init__(self):
        file_valid = False
        while not file_valid:  # test if file exists
            db_name = str_input('datenbank', default='test') + '.db'
            file_valid = exists(db_name)
            if not file_valid:
                print('File not found :(')

        success = False
        while not success:
            db_password = str_input('passwort', default='123456')
            database = db_connect(db_name, password=db_password)
            # try if password was correct
            try:
                database.query(Currency).all()
                success = True
            except DatabaseError:
                success = False

        # FINALLY
        self.db = database
Пример #3
0
    def track_expense(self):
        price = type_input('price', float)
        price = int(price * 100)

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

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

        if bool_question('Not issued right now?', default=False):
            issued = dt_input('Date if issue')
        else:
            issued = dt.datetime.now()

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

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

        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,
                          currency=currency,
                          category=cat)
        self.db.add(expense)
        self.db.commit()

        if bool_question('another expense?', default=False):
            self.track_expense()