Skip to content

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

Fix missing voucher_code assignment in order (#16775)

Alexis Mansilla23c70ec22872
diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.py
index 1d94b48346..a3b7c4e637 100644
--- a/saleor/checkout/complete_checkout.py
+++ b/saleor/checkout/complete_checkout.py
@@ -1246,6 +1246,9 @@ def _create_order_from_checkout(
# voucher
voucher = checkout_info.voucher
+ voucher_code = (
+ checkout_info.voucher_code.code if checkout_info.voucher_code else None
+ )
# shipping
undiscounted_base_shipping_price = base_checkout_undiscounted_delivery_price(
@@ -1295,6 +1298,7 @@ def _create_order_from_checkout(
total=taxed_total, # money field not supported by mypy_django_plugin
shipping_tax_rate=shipping_tax_rate,
voucher=voucher,
+ voucher_code=voucher_code,
checkout_token=str(checkout_info.checkout.token),
origin=OrderOrigin.CHECKOUT,
channel=checkout_info.channel,
diff --git a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
index cde5c68745..75dcb160a5 100644
--- a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
+++ b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py
@@ -771,6 +771,7 @@ def test_order_from_checkout_with_voucher(
assert order_discount.type == DiscountType.VOUCHER
assert order_discount.voucher == voucher_percentage
assert order_discount.voucher_code == code.code
+ assert order.voucher_code == code.code
code.refresh_from_db()
assert code.used == voucher_used_count + 1