~homeworkprod/byceps

ref: bcef32cd2dc329bcf81057794883008f5c040ac8 byceps/byceps/services/shop/order/actions/revoke_ticket_bundles.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
46
47
48
49
"""
byceps.services.shop.order.actions.revoke_ticket_bundles
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from .....typing import UserID

from ....ticketing import ticket_bundle_service, ticket_service
from ....ticketing.transfer.models import TicketBundleID

from ...article.transfer.models import ArticleNumber

from .. import event_service
from ..dbmodels.order_action import Parameters
from ..transfer.models import Order, OrderID


def revoke_ticket_bundles(
    order: Order,
    article_number: ArticleNumber,
    bundle_quantity: int,
    initiator_id: UserID,
    parameters: Parameters,
) -> None:
    """Revoke all ticket bundles in this order."""
    # Fetch all tickets, bundled or not.
    tickets = ticket_service.find_tickets_created_by_order(order.order_number)

    bundle_ids = {t.bundle_id for t in tickets if t.bundle_id}

    for bundle_id in bundle_ids:
        ticket_bundle_service.revoke_bundle(bundle_id, initiator_id)
        _create_order_event(order.id, bundle_id, initiator_id)


def _create_order_event(
    order_id: OrderID, bundle_id: TicketBundleID, initiator_id: UserID
) -> None:
    event_type = 'ticket-bundle-revoked'

    data = {
        'ticket_bundle_id': str(bundle_id),
        'initiator_id': str(initiator_id),
    }

    event_service.create_event(event_type, order_id, data)