~homeworkprod/byceps

ref: bcef32cd2dc329bcf81057794883008f5c040ac8 byceps/byceps/services/shop/order/actions/_ticketing.py -rw-r--r-- 1.4 KiB
bcef32cd — Jochen Kupperschmidt Work around Jinja 3.0.0 bug with `for` inside of `set` block 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
byceps.services.shop.order.actions._ticketing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from .....events.ticketing import TicketsSold
from .....signals import ticketing as ticketing_signals
from .....typing import UserID

from ....ticketing import category_service
from ....ticketing.transfer.models import TicketCategoryID
from ....user import service as user_service

from .. import service as order_service
from ..transfer.models import OrderID


def create_tickets_sold_event(
    order_id: OrderID,
    initiator_id: UserID,
    category_id: TicketCategoryID,
    owner_id: UserID,
    quantity: int,
) -> TicketsSold:
    occurred_at = order_service.get_payment_date(order_id)
    initiator_screen_name = user_service.find_screen_name(initiator_id)
    category = category_service.find_category(category_id)
    owner_screen_name = user_service.find_screen_name(owner_id)

    return TicketsSold(
        occurred_at=occurred_at,
        initiator_id=initiator_id,
        initiator_screen_name=initiator_screen_name,
        party_id=category.party_id,
        owner_id=owner_id,
        owner_screen_name=owner_screen_name,
        quantity=quantity,
    )


def send_tickets_sold_event(event: TicketsSold) -> None:
    ticketing_signals.tickets_sold.send(None, event=event)