def leave_courier(update, context: CallbackContext, user: Operator): courier = Utils.prepare_external_field(BW.COURIERS, user.deal_data.courier_id, BW.COURIERS_LOCK) message = Txt.COURIER_LEFT.format(user.deal_data.deal_id, courier) TgCommons.send_mdv2(update.effective_user, message) return TgCommons.restart(update, context)
def set_description(update, context: CallbackContext, user: Operator): user.deal_data.reserve_desc = update.message.text BH.update_deal_reserve(user) TgCommons.send_mdv2(update.effective_user, GlobalTxt.DEAL_UPDATED.format(user.deal_data.deal_id)) return TgCommons.restart(update, context)
def load_checklist_photo(update, context, user: Operator): if not user.equip.photos: keyboard = [[ InlineKeyboardButton(text=Txt.FINISH_PHOTO_LOADING, callback_data=Txt.FINISH_PHOTO_LOADING_CB) ]] TgCommons.send_mdv2(update.effective_user, Txt.NO_PHOTOS_TEXT, keyboard) return State.EQUIP_SET_PHOTOS photos: List[PhotoSize] = update.message.photo photo = photos[-1] unique_id = photo.file_unique_id photo_content = photo.get_file().download_as_bytearray() file_extension = photo.get_file().file_path.split('.')[-1] encoded_data = base64.b64encode(photo_content).decode('ascii') user.deal_data.photo_data = encoded_data user.deal_data.photo_name = unique_id + '.' + file_extension StorageHandlers.save_deal(user, user.deal_data.deal_id) BH.update_deal_image(user) TgCommons.send_mdv2(update.effective_user, GlobalTxt.DEAL_UPDATED.format(user.deal_data.deal_id)) return TgCommons.restart(update, context)
def choose_courier(update, context, user: Operator): courier_id = context.match.group(1) user.deal_data.courier_id = courier_id BH.send_deal(user) courier = Utils.prepare_external_field(BW.COURIERS, courier_id, BW.COURIERS_LOCK) message = Txt.DEAL_UPDATED.format(user.deal_data.deal_id, courier) TgCommons.send_mdv2(update.effective_user, message) return TgCommons.restart(update, context)
def choose_florist(update, context, user: Operator): florist_id = context.match.group(1) user.deal_data.florist_id = florist_id BH.update_deal_florist(user) with BW.FLORISTS_LOCK: florist = Utils.prepare_external_field( BW.FLORISTS, user.deal_data.florist_id).upper() message = Txt.DEAL_UPDATED.format(user.deal_data.deal_id, florist) TgCommons.send_mdv2(update.effective_user, message) return TgCommons.restart(update, context)
def finish_deal_helper(update, context, user): deal_id = user.deal_data.deal_id result = BitrixHandlers.finish_deal(user) if result == BW.BW_WRONG_STAGE: TgCommons.send_mdv2(update.effective_user, Txt.DEAL_IS_IN_WRONG_STAGE_TXT.format(deal_id)) return user.state TgCommons.send_mdv2(update.effective_user, Txt.DEAL_FINISHED.format(deal_id)) return TgCommons.restart(update, context)
def calendar_selection(update, context: CallbackContext, user: Operator): query = update.callback_query result, dt = TgCalendar.process_calendar_selection(update, context) if result: if dt < datetime.datetime.now(tz=cfg.TIMEZONE): query.answer(text=Txt.DATE_TOO_EARLY) context.bot.edit_message_text(text=query.message.text, chat_id=query.message.chat_id, message_id=query.message.message_id, reply_markup=InlineKeyboardMarkup( TgCalendar.create_calendar())) return None user.deal_data.supply_datetime = dt.isoformat() BH.update_deal_waiting_for_supply(user) TgCommons.send_mdv2( update.effective_user, GlobalTxt.DEAL_UPDATED.format(user.deal_data.deal_id)) TgCommons.restart(update, context)
def no_reserve_approve(update, context: CallbackContext, user: Operator): photo_stub_name = 'no_reserve_needed.png' photo_stub_path = pathlib.Path( __file__).parent.resolve() / 'data' / photo_stub_name with open(photo_stub_path, 'rb') as f: stub_bytes = f.read() user.reserve.add_deal_photo(Photo(photo_stub_name, stub_bytes)) BH.update_deal_no_reserve(user) TgCommons.send_mdv2(update.effective_user, GlobalTxt.DEAL_UPDATED.format(user.deal_data.deal_id)) return TgCommons.restart(update, context)
def set_warehouse_return_reason(update, context, user): deal_id = user.deal_data.deal_id user.data.warehouse_return_reason = update.message.text result = BitrixHandlers.return_to_warehouse(user) if result == BW.BW_WRONG_STAGE: TgCommons.send_mdv2(update.effective_user, Txt.DEAL_IS_IN_WRONG_STAGE_TXT.format(deal_id)) return user.state TgCommons.send_mdv2(update.effective_user, Txt.DEAL_RETURNED_TO_WAREHOUSE.format(deal_id)) return TgCommons.restart(update, context)
def leave_florist(update, context: CallbackContext, user: Operator): message = Txt.DEAL_UPDATED.format(user.deal_data.deal_id, user.deal_data.florist) TgCommons.send_mdv2(update.effective_user, message) return TgCommons.restart(update, context)