Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use only variants with price for draft order
Damian We49f4c8a68d1
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 8bd9df0644..6eb4dc8154 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -220,8 +220,7 @@ def test_checkout_create_with_unavailable_variant():variant = stock.product_variant- variant.channel_listings.filter(channel=channel_USD).delete()- variant.channel_listings.create(channel=channel_USD)+ variant.channel_listings.filter(channel=channel_USD).update(price_amount=None)variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)test_email = "[email protected]"shipping_address = graphql_address_data@@ -1385,8 +1384,9 @@ def test_checkout_lines_add_with_unavailable_variant(user_api_client, checkout_with_item, stock):variant = stock.product_variant- variant.channel_listings.filter(channel=checkout_with_item.channel).delete()- variant.channel_listings.create(channel=checkout_with_item.channel)+ variant.channel_listings.filter(channel=checkout_with_item.channel).update(+ price_amount=None+ )checkout = checkout_with_itemline = checkout.lines.first()assert line.quantity == 3@@ -1660,8 +1660,9 @@ def test_checkout_lines_update_with_unavailable_variant(assert checkout.lines.count() == 1line = checkout.lines.first()variant = line.variant- variant.channel_listings.filter(channel=checkout_with_item.channel).delete()- variant.channel_listings.create(channel=checkout_with_item.channel)+ variant.channel_listings.filter(channel=checkout_with_item.channel).update(+ price_amount=None+ )assert line.quantity == 3variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.pyindex a1c3f12043..d3c7665891 100644--- a/saleor/graphql/checkout/tests/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py@@ -247,27 +247,24 @@ def test_checkout_complete(def test_checkout_complete_with_unavailable_variant(site_settings,user_api_client,- checkout_with_gift_card,+ checkout_with_item,gift_card,payment_dummy,address,shipping_method,):- assert not gift_card.last_used_on-- checkout = checkout_with_gift_card+ checkout = checkout_with_itemcheckout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.billing_address = address- checkout.store_value_in_metadata(items={"accepted": "true"})- checkout.store_value_in_private_metadata(items={"accepted": "false"})checkout.save()checkout_line = checkout.lines.first()checkout_line_variant = checkout_line.variant- checkout_line_variant.channel_listings.filter(channel=checkout.channel).delete()- checkout_line_variant.channel_listings.create(channel=checkout.channel)+ checkout_line_variant.channel_listings.filter(channel=checkout.channel).update(+ price_amount=None+ )checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)variant_id = graphene.Node.to_global_id("ProductVariant", checkout_line_variant.pk)diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 8a6462fd24..99e1fa4b24 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -2582,6 +2582,30 @@ def test_draft_order_lines_create(assert data["orderErrors"][0]["field"] == "quantity"+def test_draft_order_lines_create_with_unavailable_variant(+ draft_order, permission_manage_orders, staff_api_client+):+ query = DRAFT_ORDER_LINES_CREATE_MUTATION+ order = draft_order+ channel = order.channel+ line = order.lines.first()+ variant = line.variant+ variant.channel_listings.filter(channel=channel).update(price_amount=None)+ quantity = 1+ order_id = graphene.Node.to_global_id("Order", order.id)+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)+ variables = {"orderId": order_id, "variantId": variant_id, "quantity": quantity}++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_orders]+ )+ content = get_graphql_content(response)+ error = content["data"]["draftOrderLinesCreate"]["orderErrors"][0]+ assert error["code"] == OrderErrorCode.NOT_AVAILABLE_IN_CHANNEL.name+ assert error["field"] == "input"+ assert error["variants"] == [variant_id]++def test_draft_order_lines_create_with_product_and_variant_not_assigned_to_channel(draft_order, permission_manage_orders, staff_api_client, variant):diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex e7eee159a8..5d1f68d79b 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -138,7 +138,7 @@ def validate_variant_channel_listings(variants, channel):)variant_ids = set([variant.id for variant in variants])variant_channel_listings = ProductVariantChannelListing.objects.filter(- channel=channel, variant_id__in=variant_ids+ channel=channel, variant_id__in=variant_ids, price_amount__isnull=False)variant_ids_in_channel = set([