Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError in reserve_admin_hl #155

Merged
merged 7 commits into from
Feb 24, 2024
2 changes: 1 addition & 1 deletion src/conv_hl/reserve_admin_conv_hl.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
reserve_admin_conv_hl = ConversationHandler(
entry_points=[
CommandHandler(COMMAND_DICT['RESERVE_ADMIN'][0],
reserve_admin_hl.choice_option_enter),
reserve_admin_hl.event_selection_option),
],
states=states,
fallbacks=[CommandHandler('help', main_hl.help_command)],
Expand Down
80 changes: 40 additions & 40 deletions src/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
class User(BaseModelTimed):
__tablename__ = 'users'

id: Mapped[int] = mapped_column(BigInteger,
primary_key=True,
autoincrement=False)
chat_id: Mapped[int] = mapped_column(BigInteger,
primary_key=True,
autoincrement=False)

name: Mapped[str]
phone: Mapped[Optional[str]]
callback_name: Mapped[str]
callback_phone: Mapped[Optional[str]]
username: Mapped[str]

children: Mapped[List['Child']] = relationship(back_populates='users')
Expand All @@ -37,42 +37,13 @@ class Child(BaseModel):
users: Mapped['User'] = relationship(back_populates='children')


class TypeEvent(BaseModel):
__tablename__ = 'type_events'

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
name_alias: Mapped[str]
price_for_gift: Mapped[int]

notes: Mapped[Optional[str]]


class TheaterEvent(BaseModel):
__tablename__ = 'theater_events'

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
flag_premier: Mapped[bool] = mapped_column(default=False)
min_age_child: Mapped[int]
max_age_child: Mapped[int]
show_emoji: Mapped[str]
# full_name: Mapped[bool]
flag_active_repertoire: Mapped[bool]
flag_active_bd: Mapped[bool]
max_num_child_bd: Mapped[int]
max_num_adult_bd: Mapped[int]
flag_indiv_cost: Mapped[bool] = mapped_column(default=False)
event_type: Mapped[int]


class TicketStatusEnum(enum.Enum):
PAID = 'paid'
APPROVED = 'approved'
REJECTED = 'rejected'
REFUNDED = 'refunded'
TRANSFERRED = 'transferred'
POSTPONED = 'postponed'
PAID = 'paid' # Оплачен
APPROVED = 'approved' # Подтвержден
REJECTED = 'rejected' # Отклонен
REFUNDED = 'refunded' # Возвращен
TRANSFERRED = 'transferred' # Передан
POSTPONED = 'postponed' # Перенесен


class Ticket(BaseModelTimed):
Expand Down Expand Up @@ -100,10 +71,39 @@ class Ticket(BaseModelTimed):
notes: Mapped[Optional[str]]


class TypeEvent(BaseModel):
__tablename__ = 'type_events'

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
name_alias: Mapped[str]
price_for_gift: Mapped[int]

notes: Mapped[Optional[str]]


class TheaterEvent(BaseModel):
__tablename__ = 'theater_events'

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
flag_premier: Mapped[bool] = mapped_column(default=False)
min_age_child: Mapped[int]
max_age_child: Mapped[int]
show_emoji: Mapped[str]
# full_name: Mapped[bool]
flag_active_repertoire: Mapped[bool]
flag_active_bd: Mapped[bool]
max_num_child_bd: Mapped[int]
max_num_adult_bd: Mapped[int]
flag_indiv_cost: Mapped[bool] = mapped_column(default=False)


class ScheduleEvent(BaseModelTimed):
__tablename__ = 'schedule_events'

id: Mapped[int] = mapped_column(primary_key=True)
event_type: Mapped[int]

