Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Make channel_slug in StockQuerySet.for_country required

IKarbowiakfd5b7971c5d2
diff --git a/saleor/graphql/warehouse/tests/test_stock.py b/saleor/graphql/warehouse/tests/test_stock.py
index b0102b7fa2..4138c95c45 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")
+ stocks = variant.stocks.for_country("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_countr
warehouse.shipping_zones.add(shipping_zone)
Stock.objects.create(warehouse=warehouse, product_variant=variant, quantity=10)
- stocks = variant.stocks.for_country("PL")
+ stocks = variant.stocks.for_country("PL", channel_USD.slug)
sum_quantities = sum([stock.quantity for stock in stocks])
variables = {
diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.py
index 7f1124d530..0f1b3110fa 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=None):
+ def for_country(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
diff --git a/saleor/warehouse/tests/test_stock.py b/saleor/warehouse/tests/test_stock.py
index ab223a1bf7..598646737a 100644
--- a/saleor/warehouse/tests/test_stock.py
+++ b/saleor/warehouse/tests/test_stock.py
@@ -3,10 +3,10 @@ from ..models import Stock
COUNTRY_CODE = "US"
-def test_stocks_for_country(variant_with_many_stocks):
+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)
+ .for_country(COUNTRY_CODE, channel_USD.slug)
.order_by("pk")
.all()
)
@@ -18,12 +18,12 @@ def test_stocks_for_country(variant_with_many_stocks):
assert COUNTRY_CODE in warehouse2.countries
-def test_stock_for_country_does_not_exists(product, warehouse):
+def test_stock_for_country_does_not_exists(product, warehouse, channel_PLN):
shipping_zone = warehouse.shipping_zones.first()
shipping_zone.countries = [COUNTRY_CODE]
shipping_zone.save(update_fields=["countries"])
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)
+ stock_qs = Stock.objects.for_country(fake_country_code, channel_PLN.slug)
assert not stock_qs.exists()
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index a127a81a62..938ccbe4a0 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -360,9 +360,7 @@ def generate_fulfillment_payload(fulfillment: Fulfillment):
if fulfillment_line and fulfillment_line.stock:
warehouse = fulfillment_line.stock.warehouse
else:
- warehouse = Warehouse.objects.for_country(
- order_country, order.channel.slug
- ).first()
+ warehouse = Warehouse.objects.for_country(order_country).first()
fulfillment_data = serializer.serialize(
[fulfillment],
fields=fulfillment_fields,