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()
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()