Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change StockQuerySet.for_country to StockQuerySet.for_country_and_channel
IKarbowiak0ed3ca5c61f3
diff --git a/saleor/graphql/warehouse/tests/test_stock.py b/saleor/graphql/warehouse/tests/test_stock.pyindex 4138c95c45..73ed00f813 100644--- a/saleor/graphql/warehouse/tests/test_stock.py+++ b/saleor/graphql/warehouse/tests/test_stock.py@@ -246,7 +246,7 @@ def test_stock_quantity_is_sum_of_quantities_from_warehouses_that_support_countr# Create another warehouse with a different shipping zone that supports PL. As# a result there should be two shipping zones and two warehouses that support PL.- stocks = variant.stocks.for_country("PL", channel_USD.slug)+ stocks = variant.stocks.for_country_and_channel("PL", channel_USD.slug)warehouse = Warehouse.objects.create(address=address.get_copy(),name="WarehousePL",@@ -256,7 +256,7 @@ def test_stock_quantity_is_sum_of_quantities_from_warehouses_that_support_countrwarehouse.shipping_zones.add(shipping_zone)Stock.objects.create(warehouse=warehouse, product_variant=variant, quantity=10)- stocks = variant.stocks.for_country("PL", channel_USD.slug)+ stocks = variant.stocks.for_country_and_channel("PL", channel_USD.slug)sum_quantities = sum([stock.quantity for stock in stocks])variables = {diff --git a/saleor/warehouse/availability.py b/saleor/warehouse/availability.pyindex 9609e235e8..caa24f9f82 100644--- a/saleor/warehouse/availability.py+++ b/saleor/warehouse/availability.py@@ -52,7 +52,7 @@ def check_stock_quantity_bulk(:raises InsufficientStock: when there is not enough items in stock for a variant."""all_variants_stocks = (- Stock.objects.for_country(country_code, channel_slug)+ Stock.objects.for_country_and_channel(country_code, channel_slug).filter(product_variant__in=variants).annotate_available_quantity())diff --git a/saleor/warehouse/management.py b/saleor/warehouse/management.pyindex e56495c449..599f68a1c9 100644--- a/saleor/warehouse/management.py+++ b/saleor/warehouse/management.py@@ -39,7 +39,7 @@ def allocate_stocks(stocks = list(Stock.objects.select_for_update(of=("self",))- .for_country(country_code, channel_slug)+ .for_country_and_channel(country_code, channel_slug).filter(product_variant__in=variants).order_by("pk").values("id", "product_variant", "pk", "quantity")diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.pyindex 0f1b3110fa..195d51056d 100644--- a/saleor/warehouse/models.py+++ b/saleor/warehouse/models.py@@ -72,7 +72,7 @@ class StockQuerySet(models.QuerySet):warehouse__in=query_warehouse)- def for_country(self, country_code: str, channel_slug):+ def for_country_and_channel(self, country_code: str, channel_slug):filter_lookup = {"shipping_zones__countries__contains": country_code}if channel_slug is not None:filter_lookup["shipping_zones__channels__slug"] = channel_slug@@ -90,14 +90,14 @@ class StockQuerySet(models.QuerySet):Note it will raise a 'Stock.DoesNotExist' exception if no such stock is found."""- return self.for_country(country_code, channel_slug).filter(+ return self.for_country_and_channel(country_code, channel_slug).filter(product_variant=product_variant)def get_product_stocks_for_country_and_channel(self, country_code: str, channel_slug: str, product: Product):- return self.for_country(country_code, channel_slug).filter(+ return self.for_country_and_channel(country_code, channel_slug).filter(product_variant__product_id=product.pk)diff --git a/saleor/warehouse/tests/test_stock.py b/saleor/warehouse/tests/test_stock.pyindex 598646737a..5552ab6102 100644--- a/saleor/warehouse/tests/test_stock.py+++ b/saleor/warehouse/tests/test_stock.py@@ -6,7 +6,7 @@ COUNTRY_CODE = "US"def test_stocks_for_country(variant_with_many_stocks, channel_USD):[stock1, stock2] = (Stock.objects.filter(product_variant=variant_with_many_stocks)- .for_country(COUNTRY_CODE, channel_USD.slug)+ .for_country_and_channel(COUNTRY_CODE, channel_USD.slug).order_by("pk").all())@@ -25,5 +25,7 @@ def test_stock_for_country_does_not_exists(product, warehouse, channel_PLN):warehouse.refresh_from_db()fake_country_code = "PL"assert fake_country_code not in warehouse.countries- stock_qs = Stock.objects.for_country(fake_country_code, channel_PLN.slug)+ stock_qs = Stock.objects.for_country_and_channel(+ fake_country_code, channel_PLN.slug+ )assert not stock_qs.exists()