def add_product(self, user_id): temp = self.get_info(user_id, 'temp') name = temp[0] quantity = temp[1] cost = quantity * Product.get_price(name) self.data[str(user_id)]['products'].append( [name, quantity, cost, f'{datetime.now()}']) self.save() self.update_user(user_id, 'temp', []) self.update_user(user_id, 'status', 0) Product.update_product(name, quantity)
def answer(context, bot): user_id = context.message.chat_id msg_text = context.message.text status = DB.get_info(user_id, 'status') if status == 1 and msg_text.isdigit(): msg_text = int(msg_text) DB.update_user(user_id, 'temp', msg_text) if pr.get_quantity(DB.get_info(user_id, 'temp')[0]) >= msg_text: data = DB.get_info(user_id, 'temp')[0] text = tx.get_text('status_1').format( data, msg_text, msg_text * pr.get_price(data)) bot.bot.send_message(user_id, text, reply_markup=final_question()) DB.update_user(user_id, 'status', 2)