Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix gift reward creation during checkout creation (#15402)
Iga Karbowiak6bea797b6f3a
diff --git a/saleor/graphql/checkout/mutations/utils.py b/saleor/graphql/checkout/mutations/utils.pyindex f5495b9c88..abd41b4991 100644--- a/saleor/graphql/checkout/mutations/utils.py+++ b/saleor/graphql/checkout/mutations/utils.py@@ -535,14 +535,15 @@ def apply_gift_reward_if_applicable_on_checkout_creation(checkout: "Checkout") -if not gift_listing:return+ amount_value = gift_listing.price_amountwith transaction.atomic():line, _line_created = create_gift_line(checkout, gift_listing.variant_id)CheckoutLineDiscount.objects.create(type=DiscountType.ORDER_PROMOTION,line=line,- amount_value=best_discount_amount,+ amount_value=amount_value,value_type=DiscountValueType.FIXED,- value=best_discount_amount,+ value=amount_value,promotion_rule=best_rule,currency=checkout.currency,)diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create.pyindex 3860b61070..8db4f831aa 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create.py@@ -622,6 +622,11 @@ def test_checkout_create_with_gift_reward(line for line in checkout_data["lines"] if line["isGift"] is True][0]assert gift_line_data["quantity"] == 1+ gift_line = new_checkout.lines.get(is_gift=True)+ assert gift_line.discounts.count() == 1+ discount = gift_line.discounts.first()+ gift_variant_listing = gift_line.variant.channel_listings.get(channel=channel_USD)+ assert discount.amount_value == gift_variant_listing.price_amountdef test_checkout_create_with_metadata_in_line(diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_create_from_order.py b/saleor/graphql/checkout/tests/mutations/test_checkout_create_from_order.pyindex b72aa433c3..a351616571 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_create_from_order.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_create_from_order.py@@ -234,6 +234,12 @@ def test_checkout_create_from_order_with_gift_reward(_assert_checkout_lines(order_lines_map, checkout_lines, checkout_lines_from_response_map)+ assert gift_line.discounts.count() == 1+ discount = gift_line.discounts.first()+ gift_variant_listing = gift_line.variant.channel_listings.get(+ channel=checkout.channel+ )+ assert discount.amount_value == gift_variant_listing.price_amountdef test_checkout_create_from_order_when_order_not_found(