Skip to content

Commit

Permalink
Merge pull request saleor#8762 from saleor/fix/cc-preorder-int
Browse files Browse the repository at this point in the history
Add preorder validation to queryset used in clean_delivery_method
  • Loading branch information
fowczarek authored Dec 9, 2021
2 parents 3b2a3a0 + 7e217b6 commit 68c4f7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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": [],
Expand Down Expand Up @@ -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]],
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions saleor/graphql/checkout/tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
5 changes: 5 additions & 0 deletions saleor/warehouse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def applicable_for_click_and_collect_no_quantity_check(
This method should be used only if stocks quantity will be checked in further
validation 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"),
Expand Down

0 comments on commit 68c4f7a

Please sign in to comment.