Пример #1
0
def test_append_checkout_details_tax_included(
    mocked_checkout_line_total,
    mocked_plugins_manager,
    dummy_payment_data,
    payment_dummy,
    checkout_ready_to_complete,
):
    # given
    net = Money(100, "USD")
    gross = Money(123, "USD")
    # tax 23 %
    mocked_checkout_line_total.return_value = quantize_price(
        TaxedMoney(net=net, gross=gross), "USD"
    )
    manager = get_plugins_manager()
    unit_price = mock.MagicMock()
    unit_price.return_value = quantize_price(TaxedMoney(net=net, gross=gross), "USD")
    manager.calculate_checkout_line_unit_price = unit_price
    mocked_plugins_manager.return_value = manager
    country_code = checkout_ready_to_complete.get_country()

    checkout_ready_to_complete.payments.add(payment_dummy)
    line = checkout_ready_to_complete.lines.first()
    payment_data = {
        "reference": "test",
    }

    # when
    result = append_checkout_details(dummy_payment_data, payment_data)

    # then

    expected_result = {
        "reference": "test",
        "shopperLocale": get_shopper_locale_value(country_code),
        "countryCode": country_code,
        "lineItems": [
            {
                "description": f"{line.variant.product.name}, {line.variant.name}",
                "quantity": line.quantity,
                "id": line.variant.sku,
                "taxAmount": price_to_minor_unit((gross - net).amount, "USD"),
                "taxPercentage": 2300,
                "amountExcludingTax": price_to_minor_unit(net.amount, "USD"),
                "amountIncludingTax": price_to_minor_unit(gross.amount, "USD"),
            },
            {
                "amountExcludingTax": "1000",
                "amountIncludingTax": "1000",
                "description": "Shipping - DHL",
                "id": f"Shipping:{checkout_ready_to_complete.shipping_method.id}",
                "quantity": 1,
                "taxAmount": "0",
                "taxPercentage": 0,
            },
        ],
    }
    assert result == expected_result
Пример #2
0
def test_append_checkout_details_without_sku(dummy_payment_data, payment_dummy,
                                             checkout_ready_to_complete):
    # given
    checkout_ready_to_complete.payments.add(payment_dummy)
    channel_id = checkout_ready_to_complete.channel_id
    line = checkout_ready_to_complete.lines.first()
    line.variant.sku = None
    line.variant.save()
    payment_data = {
        "reference": "test",
    }
    country_code = checkout_ready_to_complete.get_country()

    # when
    result = append_checkout_details(dummy_payment_data, payment_data)

    # then
    variant_channel_listing = line.variant.channel_listings.get(
        channel_id=channel_id)
    variant_price = variant_channel_listing.price_amount
    variant_currency = variant_channel_listing.currency
    price = price_to_minor_unit(variant_price, variant_currency)

    assert result == {
        "reference":
        "test",
        "shopperLocale":
        get_shopper_locale_value(country_code),
        "countryCode":
        country_code,
        "lineItems": [
            {
                "description":
                f"{line.variant.product.name}, {line.variant.name}",
                "quantity": line.quantity,
                "id": line.variant.get_global_id(),
                "taxAmount": "0",
                "taxPercentage": 0,
                "amountExcludingTax": price,
                "amountIncludingTax": price,
            },
            {
                "amountExcludingTax": "1000",
                "amountIncludingTax": "1000",
                "description": "Shipping - DHL",
                "id":
                f"Shipping:{checkout_ready_to_complete.shipping_method.id}",
                "quantity": 1,
                "taxAmount": "0",
                "taxPercentage": 0,
            },
        ],
    }