def edit_categories(self): for item in self.db.query(Category): print(item.name) 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) 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()