Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add preorder validation to queryset used in clean_delivery_method
kuchichan7e217b6936ea
diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.pyindex 2f2698d14c..0b32b6e21a 100644--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py@@ -706,7 +706,7 @@ def test_update_checkout_lines_with_reservations(reservation_length=5,)- with django_assert_num_queries(58):+ with django_assert_num_queries(60):variant_id = graphene.Node.to_global_id("ProductVariant", variants[0].pk)variables = {"token": checkout.token,@@ -720,7 +720,7 @@ def test_update_checkout_lines_with_reservations(assert not data["errors"]# Updating multiple lines in checkout has same query count as updating one- with django_assert_num_queries(58):+ with django_assert_num_queries(60):variables = {"token": checkout.token,"lines": [],@@ -859,7 +859,7 @@ def test_add_checkout_lines_with_reservations(new_lines.append({"quantity": 2, "variantId": variant_id})# Adding multiple lines to checkout has same query count as adding one- with django_assert_num_queries(57):+ with django_assert_num_queries(59):variables = {"checkoutId": Node.to_global_id("Checkout", checkout.pk),"lines": [new_lines[0]],@@ -872,7 +872,7 @@ def test_add_checkout_lines_with_reservations(checkout.lines.exclude(id=line.id).delete()- with django_assert_num_queries(57):+ with django_assert_num_queries(59):variables = {"checkoutId": Node.to_global_id("Checkout", checkout.pk),"lines": new_lines,diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 8382220871..c6eb0d3bfb 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -71,6 +71,20 @@ def test_clean_delivery_method_after_shipping_address_changes_stay_the_same(assert is_valid_method is True+def test_clean_delivery_method_with_preorder_is_valid_for_enabled_warehouse(+ checkout_with_preorders_only, address, warehouses_for_cc+):+ checkout = checkout_with_preorders_only+ checkout.shipping_address = address++ manager = get_plugins_manager()+ lines = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ is_valid_method = clean_delivery_method(checkout_info, lines, warehouses_for_cc[1])++ assert is_valid_method is True++def test_clean_delivery_method_does_nothing_if_no_shipping_method(checkout_with_single_item, address, other_shipping_method):diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.pyindex d417e67eeb..580f0e5e8f 100644--- a/saleor/warehouse/models.py+++ b/saleor/warehouse/models.py@@ -39,6 +39,11 @@ class WarehouseQueryset(models.QuerySet):This method should be used only if stocks quantity will be checked in furthervalidation steps, for instance in checkout completion."""+ if all(+ line.variant.is_preorder_active()+ for line in lines_qs.select_related("variant").only("variant_id")+ ):+ return self.for_country(country)stocks_qs = Stock.objects.filter(product_variant__id__in=lines_qs.values("variant_id"),