Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tests for valid total 0 cases (#17191)

Anna Szczęch83efad25c081
diff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.py
index 37c07641ad..cbfceb036d 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_complete.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py
@@ -61,33 +61,41 @@ mutation CheckoutComplete($checkoutId: ID!) {
lines {
id
quantity
- unitPrice {
+ totalPrice {
gross {
amount
}
}
- unitDiscount {
- amount
+ unitPrice {
+ gross {
+ amount
+ }
}
- unitDiscountType
- unitDiscountReason
- unitDiscountValue
- undiscountedUnitPrice {
+ undiscountedTotalPrice {
gross {
amount
}
}
- totalPrice {
+ undiscountedUnitPrice {
gross {
amount
}
}
+ unitDiscount {
+ amount
+ }
+ unitDiscountType
+ unitDiscountReason
+ unitDiscountValue
}
discounts {
id
name
type
value
+ amount {
+ amount
+ }
}
voucher {
code
diff --git a/saleor/tests/e2e/checkout/utils/checkout_lines_add.py b/saleor/tests/e2e/checkout/utils/checkout_lines_add.py
index 3718b48542..4fd7d11508 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_lines_add.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_lines_add.py
@@ -23,6 +23,9 @@ mutation checkoutLinesAdd($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
undiscountedUnitPrice {
amount
}
+ undiscountedTotalPrice {
+ amount
+ }
}
availablePaymentGateways {
id
@@ -37,6 +40,15 @@ mutation checkoutLinesAdd($checkoutId: ID!, $lines: [CheckoutLineInput!]!) {
amount
}
}
+ isShippingRequired
+ availableCollectionPoints {
+ id
+ name
+ }
+ shippingMethods {
+ id
+ name
+ }
}
errors {
field
diff --git a/saleor/tests/e2e/checkout/utils/checkout_lines_update.py b/saleor/tests/e2e/checkout/utils/checkout_lines_update.py
index 60482fb44f..7a4220ea64 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_lines_update.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_lines_update.py
@@ -42,6 +42,10 @@ mutation checkoutLinesUpdate($checkoutId: ID!, $lines: [CheckoutLineUpdateInput!
}
}
}
+ shippingMethods {
+ id
+ name
+ }
}
errors {
field
diff --git a/saleor/tests/e2e/checkout/zero_total/__init__.py b/saleor/tests/e2e/checkout/zero_total/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_catalog_promotion_and_shipping_voucher.py b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_catalog_promotion_and_shipping_voucher.py
new file mode 100644
index 0000000000..c04f902322
--- /dev/null
+++ b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_catalog_promotion_and_shipping_voucher.py
@@ -0,0 +1,210 @@
+import pytest
+
+from .....product.tasks import recalculate_discounted_price_for_products_task
+from ...channel.utils import update_channel
+from ...product.utils.preparing_product import prepare_products
+from ...promotions.utils import create_promotion, create_promotion_rule
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+from ...vouchers.utils.prepare_voucher import prepare_voucher
+from ..utils import (
+ checkout_add_promo_code,
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_lines_add,
+)
+
+
+ ("mark_as_paid_strategy"),
+ [
+ ("TRANSACTION_FLOW"),
+ ("PAYMENT_FLOW"),
+ ],
+)
+def test_complete_0_total_checkout_with_catalog_promotion_and_free_shipping_voucher_CORE_0126(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_product_types_and_attributes,
+ shop_permissions,
+ permission_manage_discounts,
+ mark_as_paid_strategy,
+):
+ # Before
+ permissions = [
+ permission_manage_product_types_and_attributes,
+ *shop_permissions,
+ permission_manage_discounts,
+ ]
+
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ shop_data = prepare_default_shop(e2e_staff_api_client)
+ channel_id = shop_data["channel"]["id"]
+ channel_slug = shop_data["channel"]["slug"]
+ warehouse_id = shop_data["warehouse"]["id"]
+ update_channel(
+ e2e_staff_api_client,
+ channel_id,
+ input={"orderSettings": {"markAsPaidStrategy": mark_as_paid_strategy}},
+ )
+
+ products_data = prepare_products(
+ e2e_staff_api_client, warehouse_id, channel_id, [1.99, 120, 66.66]
+ )
+ product1_id = products_data[0]["product_id"]
+ product1_variant_id = products_data[0]["variant_id"]
+ product1_variant_price = float(products_data[0]["price"])
+
+ product2_id = products_data[1]["product_id"]
+ product2_variant_id = products_data[1]["variant_id"]
+ product2_variant_price = float(products_data[1]["price"])
+
+ product3_id = products_data[2]["product_id"]
+ product3_variant_id = products_data[2]["variant_id"]
+ product3_variant_price = float(products_data[2]["price"])
+
+ product1_quantity = 1
+ product2_quantity = 1
+ product3_quantity = 1
+
+ promotion = create_promotion(
+ e2e_staff_api_client, "Promotion PERCENTAGE", "CATALOGUE"
+ )
+ promotion_id = promotion["id"]
+ input = {
+ "promotion": promotion_id,
+ "channels": [channel_id],
+ "name": "rule for products",
+ "cataloguePredicate": {
+ "productPredicate": {"ids": [product1_id, product2_id, product3_id]}
+ },
+ "rewardValue": 100,
+ "rewardValueType": "PERCENTAGE",
+ }
+
+ create_promotion_rule(e2e_staff_api_client, input)
+
+ # prices are updated in the background, we need to force it to retrieve the correct
+ # ones
+ recalculate_discounted_price_for_products_task()
+
+ voucher_code = "FREESHIPPING"
+ prepare_voucher(
+ e2e_staff_api_client,
+ channel_id,
+ voucher_code=voucher_code,
+ voucher_discount_type="PERCENTAGE",
+ voucher_discount_value=100,
+ voucher_type="SHIPPING",
+ )
+
+ # Step 1 - Create checkout for products
+ lines = [
+ {
+ "variantId": product1_variant_id,
+ "quantity": product1_quantity,
+ },
+ {
+ "variantId": product2_variant_id,
+ "quantity": product2_quantity,
+ },
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 0
+
+ line1_total = round(product1_variant_price * product1_quantity, 2)
+ line2_total = round(product2_variant_price * product2_quantity, 2)
+ assert len(checkout_data["lines"]) == 2
+ line1 = checkout_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["amount"] == product1_variant_price
+
+ line2 = checkout_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["amount"] == product2_variant_price
+
+ # Step 2 - Add more lines
+ lines = [
+ {
+ "variantId": product3_variant_id,
+ "quantity": product3_quantity,
+ }
+ ]
+ checkout_data = checkout_lines_add(e2e_not_logged_api_client, checkout_id, lines)
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["isShippingRequired"] is True
+
+ line3_total = round(product3_variant_price * product3_quantity, 2)
+ assert len(checkout_data["lines"]) == 3
+ line3 = checkout_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedUnitPrice"]["amount"] == product3_variant_price
+ assert line3["undiscountedTotalPrice"]["amount"] == line3_total
+
+ # Step 3 - Assign delivery method
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ checkout_data["shippingMethods"][0]["id"],
+ )
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 10
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["shippingPrice"]["gross"]["amount"] == 10
+
+ # Step 4 - Add free shipping voucher code to checkout
+ checkout_data = checkout_add_promo_code(
+ e2e_not_logged_api_client,
+ checkout_id,
+ voucher_code,
+ )
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["shippingPrice"]["gross"]["amount"] == 0
+
+ # Step 5 - Complete checkout and verify created order
+ order_data = checkout_complete(
+ e2e_not_logged_api_client,
+ checkout_id,
+ )
+ assert order_data["status"] == "UNCONFIRMED"
+ assert order_data["total"]["gross"]["amount"] == 0
+ assert order_data["subtotal"]["gross"]["amount"] == 0
+ assert order_data["shippingPrice"]["gross"]["amount"] == 0
+
+ assert len(order_data["lines"]) == 3
+ line1 = order_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
+
+ line3 = order_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedTotalPrice"]["gross"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["gross"]["amount"] == product3_variant_price
diff --git a/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_line_voucher_and_click_and_collect.py b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_line_voucher_and_click_and_collect.py
new file mode 100644
index 0000000000..ebe1819c03
--- /dev/null
+++ b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_line_voucher_and_click_and_collect.py
@@ -0,0 +1,218 @@
+import pytest
+
+from ...channel.utils import update_channel
+from ...product.utils.preparing_product import prepare_products
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+from ...vouchers.utils.prepare_voucher import prepare_voucher
+from ...warehouse.utils import update_warehouse
+from ..utils import (
+ checkout_add_promo_code,
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_lines_add,
+)
+
+
+ ("mark_as_paid_strategy"),
+ [
+ ("TRANSACTION_FLOW"),
+ ("PAYMENT_FLOW"),
+ ],
+)
+def test_complete_0_total_checkout_with_lines_voucher_and_click_and_collect_CORE_0125(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_product_types_and_attributes,
+ shop_permissions,
+ permission_manage_discounts,
+ mark_as_paid_strategy,
+):
+ # Before
+ permissions = [
+ permission_manage_product_types_and_attributes,
+ *shop_permissions,
+ permission_manage_discounts,
+ ]
+
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ shop_data = prepare_default_shop(e2e_staff_api_client)
+ channel_id = shop_data["channel"]["id"]
+ channel_slug = shop_data["channel"]["slug"]
+ warehouse_id = shop_data["warehouse"]["id"]
+ update_warehouse(
+ e2e_staff_api_client,
+ warehouse_id,
+ is_private=False,
+ click_and_collect_option="LOCAL",
+ )
+ update_channel(
+ e2e_staff_api_client,
+ channel_id,
+ input={"orderSettings": {"markAsPaidStrategy": mark_as_paid_strategy}},
+ )
+ products_data = prepare_products(
+ e2e_staff_api_client, warehouse_id, channel_id, [9.99, 150, 77.77]
+ )
+ product1_id = products_data[0]["product_id"]
+ product1_variant_id = products_data[0]["variant_id"]
+ product1_variant_price = float(products_data[0]["price"])
+
+ product2_id = products_data[1]["product_id"]
+ product2_variant_id = products_data[1]["variant_id"]
+ product2_variant_price = float(products_data[1]["price"])
+
+ product3_id = products_data[2]["product_id"]
+ product3_variant_id = products_data[2]["variant_id"]
+ product3_variant_price = float(products_data[2]["price"])
+
+ product1_quantity = 1
+ product2_quantity = 4
+ product3_quantity = 2
+
+ voucher_code, _voucher_id, _voucher_discount_value = prepare_voucher(
+ e2e_staff_api_client,
+ channel_id,
+ voucher_code="voucher_qwerty",
+ voucher_discount_type="PERCENTAGE",
+ voucher_discount_value=100,
+ voucher_type="SPECIFIC_PRODUCT",
+ products_list=[product1_id, product2_id, product3_id],
+ apply_once_per_order=False,
+ )
+ # Step 1 - Create checkout for products
+ lines = [
+ {
+ "variantId": product1_variant_id,
+ "quantity": product1_quantity,
+ },
+ {
+ "variantId": product2_variant_id,
+ "quantity": product2_quantity,
+ },
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+ line1_total = round(product1_variant_price * product1_quantity, 2)
+ line2_total = round(product2_variant_price * product2_quantity, 2)
+ calculated_subtotal = round(line1_total + line2_total, 2)
+
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+ line1 = checkout_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == product1_variant_price
+ assert line1["totalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedTotalPrice"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["amount"] == product1_variant_price
+
+ line2 = checkout_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == product2_variant_price
+ assert line2["totalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedTotalPrice"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["amount"] == product2_variant_price
+
+ # Step 2 - Add more lines
+ lines = [
+ {
+ "variantId": product3_variant_id,
+ "quantity": product3_quantity,
+ }
+ ]
+ checkout_data = checkout_lines_add(e2e_not_logged_api_client, checkout_id, lines)
+ assert checkout_data["isShippingRequired"] is True
+ line3_total = round(product3_variant_price * product3_quantity, 2)
+ calculated_subtotal = round(line1_total + line2_total + line3_total, 2)
+
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+
+ collection_point = checkout_data["availableCollectionPoints"][0]
+ assert collection_point["id"] == warehouse_id
+
+ line3 = checkout_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == product3_variant_price
+ assert line3["totalPrice"]["gross"]["amount"] == line3_total
+ assert line3["undiscountedTotalPrice"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["amount"] == product3_variant_price
+
+ # Step 3 - Assign delivery method
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ collection_point["id"],
+ )
+ assert checkout_data["deliveryMethod"]["id"] == warehouse_id
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["shippingPrice"]["gross"]["amount"] == 0
+
+ # Step 4 - Add voucher code to the checkout
+ data = checkout_add_promo_code(
+ e2e_not_logged_api_client,
+ checkout_id,
+ voucher_code,
+ )
+ assert data["voucherCode"] == voucher_code
+ assert data["totalPrice"]["gross"]["amount"] == 0
+ assert data["subtotalPrice"]["gross"]["amount"] == 0
+ assert data["shippingPrice"]["gross"]["amount"] == 0
+
+ assert len(data["lines"]) == 3
+ line1 = data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["amount"] == product1_variant_price
+
+ line2 = data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["amount"] == product2_variant_price
+
+ line3 = data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedTotalPrice"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["amount"] == product3_variant_price
+
+ # Step 5 - Complete checkout and verify created order
+ order_data = checkout_complete(
+ e2e_not_logged_api_client,
+ checkout_id,
+ )
+ assert order_data["status"] == "UNCONFIRMED"
+ assert order_data["deliveryMethod"]["id"] == warehouse_id
+ assert order_data["total"]["gross"]["amount"] == 0
+ assert order_data["subtotal"]["gross"]["amount"] == 0
+ assert order_data["shippingPrice"]["gross"]["amount"] == 0
+
+ assert len(order_data["lines"]) == 3
+ line1 = order_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
+
+ line3 = order_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedTotalPrice"]["gross"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["gross"]["amount"] == product3_variant_price
diff --git a/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_with_order_promotion_and_free_shipping.py b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_with_order_promotion_and_free_shipping.py
new file mode 100644
index 0000000000..1f3b668d10
--- /dev/null
+++ b/saleor/tests/e2e/checkout/zero_total/test_0_total_checkout_with_order_promotion_and_free_shipping.py
@@ -0,0 +1,259 @@
+import pytest
+
+from ...product.utils.preparing_product import prepare_products
+from ...promotions.utils import create_promotion
+from ...shop.utils.preparing_shop import prepare_shop
+from ...utils import assign_permissions
+from ..utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_lines_add,
+ checkout_lines_update,
+)
+
+
+ ("mark_as_paid_strategy"),
+ [
+ ("TRANSACTION_FLOW"),
+ ("PAYMENT_FLOW"),
+ ],
+)
+def test_complete_0_total_checkout_with_order_promotion_and_free_shipping_method_CORE_0124(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_product_types_and_attributes,
+ shop_permissions,
+ permission_manage_discounts,
+ mark_as_paid_strategy,
+):
+ # Before
+ permissions = [
+ permission_manage_product_types_and_attributes,
+ *shop_permissions,
+ permission_manage_discounts,
+ ]
+
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ fedex_price = 0
+ shop_data, _tax_config = prepare_shop(
+ e2e_staff_api_client,
+ channels=[
+ {
+ "shipping_zones": [
+ {
+ "countries": ["US"],
+ "shipping_methods": [
+ {
+ "name": "FEDEX",
+ "add_channels": {
+ "price": fedex_price,
+ },
+ }
+ ],
+ }
+ ],
+ "order_settings": {
+ "markAsPaidStrategy": mark_as_paid_strategy,
+ },
+ }
+ ],
+ )
+ channel_id = shop_data[0]["id"]
+ channel_slug = shop_data[0]["slug"]
+ shipping_method_id = shop_data[0]["shipping_zones"][0]["shipping_methods"][0]["id"]
+ warehouse_id = shop_data[0]["warehouse_id"]
+
+ products_data = prepare_products(
+ e2e_staff_api_client, warehouse_id, channel_id, [9.99, 150, 77.77]
+ )
+ product1_variant_id = products_data[0]["variant_id"]
+ product1_variant_price = float(products_data[0]["price"])
+
+ product2_variant_id = products_data[1]["variant_id"]
+ product2_variant_price = float(products_data[1]["price"])
+
+ product3_variant_id = products_data[2]["variant_id"]
+ product3_variant_price = float(products_data[2]["price"])
+
+ product1_quantity = 1
+ product2_quantity = 1
+ product3_quantity = 1
+
+ new_product1_quantity = 3
+ new_product2_quantity = 3
+ new_product3_quantity = 3
+
+ rule_input = {
+ "name": "subtotal rule",
+ "orderPredicate": {
+ "discountedObjectPredicate": {"baseSubtotalPrice": {"range": {"gte": 500}}}
+ },
+ "rewardValue": 100,
+ "rewardValueType": "PERCENTAGE",
+ "rewardType": "SUBTOTAL_DISCOUNT",
+ "channels": [channel_id],
+ }
+
+ create_promotion(
+ e2e_staff_api_client,
+ "Order promotion",
+ "ORDER",
+ rules=[rule_input],
+ )
+
+ # Step 1 - Create checkout for products
+ lines = [
+ {
+ "variantId": product1_variant_id,
+ "quantity": product1_quantity,
+ },
+ {
+ "variantId": product2_variant_id,
+ "quantity": product2_quantity,
+ },
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+ line1_total = round(product1_variant_price * product1_quantity, 2)
+ line2_total = round(product2_variant_price * product2_quantity, 2)
+ calculated_subtotal = round(line1_total + line2_total, 2)
+
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+
+ line1 = checkout_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == product1_variant_price
+ assert line1["totalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedTotalPrice"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["amount"] == product1_variant_price
+
+ line2 = checkout_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == product2_variant_price
+ assert line2["totalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedTotalPrice"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["amount"] == product2_variant_price
+
+ # Step 2 - Add more lines
+ lines = [
+ {
+ "variantId": product3_variant_id,
+ "quantity": product3_quantity,
+ }
+ ]
+ checkout_data = checkout_lines_add(e2e_not_logged_api_client, checkout_id, lines)
+ line3_total = round(product3_variant_price * product3_quantity, 2)
+ calculated_subtotal = round(line1_total + line2_total + line3_total, 2)
+
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["isShippingRequired"] is True
+
+ line3 = checkout_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == product3_variant_price
+ assert line3["totalPrice"]["gross"]["amount"] == line3_total
+ assert line3["undiscountedTotalPrice"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["amount"] == product3_variant_price
+
+ # Step 3 - Update lines to apply promotion
+ lines = [
+ {
+ "quantity": new_product1_quantity,
+ "variantId": product1_variant_id,
+ },
+ {
+ "quantity": new_product2_quantity,
+ "variantId": product2_variant_id,
+ },
+ {
+ "quantity": new_product3_quantity,
+ "variantId": product3_variant_id,
+ },
+ ]
+ checkout_data = checkout_lines_update(e2e_not_logged_api_client, checkout_id, lines)
+ line1_total = round(product1_variant_price * new_product1_quantity, 2)
+ line2_total = round(product2_variant_price * new_product2_quantity, 2)
+ line3_total = round(product3_variant_price * new_product3_quantity, 2)
+ calculated_subtotal_before_promo = round(line1_total + line2_total + line3_total, 2)
+
+ checkout_data = checkout_data["checkout"]
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["discount"]["amount"] == calculated_subtotal_before_promo
+
+ assert len(checkout_data["shippingMethods"]) == 1
+ assert checkout_data["shippingMethods"][0]["id"] == shipping_method_id
+
+ line1 = checkout_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["amount"] == product1_variant_price
+
+ line2 = checkout_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["amount"] == product2_variant_price
+
+ line3 = checkout_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedTotalPrice"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["amount"] == product3_variant_price
+
+ # Step 3 - Assign delivery method
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ checkout_data["shippingMethods"][0]["id"],
+ )
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+ assert checkout_data["totalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == 0
+ assert checkout_data["shippingPrice"]["gross"]["amount"] == 0
+
+ # Step 4 - Complete checkout and verify created order
+ order_data = checkout_complete(
+ e2e_not_logged_api_client,
+ checkout_id,
+ )
+ assert order_data["status"] == "UNCONFIRMED"
+ assert order_data["deliveryMethod"]["id"] == shipping_method_id
+ assert order_data["total"]["gross"]["amount"] == 0
+ assert order_data["subtotal"]["gross"]["amount"] == 0
+ assert order_data["shippingPrice"]["gross"]["amount"] == 0
+ assert (
+ order_data["discounts"][0]["amount"]["amount"]
+ == calculated_subtotal_before_promo
+ )
+
+ assert len(order_data["lines"]) == 3
+ assert len(order_data["lines"]) == 3
+ line1 = order_data["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order_data["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
+
+ line3 = order_data["lines"][2]
+ assert line3["unitPrice"]["gross"]["amount"] == 0
+ assert line3["totalPrice"]["gross"]["amount"] == 0
+ assert line3["undiscountedTotalPrice"]["gross"]["amount"] == line3_total
+ assert line3["undiscountedUnitPrice"]["gross"]["amount"] == product3_variant_price
diff --git a/saleor/tests/e2e/checkout/test_pay_for_total_checkout_with_gift_card.py b/saleor/tests/e2e/checkout/zero_total/test_pay_for_total_checkout_with_gift_card.py
similarity index 51%
rename from saleor/tests/e2e/checkout/test_pay_for_total_checkout_with_gift_card.py
rename to saleor/tests/e2e/checkout/zero_total/test_pay_for_total_checkout_with_gift_card.py
index 0475aa0703..df68ead987 100644
--- a/saleor/tests/e2e/checkout/test_pay_for_total_checkout_with_gift_card.py
+++ b/saleor/tests/e2e/checkout/zero_total/test_pay_for_total_checkout_with_gift_card.py
@@ -1,25 +1,34 @@
import pytest
-from ..gift_cards.utils import create_gift_card
-from ..product.utils.preparing_product import prepare_product
-from ..shop.utils.preparing_shop import prepare_default_shop
-from ..utils import assign_permissions
-from .utils import (
+from ...channel.utils import update_channel
+from ...gift_cards.utils import create_gift_card
+from ...product.utils.preparing_product import prepare_products
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+from ..utils import (
checkout_add_promo_code,
checkout_complete,
checkout_create,
checkout_delivery_method_update,
- raw_checkout_dummy_payment_create,
+ checkout_lines_add,
)
@pytest.mark.e2e
+ ("mark_as_paid_strategy"),
+ [
+ ("TRANSACTION_FLOW"),
+ ("PAYMENT_FLOW"),
+ ],
+)
def test_gift_card_total_payment_for_checkout_core_1101(
e2e_logged_api_client,
e2e_staff_api_client,
shop_permissions,
permission_manage_product_types_and_attributes,
permission_manage_gift_card,
+ mark_as_paid_strategy,
):
# Before
permissions = [
@@ -34,26 +43,41 @@ def test_gift_card_total_payment_for_checkout_core_1101(
channel_slug = shop_data["channel"]["slug"]
warehouse_id = shop_data["warehouse"]["id"]
shipping_method_id = shop_data["shipping_method"]["id"]
-
- (
- _product_id,
- product_variant_id,
- product_variant_price,
- ) = prepare_product(
+ update_channel(
e2e_staff_api_client,
- warehouse_id,
channel_id,
- variant_price=24.99,
+ input={"orderSettings": {"markAsPaidStrategy": mark_as_paid_strategy}},
)
+
+ products_data = prepare_products(
+ e2e_staff_api_client, warehouse_id, channel_id, [24.99, 5, 16]
+ )
+ product1_variant_id = products_data[0]["variant_id"]
+ product1_variant_price = float(products_data[0]["price"])
+
+ product2_variant_id = products_data[1]["variant_id"]
+ product2_variant_price = float(products_data[1]["price"])
+
+ product3_variant_id = products_data[2]["variant_id"]
+ product3_variant_price = float(products_data[2]["price"])
+
+ product1_quantity = 1
+ product2_quantity = 4
+ product3_quantity = 2
+
gift_card = create_gift_card(e2e_staff_api_client, 100, "USD", active=True)
gift_card_code = gift_card["code"]
gift_card_id = gift_card["id"]
- # Step 1 - Create checkout for product
+ # Step 1 - Create checkout for products
lines = [
{
- "variantId": product_variant_id,
- "quantity": 3,
+ "variantId": product1_variant_id,
+ "quantity": product1_quantity,
+ },
+ {
+ "variantId": product2_variant_id,
+ "quantity": product2_quantity,
},
]
checkout_data = checkout_create(
@@ -65,12 +89,33 @@ def test_gift_card_total_payment_for_checkout_core_1101(
set_default_shipping_address=True,
)
checkout_id = checkout_data["id"]
+ calculated_subtotal = round(
+ product1_variant_price * product1_quantity
+ + product2_variant_price * product2_quantity,
+ 2,
+ )
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
+
+ # Step 2 - Add more lines
+ lines = [
+ {
+ "variantId": product3_variant_id,
+ "quantity": product3_quantity,
+ }
+ ]
+ checkout_data = checkout_lines_add(e2e_logged_api_client, checkout_id, lines)
assert checkout_data["isShippingRequired"] is True
- assert checkout_data["totalPrice"]["gross"]["amount"] == float(
- product_variant_price * 3
+ calculated_subtotal = round(
+ product1_variant_price * product1_quantity
+ + product2_variant_price * product2_quantity
+ + product3_variant_price * product3_quantity,
+ 2,
)
+ assert checkout_data["subtotalPrice"]["gross"]["amount"] == calculated_subtotal
+ assert checkout_data["totalPrice"]["gross"]["amount"] == calculated_subtotal
- # Step 2 - Set DeliveryMethod for checkout.
+ # Step 3 - Set DeliveryMethod for checkout.
checkout_data = checkout_delivery_method_update(
e2e_logged_api_client,
checkout_id,
@@ -80,9 +125,9 @@ def test_gift_card_total_payment_for_checkout_core_1101(
total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
shipping_price = checkout_data["deliveryMethod"]["price"]["amount"]
assert shipping_price == 10
- assert total_gross_amount == float(product_variant_price * 3) + shipping_price
+ assert total_gross_amount == calculated_subtotal + shipping_price
- # Step 3 Add gift card to checkout
+ # Step 4 Add gift card to checkout
checkout_data = checkout_add_promo_code(
e2e_logged_api_client,
checkout_id,
@@ -93,16 +138,6 @@ def test_gift_card_total_payment_for_checkout_core_1101(
assert checkout_data["giftCards"][0]["id"] == gift_card_id
assert checkout_data["giftCards"][0]["last4CodeChars"] == gift_card_code[-4:]
- # Step 4 - Create payment for checkout.
- create_payment = raw_checkout_dummy_payment_create(
- e2e_logged_api_client,
- checkout_id,
- total_gross_amount,
- token="fully_charged",
- )
- assert create_payment["errors"] == []
- assert create_payment["checkout"]["id"] == checkout_id
-
# Step 5 - Complete checkout.
order_data = checkout_complete(
e2e_logged_api_client,
diff --git a/saleor/tests/e2e/orders/utils/__init__.py b/saleor/tests/e2e/orders/utils/__init__.py
index 7c4d3d4426..73e8832a77 100644
--- a/saleor/tests/e2e/orders/utils/__init__.py
+++ b/saleor/tests/e2e/orders/utils/__init__.py
@@ -15,6 +15,7 @@ from .order_fulfill_add_tracking import order_add_tracking
from .order_fulfillment_cancel import order_fulfillment_cancel
from .order_invoice_create import order_invoice_create
from .order_line_delete import order_line_delete
+from .order_line_discount_update import order_line_discount_update
from .order_line_update import order_line_update
from .order_lines_create import order_lines_create
from .order_mark_as_paid import mark_order_paid
@@ -45,5 +46,6 @@ __all__ = [
"draft_order_bulk_delete",
"order_line_update",
"order_line_delete",
+ "order_line_discount_update",
"raw_order_create_from_checkout",
]
diff --git a/saleor/tests/e2e/orders/utils/order_discount_add.py b/saleor/tests/e2e/orders/utils/order_discount_add.py
index 99d85b6bdb..0908ecb42a 100644
--- a/saleor/tests/e2e/orders/utils/order_discount_add.py
+++ b/saleor/tests/e2e/orders/utils/order_discount_add.py
@@ -47,6 +47,12 @@ mutation OrderDiscountAdd($input: OrderDiscountCommonInput!, $id: ID!) {
...BaseTaxedMoney
}
unitDiscountReason
+ undiscountedUnitPrice {
+ ...BaseTaxedMoney
+ }
+ undiscountedTotalPrice {
+ ...BaseTaxedMoney
+ }
}
voucherCode
voucher {
@@ -54,16 +60,16 @@ mutation OrderDiscountAdd($input: OrderDiscountCommonInput!, $id: ID!) {
code
discountValue
codes(first: 10) {
- edges {
- node {
- id
- code
- isActive
- used
- }
+ edges {
+ node {
+ id
+ code
+ isActive
+ used
}
- totalCount
}
+ totalCount
+ }
}
}
}
diff --git a/saleor/tests/e2e/orders/utils/order_lines_create.py b/saleor/tests/e2e/orders/utils/order_lines_create.py
index cd7f881157..a9f3d4dc07 100644
--- a/saleor/tests/e2e/orders/utils/order_lines_create.py
+++ b/saleor/tests/e2e/orders/utils/order_lines_create.py
@@ -47,6 +47,11 @@ mutation orderLinesCreate($id: ID!, $input: [OrderLineCreateInput!]!) {
amount
}
}
+ undiscountedTotalPrice {
+ gross {
+ amount
+ }
+ }
}
discounts {
id
diff --git a/saleor/tests/e2e/orders/zero_total/__init__.py b/saleor/tests/e2e/orders/zero_total/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/orders/zero_total/test_0_total_order_for_lines_with_price_0.py b/saleor/tests/e2e/orders/zero_total/test_0_total_order_for_lines_with_price_0.py
new file mode 100644
index 0000000000..49e463d8f5
--- /dev/null
+++ b/saleor/tests/e2e/orders/zero_total/test_0_total_order_for_lines_with_price_0.py
@@ -0,0 +1,91 @@
+import pytest
+
+from ... import DEFAULT_ADDRESS
+from ...orders.utils import (
+ draft_order_complete,
+ draft_order_create,
+ draft_order_update,
+ order_lines_create,
+)
+from ...product.utils.preparing_product import prepare_digital_product
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+
+
+def test_complete_draft_order_with_0_price_lines_CORE_0244(
+ e2e_staff_api_client,
+ shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+):
+ # Before
+ permissions = [
+ *shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ shop_data = prepare_default_shop(e2e_staff_api_client)
+ channel_id = shop_data["channel"]["id"]
+ warehouse_id = shop_data["warehouse"]["id"]
+
+ _product_id, product_variant_id, _product_variant_price = prepare_digital_product(
+ e2e_staff_api_client, channel_id, warehouse_id, 0
+ )
+ variant_quantity = 1
+
+ # Step 1 - Create draft order
+ draft_order_input = {
+ "channelId": channel_id,
+ }
+ data = draft_order_create(
+ e2e_staff_api_client,
+ draft_order_input,
+ )
+ order_id = data["order"]["id"]
+ assert order_id is not None
+
+ # Step 2 - Add lines to the order
+ lines = [
+ {
+ "variantId": product_variant_id,
+ "quantity": variant_quantity,
+ }
+ ]
+ order_data = order_lines_create(
+ e2e_staff_api_client,
+ order_id,
+ lines,
+ )
+ order_product_variant_id = order_data["order"]["lines"][0]["variant"]["id"]
+ assert order_product_variant_id == product_variant_id
+ assert order_data["order"]["total"]["gross"]["amount"] == 0
+ assert order_data["order"]["lines"][0]["totalPrice"]["gross"]["amount"] == 0
+
+ # Step 3 - Update order's addresses and email
+ input = {
+ "userEmail": "[email protected]",
+ "shippingAddress": DEFAULT_ADDRESS,
+ "billingAddress": DEFAULT_ADDRESS,
+ }
+ draft_order = draft_order_update(
+ e2e_staff_api_client,
+ order_id,
+ input,
+ )
+ assert draft_order["order"]["userEmail"] == "[email protected]"
+ assert draft_order["order"]["shippingAddress"] is not None
+ assert draft_order["order"]["billingAddress"] is not None
+ assert draft_order["order"]["isShippingRequired"] is False
+
+ # Step 4 - Complete the order and check it's status
+ order = draft_order_complete(
+ e2e_staff_api_client,
+ order_id,
+ )
+ assert order["order"]["status"] == "UNFULFILLED"
+ assert order["order"]["total"]["gross"]["amount"] == 0
+ assert order["order"]["lines"][0]["totalPrice"]["gross"]["amount"] == 0
+ assert order["order"]["lines"][0]["undiscountedTotalPrice"]["gross"]["amount"] == 0
diff --git a/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_100_percent_manual_discount.py b/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_100_percent_manual_discount.py
new file mode 100644
index 0000000000..58f112775d
--- /dev/null
+++ b/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_100_percent_manual_discount.py
@@ -0,0 +1,185 @@
+import pytest
+
+from ... import DEFAULT_ADDRESS
+from ...orders.utils import (
+ draft_order_complete,
+ draft_order_create,
+ draft_order_update,
+ order_discount_add,
+ order_lines_create,
+)
+from ...product.utils.preparing_product import prepare_products
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+
+
+def test_complete_draft_order_with_0_total_100_percent_manual_total_discount_CORE_0252(
+ e2e_staff_api_client,
+ shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+):
+ # Before
+ permissions = [
+ *shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ shop_data = prepare_default_shop(e2e_staff_api_client)
+ channel_id = shop_data["channel"]["id"]
+ warehouse_id = shop_data["warehouse"]["id"]
+ shipping_method_id = shop_data["shipping_method"]["id"]
+
+ shipping_price = 10
+
+ products_data = prepare_products(
+ e2e_staff_api_client, warehouse_id, channel_id, [103, 9.99]
+ )
+ product1_variant_id = products_data[0]["variant_id"]
+ product1_variant_price = float(products_data[0]["price"])
+
+ product2_variant_id = products_data[1]["variant_id"]
+ product2_variant_price = float(products_data[1]["price"])
+
+ variant1_quantity = 2
+ variant2_quantity = 1
+
+ # Step 1 - Create draft order
+ draft_order_input = {
+ "channelId": channel_id,
+ }
+ data = draft_order_create(
+ e2e_staff_api_client,
+ draft_order_input,
+ )
+ order_id = data["order"]["id"]
+ assert order_id is not None
+
+ # Step 2 - Add lines to the order
+ lines = [
+ {
+ "variantId": product1_variant_id,
+ "quantity": variant1_quantity,
+ },
+ {
+ "variantId": product2_variant_id,
+ "quantity": variant2_quantity,
+ },
+ ]
+ order_data = order_lines_create(
+ e2e_staff_api_client,
+ order_id,
+ lines,
+ )
+ assert len(order_data["order"]["lines"]) == 2
+ line1_total = round(product1_variant_price * variant1_quantity, 2)
+ line2_total = round(product2_variant_price * variant2_quantity, 2)
+
+ line1 = order_data["order"]["lines"][0]
+ assert line1["totalPrice"]["gross"]["amount"] == line1_total
+ assert line1["unitPrice"]["gross"]["amount"] == product1_variant_price
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order_data["order"]["lines"][1]
+ assert line2["totalPrice"]["gross"]["amount"] == line2_total
+ assert line2["unitPrice"]["gross"]["amount"] == product2_variant_price
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
+
+ calculated_subtotal = line1_total + line2_total
+ assert order_data["order"]["subtotal"]["gross"]["amount"] == calculated_subtotal
+ assert order_data["order"]["total"]["gross"]["amount"] == calculated_subtotal
+
+ # Step 3 - Update order's addresses and email
+ input = {
+ "userEmail": "[email protected]",
+ "shippingAddress": DEFAULT_ADDRESS,
+ "billingAddress": DEFAULT_ADDRESS,
+ }
+ draft_order = draft_order_update(
+ e2e_staff_api_client,
+ order_id,
+ input,
+ )
+
+ assert draft_order["order"]["userEmail"] == "[email protected]"
+ assert draft_order["order"]["shippingAddress"] is not None
+ assert draft_order["order"]["billingAddress"] is not None
+ assert draft_order["order"]["isShippingRequired"] is True
+ assert draft_order["order"]["total"]["gross"]["amount"] == calculated_subtotal
+ assert draft_order["order"]["subtotal"]["gross"]["amount"] == calculated_subtotal
+
+ # Step 4 - Update shipping method
+ shipping_method_id = shop_data["shipping_method"]["id"]
+ draft_order = draft_order_update(
+ e2e_staff_api_client,
+ order_id,
+ {"shippingMethod": shipping_method_id},
+ )
+ assert draft_order["order"]["shippingPrice"]["gross"]["amount"] == shipping_price
+ calculated_total = calculated_subtotal + shipping_price
+ assert draft_order["order"]["total"]["gross"]["amount"] == calculated_total
+ assert draft_order["order"]["subtotal"]["gross"]["amount"] == calculated_subtotal
+
+ # Step 5 - Add manual discount to the order
+ manual_discount_input = {
+ "valueType": "PERCENTAGE",
+ "value": 100,
+ }
+ order_data = order_discount_add(
+ e2e_staff_api_client,
+ order_id,
+ manual_discount_input,
+ )
+ assert order_data["order"]["total"]["gross"]["amount"] == 0
+ assert order_data["order"]["subtotal"]["gross"]["amount"] == 0
+ assert order_data["order"]["shippingPrice"]["gross"]["amount"] == 0
+ assert order_data["order"]["undiscountedShippingPrice"]["amount"] == shipping_price
+ # Bug SHOPX-1390 - uncoment below line when fixed
+ # assert (
+ # order_data["order"]["undiscountedTotal"]["gross"]["amount"] == calculated_total
+ # )
+ assert order_data["order"]["discounts"][0]["amount"]["amount"] == calculated_total
+
+ line1 = order_data["order"]["lines"][0]
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order_data["order"]["lines"][1]
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
+
+ # Step 6 - Complete the order and check it's status
+ order = draft_order_complete(
+ e2e_staff_api_client,
+ order_id,
+ )
+ assert order["order"]["status"] == "UNFULFILLED"
+ assert order["order"]["total"]["gross"]["amount"] == 0
+ assert order["order"]["subtotal"]["gross"]["amount"] == 0
+ assert order["order"]["discounts"][0]["amount"]["amount"] == calculated_total
+ assert order["order"]["shippingPrice"]["gross"]["amount"] == 0
+ assert order["order"]["undiscountedShippingPrice"]["amount"] == shipping_price
+ # Bug SHOPX-1390 - uncoment below line when fixed
+ # assert order["order"]["undiscountedTotal"]["gross"]["amount"] == calculated_total
+
+ assert len(order["order"]["lines"]) == 2
+ line1 = order["order"]["lines"][0]
+ assert line1["unitPrice"]["gross"]["amount"] == 0
+ assert line1["totalPrice"]["gross"]["amount"] == 0
+ assert line1["undiscountedTotalPrice"]["gross"]["amount"] == line1_total
+ assert line1["undiscountedUnitPrice"]["gross"]["amount"] == product1_variant_price
+
+ line2 = order["order"]["lines"][1]
+ assert line2["unitPrice"]["gross"]["amount"] == 0
+ assert line2["totalPrice"]["gross"]["amount"] == 0
+ assert line2["undiscountedTotalPrice"]["gross"]["amount"] == line2_total
+ assert line2["undiscountedUnitPrice"]["gross"]["amount"] == product2_variant_price
diff --git a/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_manual_discount_for_digital_product.py b/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_manual_discount_for_digital_product.py
new file mode 100644
index 0000000000..1ba08e7eb2
--- /dev/null
+++ b/saleor/tests/e2e/orders/zero_total/test_0_total_order_with_manual_discount_for_digital_product.py
@@ -0,0 +1,124 @@
+import pytest
+
+from ... import DEFAULT_ADDRESS
+from ...orders.utils import (
+ draft_order_complete,
+ draft_order_create,
+ draft_order_update,
+ order_line_discount_update,
+ order_lines_create,
+)
+from ...product.utils.preparing_product import prepare_digital_product
+from ...shop.utils.preparing_shop import prepare_default_shop
+from ...utils import assign_permissions
+
+
+def test_complete_draft_order_with_0_total_manual_discount_for_digital_products_CORE_0239(
+ e2e_staff_api_client,
+ shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+):
+ # Before
+ permissions = [
+ *shop_permissions,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ shop_data = prepare_default_shop(e2e_staff_api_client)
+ channel_id = shop_data["channel"]["id"]
+ warehouse_id = shop_data["warehouse"]["id"]
+
+ _product_id, product_variant_id, product_variant_price = prepare_digital_product(
+ e2e_staff_api_client, channel_id, warehouse_id, 200
+ )
+ variant_quantity = 1
+
+ # Step 1 - Create draft order
+ draft_order_input = {
+ "channelId": channel_id,
+ }
+ data = draft_order_create(
+ e2e_staff_api_client,
+ draft_order_input,
+ )
+ order_id = data["order"]["id"]
+ assert order_id is not None
+
+ # Step 2 - Add lines to the order
+ lines = [
+ {
+ "variantId": product_variant_id,
+ "quantity": variant_quantity,
+ }
+ ]
+ order_data = order_lines_create(
+ e2e_staff_api_client,
+ order_id,
+ lines,
+ )
+ order_product_variant_id = order_data["order"]["lines"][0]["variant"]["id"]
+ assert order_product_variant_id == product_variant_id
+ assert order_data["order"]["total"]["gross"]["amount"] == product_variant_price
+
+ order_line = order_data["order"]["lines"][0]
+ line_total = round(product_variant_price * variant_quantity, 2)
+ assert order_line["totalPrice"]["gross"]["amount"] == product_variant_price
+ assert order_line["undiscountedTotalPrice"]["gross"]["amount"] == line_total
+ assert order_line["unitPrice"]["gross"]["amount"] == product_variant_price
+ assert order_line["undiscountedTotalPrice"]["gross"]["amount"] == line_total
+
+ # Step 3 - Update order's addresses and email
+ input = {
+ "userEmail": "[email protected]",
+ "shippingAddress": DEFAULT_ADDRESS,
+ "billingAddress": DEFAULT_ADDRESS,
+ }
+ draft_order = draft_order_update(
+ e2e_staff_api_client,
+ order_id,
+ input,
+ )
+ assert draft_order["order"]["userEmail"] == "[email protected]"
+ assert draft_order["order"]["shippingAddress"] is not None
+ assert draft_order["order"]["billingAddress"] is not None
+ assert draft_order["order"]["isShippingRequired"] is False
+
+ # Step 4 - Add manual discount to the order line
+ manual_discount_value = product_variant_price
+ manual_discount_reason = "Manual discount reason"
+ manual_line_discount_input = {
+ "valueType": "FIXED",
+ "value": manual_discount_value,
+ "reason": manual_discount_reason,
+ }
+ order_data = order_line_discount_update(
+ e2e_staff_api_client, order_line["id"], manual_line_discount_input
+ )
+ assert order_data["order"]["total"]["gross"]["amount"] == 0
+ assert order_data["order"]["subtotal"]["gross"]["amount"] == 0
+ order_line = order_data["order"]["lines"][0]
+ assert order_line["totalPrice"]["gross"]["amount"] == 0
+ assert order_line["undiscountedTotalPrice"]["gross"]["amount"] == line_total
+ assert order_line["unitPrice"]["gross"]["amount"] == 0
+ assert (
+ order_line["undiscountedUnitPrice"]["gross"]["amount"] == product_variant_price
+ )
+
+ # Step 5 - Complete the order and check it's status
+ order = draft_order_complete(
+ e2e_staff_api_client,
+ order_id,
+ )
+ assert order["order"]["status"] == "UNFULFILLED"
+ assert order["order"]["total"]["gross"]["amount"] == 0
+ order_line = order["order"]["lines"][0]
+ assert order_line["totalPrice"]["gross"]["amount"] == 0
+ assert order_line["undiscountedTotalPrice"]["gross"]["amount"] == line_total
+ assert order_line["unitPrice"]["gross"]["amount"] == 0
+ assert (
+ order_line["undiscountedUnitPrice"]["gross"]["amount"] == product_variant_price
+ )
diff --git a/saleor/tests/e2e/product/utils/preparing_product.py b/saleor/tests/e2e/product/utils/preparing_product.py
index 402fd58a79..ba9932c701 100644
--- a/saleor/tests/e2e/product/utils/preparing_product.py
+++ b/saleor/tests/e2e/product/utils/preparing_product.py
@@ -15,10 +15,12 @@ def prepare_product(
channel_id,
variant_price,
product_type_slug="default",
+ is_shipping_required=True,
):
product_type_data = create_product_type(
e2e_staff_api_client,
slug=product_type_slug,
+ is_shipping_required=is_shipping_required,
)
product_type_id = product_type_data["id"]
@@ -107,7 +109,7 @@ def prepare_digital_product(
product_variant_id = product_variant_data["id"]
variant_listing = create_product_variant_channel_listing(
- e2e_staff_api_client, product_variant_id, channel_id, price=10
+ e2e_staff_api_client, product_variant_id, channel_id, price=variant_price
)
create_digital_content(e2e_staff_api_client, product_variant_id)
diff --git a/saleor/tests/e2e/vouchers/utils/prepare_voucher.py b/saleor/tests/e2e/vouchers/utils/prepare_voucher.py
new file mode 100644
index 0000000000..3d37f25c7f
--- /dev/null
+++ b/saleor/tests/e2e/vouchers/utils/prepare_voucher.py
@@ -0,0 +1,40 @@
+from ...vouchers.utils import create_voucher, create_voucher_channel_listing
+
+
+def prepare_voucher(
+ e2e_staff_api_client,
+ channel_id,
+ voucher_code,
+ voucher_discount_type,
+ voucher_discount_value,
+ voucher_type,
+ products_list=None,
+ usage_limit=2,
+ single_use=True,
+ apply_once_per_order=False,
+):
+ input = {
+ "code": voucher_code,
+ "discountValueType": voucher_discount_type,
+ "type": voucher_type,
+ "usageLimit": usage_limit,
+ "singleUse": single_use,
+ "products": products_list,
+ "applyOncePerOrder": apply_once_per_order,
+ }
+ voucher_data = create_voucher(e2e_staff_api_client, input)
+
+ voucher_id = voucher_data["id"]
+ channel_listing = [
+ {
+ "channelId": channel_id,
+ "discountValue": voucher_discount_value,
+ },
+ ]
+ create_voucher_channel_listing(
+ e2e_staff_api_client,
+ voucher_id,
+ channel_listing,
+ )
+
+ return voucher_code, voucher_id, voucher_discount_value