type_id: Mapped[int] = mapped_column(
ForeignKey('type_events.id', ondelete='CASCADE')
Expand Down
37 changes: 21 additions & 16 deletions src/handlers/reserve_admin_hl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
reserve_admin_hl_logger = logging.getLogger('bot.reserve_admin_hl')


async def choice_option_enter(
async def event_selection_option(
update: Update,
context: ContextTypes.DEFAULT_TYPE
):
Expand Down Expand Up @@ -98,6 +98,7 @@ async def choice_option_of_reserve(
update.effective_chat.id,
context.user_data['message'])
event_id = update.effective_message.text
message = await update.effective_chat.send_message('Загружаю данные')

user = context.user_data['user']
reserve_admin_hl_logger.info(": ".join(
Expand All @@ -111,6 +112,7 @@ async def choice_option_of_reserve(

event_info, name_column = load_show_info(int(event_id))
list_of_tickets = context.bot_data['list_of_tickets']
await message.edit_text('Данные загружены')

text = ''
keyboard = []
Expand All @@ -137,8 +139,8 @@ async def choice_option_of_reserve(
keyboard.append(add_btn_back_and_cancel(postfix_for_cancel='res',
postfix_for_back=1))
reply_markup = InlineKeyboardMarkup(keyboard)
await update.effective_chat.send_message(text=text,
reply_markup=reply_markup)
await message.edit_text(text=text,
reply_markup=reply_markup)

option, text_emoji = await get_emoji_and_options_for_event(event_info,
name_column)
Expand Down Expand Up @@ -172,7 +174,11 @@ async def start_forma_info(
await query.answer()

key_option_for_reserve = int(query.data)

common_data = context.user_data['common_data']
reserve_user_data = context.user_data['reserve_user_data']
reserve_admin_data = context.user_data['reserve_admin_data']

choose_event_info = reserve_user_data['choose_event_info']
chose_ticket, price = await get_chose_ticket_and_price(
choose_event_info,
Expand All @@ -181,23 +187,11 @@ async def start_forma_info(
reserve_user_data
)

common_data = context.user_data['common_data']
common_data['dict_of_shows'].clear()

reserve_user_data = context.user_data['reserve_user_data']
reserve_user_data['chose_price'] = price
if context.user_data.get('dict_of_name_show', False):
reserve_user_data['dict_of_name_show'].clear()
if context.user_data.get('dict_of_name_show_flip', False):
reserve_user_data['dict_of_name_show_flip'].clear()
if context.user_data.get('dict_of_date_show', False):
reserve_user_data['dict_of_date_show'].clear()
reserve_user_data['back'].clear()

reserve_admin_data = context.user_data['reserve_admin_data']
payment_id = reserve_admin_data['payment_id']
reserve_admin_data[payment_id]['chose_ticket'] = chose_ticket
event_id = reserve_admin_data[payment_id]['event_id']

list_of_name_colum = [
'qty_child_free_seat',
'qty_adult_free_seat',
Expand Down Expand Up @@ -227,6 +221,17 @@ async def start_forma_info(
parse_mode=ParseMode.HTML
)

if common_data.get('dict_of_shows', False):
common_data['dict_of_shows'].clear()
if reserve_user_data.get('dict_of_name_show', False):
reserve_user_data['dict_of_name_show'].clear()
if reserve_user_data.get('dict_of_name_show_flip', False):
reserve_user_data['dict_of_name_show_flip'].clear()
if reserve_user_data.get('dict_of_date_show', False):
reserve_user_data['dict_of_date_show'].clear()
if reserve_user_data.get('dict_of_date_show', False):
reserve_user_data['back'].clear()

state = 'FORMA'
context.user_data['STATE'] = state
return state
4 changes: 2 additions & 2 deletions src/utilities/schemas/context_bot_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
'min_age_child': int,
'max_age_child': int,
'show_emoji': str,
'full_name': str,
'flag_repertoire': bool,
'birthday': {
'flag': bool,
'max_num_child': int,
'max_num_adult': int,
},
'flag_repertoire': bool,
'flag_indiv_cost': bool,
'full_name': str,
'price_type': str,
},
},
Expand Down