def choose_uk(call): if authorized(message=call.message, bot=bot): if User.get(telegram_id=call.message.chat.id).status.split('_')[0] == 'MOVE': uk_num = call.data.split('_')[1] it_id = User.get(telegram_id=call.message.chat.id).status.split('_')[1] movement = Movement.create(it_id=Equipment.get(it_id=it_id), korpus=f'УК {uk_num}', room='N/A') # movement.update(korpus=f'УК {uk_num}').execute() # Movement.create(it_id=it_id, # korpus=f'УК {uk_num}', # room='___') bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=bot_messages_text.get('enter_room_num'))
def plain_text_message(message: Message): if authorized(message=message, bot=bot): # для вновь подключенного пользователя свой синхронизатор с Google-таблицей if users.get(f'{message.chat.id}') is None: users[f'{message.chat.id}'] = { 'operator': GoogleSynchronizer(spreadsheet_id=SPREADSHEET_ID, credentials_file_name=CREDENTIAL_FILE) } # Обработка нажатия кнопки показа основных функций if message.text == main_reply_keyboard_text: User.update(status='').where(User.telegram_id == message.chat.id).execute() bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('show_functions'), reply_markup=main_inline_keyboard) return # Поиск по инвентарному или серийному номеру if User.get(telegram_id=message.chat.id).status == INVENT_SEARCH or \ User.get(telegram_id=message.chat.id).status == SERIAL_SEARCH: found_items = None temp_item = None if User.get(telegram_id=message.chat.id).status == INVENT_SEARCH: bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('invent_search').format(invent_num=message.text)) found_items = Equipment.select().where(Equipment.invent_num == message.text) elif User.get(telegram_id=message.chat.id).status == SERIAL_SEARCH: bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('serial_search').format(serial_num=message.text)) found_items = Equipment.select().where(Equipment.serial_num == message.text) show_equipments(found_items, bot, message) # Выполнить перемещение в базе if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'MOVE': Movement.update(room=message.text). \ where(Movement.it_id == Equipment.get(it_id=User.get(telegram_id=message.chat.id).status.split('_')[1]) and Movement.room == 'N/A'). \ execute() users[f'{message.chat.id}'].get('operator').add_new_movement( id=User.get(telegram_id=message.chat.id).status.split('_')[1]) bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('complete_move')) found_items = Equipment.select().where( Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again']) show_equipments(found_items, bot, message) if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-type': Equipment.update(type=message.text). \ where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \ execute() users[f'{message.chat.id}'].get('operator').edit_in_table( item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1])) bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('edit_complete')) found_items = Equipment.select().where( Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again']) show_equipments(found_items, bot, message) if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-mark': Equipment.update(mark=message.text). \ where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \ execute() users[f'{message.chat.id}'].get('operator').edit_in_table( item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1])) bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('edit_complete')) found_items = Equipment.select().where( Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again']) show_equipments(found_items, bot, message) if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-model': Equipment.update(model=message.text). \ where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \ execute() users[f'{message.chat.id}'].get('operator').edit_in_table( item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1])) bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('edit_complete')) found_items = Equipment.select().where( Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again']) show_equipments(found_items, bot, message) if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-serial': Equipment.update(serial_num=message.text). \ where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \ execute() users[f'{message.chat.id}'].get('operator').edit_in_table( item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1])) bot.send_message(chat_id=message.chat.id, text=bot_messages_text.get('edit_complete')) found_items = Equipment.select().where( Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again']) show_equipments(found_items, bot, message) User.update(status='').where(User.telegram_id == message.chat.id).execute()