~homeworkprod/byceps

ref: bcef32cd2dc329bcf81057794883008f5c040ac8 byceps/byceps/services/shop/order/action_registry_service.py -rw-r--r-- 2.2 KiB
bcef32cd — Jochen Kupperschmidt Work around Jinja 3.0.0 bug with `for` inside of `set` block 1 year, 5 days 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
byceps.services.shop.order.action_registry_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from ...ticketing.transfer.models import TicketCategoryID
from ...user_badge.transfer.models import BadgeID

from ..article.transfer.models import ArticleNumber

from .dbmodels.order_action import Parameters
from .transfer.models import PaymentState

from . import action_service


def register_badge_awarding(
    article_number: ArticleNumber, badge_id: BadgeID
) -> None:
    # Award badge to orderer when order is marked as paid.
    params_create = {
        'badge_id': str(badge_id),
    }
    action_service.create_action(
        article_number, PaymentState.paid, 'create_tickets', params_create
    )


def register_ticket_bundles_creation(
    article_number: ArticleNumber,
    ticket_category_id: TicketCategoryID,
    ticket_quantity: int,
) -> None:
    # Create ticket bundle(s) for order when it is marked as paid.
    params_create = {
        'category_id': str(ticket_category_id),
        'ticket_quantity': ticket_quantity,
    }
    action_service.create_action(
        article_number,
        PaymentState.paid,
        'create_ticket_bundles',
        params_create,
    )

    # Revoke ticket bundles that have been created for the order when it
    # is canceled after being marked as paid.
    params_revoke: Parameters = {}
    action_service.create_action(
        article_number,
        PaymentState.canceled_after_paid,
        'revoke_ticket_bundles',
        params_revoke,
    )


def register_tickets_creation(
    article_number: ArticleNumber, ticket_category_id: TicketCategoryID
) -> None:
    # Create tickets for order when it is marked as paid.
    params_create = {
        'category_id': str(ticket_category_id),
    }
    action_service.create_action(
        article_number, PaymentState.paid, 'create_tickets', params_create
    )

    # Revoke tickets that have been created for the order when it is
    # canceled after being marked as paid.
    params_revoke: Parameters = {}
    action_service.create_action(
        article_number,
        PaymentState.canceled_after_paid,
        'revoke_tickets',
        params_revoke,
    )