~homeworkprod/byceps

ref: a3214d27456b4060727966ca1ad520a92edaa6b2 byceps/testfixtures/shop_order.py -rw-r--r-- 1.3 KiB
a3214d27 — Jochen Kupperschmidt Make tourney avatar path depend on party path, but non-configurable besides that 2 years 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
"""
testfixtures.shop_order
~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from decimal import Decimal

from byceps.services.shop.order.models.order import Order
from byceps.services.shop.order.models.orderer import Orderer
from byceps.services.shop.order.transfer.models import PaymentMethod


ANY_ORDER_NUMBER = 'AEC-03-B00074'


def create_orderer(user):
    return Orderer(
        user.id,
        user.detail.first_names,
        user.detail.last_name,
        user.detail.country,
        user.detail.zip_code,
        user.detail.city,
        user.detail.street,
    )


def create_order(
    shop_id,
    placed_by,
    *,
    order_number=ANY_ORDER_NUMBER,
    total_amount=None,
    payment_method=PaymentMethod.bank_transfer,
    shipping_required=False,
):
    if total_amount is None:
        total_amount = Decimal('23.42')

    order = Order(
        shop_id,
        order_number,
        placed_by.id,
        placed_by.detail.first_names,
        placed_by.detail.last_name,
        placed_by.detail.country,
        placed_by.detail.zip_code,
        placed_by.detail.city,
        placed_by.detail.street,
        payment_method,
    )

    order.total_amount = total_amount
    order.shipping_required = shipping_required

    return order