def festive_reapprove(update: Update, context, user: BaseUser): deal_id = context.match.group(1) deal = BW.get_deal(deal_id) stage_id = deal.get(BFA.DEAL_STAGE_ALIAS) deal_stage = Utils.prepare_external_field(BW.STAGES, stage_id, BW.STAGES_LOCK) deal_order = Utils.prepare_external_field(deal, BFA.DEAL_ORDER_ALIAS) deal_date = Utils.prepare_deal_date(deal, BFA.DEAL_DATE_ALIAS) deal_time = Utils.prepare_deal_time(deal, BFA.DEAL_TIME_ALIAS) deal_sum = Utils.prepare_external_field(deal, BFA.DEAL_TOTAL_SUM_ALIAS) order_received_by_id = deal.get(BFA.DEAL_ORDER_RECEIVED_BY_ALIAS) deal_accepted = Utils.prepare_external_field(BW.BITRIX_IDS_USERS, order_received_by_id, BW.BITRIX_USERS_LOCK) source_id = Utils.prepare_external_field(deal, BFA.DEAL_SOURCE_ID_ALIAS) deal_source = Utils.prepare_external_field(BW.SOURCES, source_id, BW.SOURCES_LOCK) contact_id = Utils.prepare_external_field(deal, BFA.DEAL_CONTACT_ALIAS) contact_data = BW.get_contact_data(contact_id) contact_name = contact_data.get(BFA.CONTACT_USER_NAME_ALIAS) contact_phone = contact_data.get(BFA.CONTACT_PHONE_ALIAS) deal_contact = contact_name + ' ' + contact_phone subdivision_id = Utils.prepare_external_field(deal, BFA.DEAL_SUBDIVISION_ALIAS) deal_subdivision = Utils.prepare_external_field(BW.SUBDIVISIONS, subdivision_id, BW.SUBDIVISIONS_LOCK) deal_has_reserve = Utils.prepare_external_field(deal, BFA.DEAL_ORDER_HAS_RESERVE_ALIAS) deal_reserve_desc = Utils.prepare_external_field(deal, BFA.DEAL_ORDER_RESERVE_DESC_ALIAS) deal_delivery_type = Utils.prepare_deal_supply_method(deal, BFA.DEAL_SUPPLY_METHOD_ALIAS) district_id = Utils.prepare_external_field(deal, BFA.DEAL_DISTRICT_ALIAS) deal_district = Utils.prepare_external_field(BW.DISTRICTS, district_id, BW.DISTRICTS_LOCK) address, location = Utils.prepare_deal_address(deal, BFA.DEAL_ADDRESS_ALIAS) deal_address = address deal_delivery_comment = Utils.prepare_external_field(deal, BFA.DEAL_DELIVERY_COMMENT_ALIAS) payment_type_id = Utils.prepare_external_field(deal, BFA.DEAL_PAYMENT_TYPE_ALIAS) deal_pay_type = Utils.prepare_external_field(BW.PAYMENT_TYPES, payment_type_id, BW.PAYMENT_TYPES_LOCK) payment_method_id = Utils.prepare_external_field(deal, BFA.DEAL_PAYMENT_METHOD_ALIAS) deal_pay_method = Utils.prepare_external_field(BW.PAYMENT_METHODS, payment_method_id, BW.PAYMENT_METHODS_LOCK) deal_prepaid = Utils.prepare_external_field(deal, BFA.DEAL_PREPAID_ALIAS) deal_terminal = Utils.prepare_external_field(BW.DEAL_TERMINAL_CHANGE_MAPPING, Utils.prepare_external_field(deal, BFA.DEAL_TERMINAL_CHANGE_ALIAS)) deal_change = Utils.prepare_external_field(deal, BFA.DEAL_CHANGE_SUM_ALIAS) deal_to_pay = Utils.prepare_external_field(deal, BFA.DEAL_TO_PAY_ALIAS) deal_pay_status = Utils.prepare_external_field(deal, BFA.DEAL_PAYMENT_STATUS_ALIAS) if deal_has_reserve == BFM.DEAL_HAS_RESERVE_YES: with BW.BITRIX_USERS_LOCK: access_token = context.bot_data[cfg.BOT_ACCESS_TOKEN_PERSISTENT_KEY] photo_urls = BW.process_deal_photo_dl_urls(deal, access_token, (BFA.DEAL_ORDER_RESERVE_ALIAS,)) else: photo_urls = None BH.reapprove_deal(deal_id) HttpJobs.send_festive_deal_message(context.bot, deal_id, deal_stage, deal_order, deal_date, deal_time, deal_sum, deal_accepted, deal_source, deal_contact, deal_subdivision, deal_reserve_desc, deal_delivery_type, deal_district, deal_address, deal_delivery_comment, deal_pay_method, deal_pay_type, deal_prepaid, deal_terminal, deal_change, deal_to_pay, deal_pay_status, photo_urls) edited_msg = re.sub(re.escape(Txt.DECLINED_HEADER.format(deal_id)), Txt.REAPPROVED_HEADER.format(deal_id), update.effective_message.text_markdown_v2) TgCommons.edit_mdv2(update.effective_message, msg_text=edited_msg, need_cancel=False)
def get_info(context, deal_id, user: BaseUser): deal = BW.get_deal(deal_id) user.festive_data.deal_link = Utils.prepare_external_field( deal, BFA.DEAL_LINK_ALIAS) user.festive_data.deal_order = Utils.prepare_external_field( deal, BFA.DEAL_ORDER_ALIAS) user.festive_data.deal_user_declined = Utils.prepare_external_field( BW.BITRIX_IDS_USERS, user.bitrix_user_id, BW.BITRIX_USERS_LOCK) subdiv_id = deal.get(BFA.DEAL_SUBDIVISION_ALIAS) subdiv_name = Utils.prepare_external_field(BW.SUBDIVISIONS, subdiv_id, BW.SUBDIVISIONS_LOCK, escape_md=False) user.festive_data.subdiv_chat_id = creds.FESTIVE_UNAPPROVED_SUBDIVS.get( subdiv_name) user.festive_data.deal_date = Utils.prepare_deal_date( deal, BFA.DEAL_DATE_ALIAS) user.festive_data.deal_time = Utils.prepare_deal_time( deal, BFA.DEAL_TIME_ALIAS) user.festive_data.deal_sum = Utils.prepare_external_field( deal, BFA.DEAL_TOTAL_SUM_ALIAS) order_received_by_id = deal.get(BFA.DEAL_ORDER_RECEIVED_BY_ALIAS) user.festive_data.deal_accepted = Utils.prepare_external_field( BW.BITRIX_IDS_USERS, order_received_by_id, BW.BITRIX_USERS_LOCK) source_id = Utils.prepare_external_field(deal, BFA.DEAL_SOURCE_ID_ALIAS) user.festive_data.deal_source = Utils.prepare_external_field( BW.SOURCES, source_id, BW.SOURCES_LOCK) contact_id = Utils.prepare_external_field(deal, BFA.DEAL_CONTACT_ALIAS) contact_data = BW.get_contact_data(contact_id) contact_name = contact_data.get(BFA.CONTACT_USER_NAME_ALIAS) contact_phone = contact_data.get(BFA.CONTACT_PHONE_ALIAS) user.festive_data.deal_contact = contact_name + ' ' + contact_phone subdivision_id = Utils.prepare_external_field(deal, BFA.DEAL_SUBDIVISION_ALIAS) user.festive_data.deal_subdivision = Utils.prepare_external_field( BW.SUBDIVISIONS, subdivision_id, BW.SUBDIVISIONS_LOCK) user.festive_data.deal_has_reserve = Utils.prepare_external_field( deal, BFA.DEAL_ORDER_HAS_RESERVE_ALIAS) user.festive_data.deal_reserve_desc = Utils.prepare_external_field( deal, BFA.DEAL_ORDER_RESERVE_DESC_ALIAS) user.festive_data.deal_delivery_type = Utils.prepare_deal_supply_method( deal, BFA.DEAL_SUPPLY_METHOD_ALIAS) district_id = Utils.prepare_external_field(deal, BFA.DEAL_DISTRICT_ALIAS) user.festive_data.deal_district = Utils.prepare_external_field( BW.DISTRICTS, district_id, BW.DISTRICTS_LOCK) address, location = Utils.prepare_deal_address(deal, BFA.DEAL_ADDRESS_ALIAS) user.festive_data.deal_address = address user.festive_data.deal_delivery_comment = Utils.prepare_external_field( deal, BFA.DEAL_DELIVERY_COMMENT_ALIAS) payment_type_id = Utils.prepare_external_field(deal, BFA.DEAL_PAYMENT_TYPE_ALIAS) user.festive_data.deal_pay_type = Utils.prepare_external_field( BW.PAYMENT_TYPES, payment_type_id, BW.PAYMENT_TYPES_LOCK) payment_method_id = Utils.prepare_external_field( deal, BFA.DEAL_PAYMENT_METHOD_ALIAS) user.festive_data.deal_pay_method = Utils.prepare_external_field( BW.PAYMENT_METHODS, payment_method_id, BW.PAYMENT_METHODS_LOCK) user.festive_data.deal_prepaid = Utils.prepare_external_field( deal, BFA.DEAL_PREPAID_ALIAS) user.festive_data.deal_terminal = Utils.prepare_external_field( BW.DEAL_TERMINAL_CHANGE_MAPPING, Utils.prepare_external_field(deal, BFA.DEAL_TERMINAL_CHANGE_ALIAS)) user.festive_data.deal_change = Utils.prepare_external_field( deal, BFA.DEAL_CHANGE_SUM_ALIAS) user.festive_data.deal_to_pay = Utils.prepare_external_field( deal, BFA.DEAL_TO_PAY_ALIAS) user.festive_data.deal_pay_status = Utils.prepare_external_field( deal, BFA.DEAL_PAYMENT_STATUS_ALIAS) if user.festive_data.deal_has_reserve == BFM.DEAL_HAS_RESERVE_YES: with BW.BITRIX_USERS_LOCK: access_token = context.bot_data[ cfg.BOT_ACCESS_TOKEN_PERSISTENT_KEY] user.festive_data.photo_urls = BW.process_deal_photo_dl_urls( deal, access_token, (BFA.DEAL_ORDER_RESERVE_ALIAS, )) else: user.festive_data.photo_urls = None