Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use channel_slug in check_stock_quantity for checking stocks only in available warehouses for given channel
IKarbowiak5821309aed09
diff --git a/saleor/checkout/tests/test_cart.py b/saleor/checkout/tests/test_cart.pyindex d8eec0e388..edded30ed6 100644--- a/saleor/checkout/tests/test_cart.py+++ b/saleor/checkout/tests/test_cart.py@@ -25,14 +25,16 @@ def test_get_user_checkout(def test_adding_zero_quantity(checkout, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 0)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 0)assert checkout.lines.count() == 0def test_adding_same_variant(checkout, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 1)- add_variant_to_checkout(checkout, variant, 2)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)+ add_variant_to_checkout(checkout_info, variant, 2)assert checkout.lines.count() == 1assert checkout.quantity == 3subtotal = TaxedMoney(Money("30.00", "USD"), Money("30.00", "USD"))@@ -53,29 +55,33 @@ def test_adding_same_variant(checkout, product):def test_replacing_same_variant(checkout, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 1, replace=True)- add_variant_to_checkout(checkout, variant, 2, replace=True)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1, replace=True)+ add_variant_to_checkout(checkout_info, variant, 2, replace=True)assert checkout.lines.count() == 1assert checkout.quantity == 2def test_adding_invalid_quantity(checkout, product):variant = product.variants.get()+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())with pytest.raises(ValueError):- add_variant_to_checkout(checkout, variant, -1)+ add_variant_to_checkout(checkout_info, variant, -1)def test_getting_line(checkout, product):variant = product.variants.get()assert checkout.get_line(variant) is None- add_variant_to_checkout(checkout, variant)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant)assert checkout.lines.get() == checkout.get_line(variant)def test_shipping_detection(checkout, product):assert not checkout.is_shipping_required()variant = product.variants.get()- add_variant_to_checkout(checkout, variant, replace=True)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, replace=True)assert checkout.is_shipping_required()@@ -123,12 +129,12 @@ def test_get_prices_of_discounted_specific_product_only_product(channel = checkout.channelvariant_channel_listing = line.variant.channel_listings.get(channel=channel)- add_variant_to_checkout(checkout, product2.variants.get(), 1)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, [], [], manager)+ add_variant_to_checkout(checkout_info, product2.variants.get(), 1)voucher.products.add(product)- manager = get_plugins_manager()lines = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)prices = utils.get_prices_of_discounted_specific_product(manager, checkout_info, lines, voucher)@@ -156,13 +162,13 @@ def test_get_prices_of_discounted_specific_product_only_collection(channel = checkout.channelvariant_channel_listing = line.variant.channel_listings.get(channel=channel)- add_variant_to_checkout(checkout, product2.variants.get(), 1)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, [], [], manager)+ add_variant_to_checkout(checkout_info, product2.variants.get(), 1)product.collections.add(collection)voucher.collections.add(collection)- manager = get_plugins_manager()lines = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)prices = utils.get_prices_of_discounted_specific_product(manager, checkout_info, lines, voucher)@@ -193,12 +199,12 @@ def test_get_prices_of_discounted_specific_product_only_category(product2.category = category2product2.save()- add_variant_to_checkout(checkout, product2.variants.get(), 1)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, [], [], manager)+ add_variant_to_checkout(checkout_info, product2.variants.get(), 1)voucher.categories.add(category)- manager = get_plugins_manager()lines = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)prices = utils.get_prices_of_discounted_specific_product(manager, checkout_info, lines, voucher)diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.pyindex 9c4da40ad1..3c74f9100c 100644--- a/saleor/checkout/tests/test_checkout_complete.py+++ b/saleor/checkout/tests/test_checkout_complete.py@@ -507,16 +507,17 @@ def test_create_order_insufficient_stock(checkout, customer_user, product_without_shipping):variant = product_without_shipping.variants.get()- add_variant_to_checkout(checkout, variant, 10, check_quantity=False)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, [], [], manager)++ add_variant_to_checkout(checkout_info, variant, 10, check_quantity=False)checkout.user = customer_usercheckout.billing_address = customer_user.default_billing_addresscheckout.shipping_address = customer_user.default_billing_addresscheckout.tracking_code = "tracking_code"checkout.save()- manager = get_plugins_manager()lines = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)with pytest.raises(InsufficientStock):_prepare_order_data(manager=manager,@@ -749,12 +750,11 @@ def test_create_order_with_variant_tracking_false(checkout.tracking_code = ""checkout.redirect_url = "https://www.example.com"checkout.save()- add_variant_to_checkout(checkout, variant, 10, check_quantity=False)-manager = get_plugins_manager()- lines = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, [], [], manager)+ add_variant_to_checkout(checkout_info, variant, 10, check_quantity=False)+ lines = fetch_checkout_lines(checkout)order_data = _prepare_order_data(manager=manager, checkout_info=checkout_info, lines=lines, discounts=None)diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 5558581879..9953ad3dd5 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -51,7 +51,12 @@ def get_user_checkout(def check_variant_in_stock(- checkout, variant, quantity=1, replace=False, check_quantity=True+ checkout: Checkout,+ variant: product_models.ProductVariant,+ channel_slug: str,+ quantity: int = 1,+ replace: bool = False,+ check_quantity: bool = True,) -> Tuple[int, Optional[CheckoutLine]]:"""Check if a given variant is in stock and return the new quantity + line."""line = checkout.lines.filter(variant=variant).first()@@ -65,19 +70,26 @@ def check_variant_in_stock()if new_quantity > 0 and check_quantity:- check_stock_quantity(variant, checkout.get_country(), new_quantity)+ check_stock_quantity(+ variant, checkout.get_country(), channel_slug, new_quantity+ )return new_quantity, linedef add_variant_to_checkout(- checkout, variant, quantity=1, replace=False, check_quantity=True+ checkout_info: "CheckoutInfo",+ variant: product_models.ProductVariant,+ quantity: int = 1,+ replace: bool = False,+ check_quantity: bool = True,):"""Add a product variant to checkout.If `replace` is truthy then any previous quantity is discarded insteadof added to."""+ checkout = checkout_info.checkoutproduct_channel_listing = variant.product.channel_listings.filter(channel_id=checkout.channel_id).first()@@ -87,6 +99,7 @@ def add_variant_to_checkout(new_quantity, line = check_variant_in_stock(checkout,variant,+ checkout_info.channel.slug,quantity=quantity,replace=replace,check_quantity=check_quantity,diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex d0680ea05a..4f4fae72bc 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -468,7 +468,7 @@ class CheckoutLinesAdd(BaseMutation):for variant, quantity in zip(variants, quantities):try:checkout = add_variant_to_checkout(- checkout, variant, quantity, replace=replace+ checkout_info, variant, quantity, replace=replace)except InsufficientStock as exc:error = prepare_insufficient_stock_checkout_validation_error(exc)diff --git a/saleor/graphql/checkout/tests/benchmark/conftest.py b/saleor/graphql/checkout/tests/benchmark/conftest.pyindex 657ee56c75..d70a609e16 100644--- a/saleor/graphql/checkout/tests/benchmark/conftest.py+++ b/saleor/graphql/checkout/tests/benchmark/conftest.py@@ -23,11 +23,18 @@ def checkout_with_variants(product_with_single_variant,product_with_two_variants,):+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())- add_variant_to_checkout(checkout, product_with_default_variant.variants.get(), 1)- add_variant_to_checkout(checkout, product_with_single_variant.variants.get(), 10)- add_variant_to_checkout(checkout, product_with_two_variants.variants.first(), 3)- add_variant_to_checkout(checkout, product_with_two_variants.variants.last(), 5)+ add_variant_to_checkout(+ checkout_info, product_with_default_variant.variants.get(), 1+ )+ add_variant_to_checkout(+ checkout_info, product_with_single_variant.variants.get(), 10+ )+ add_variant_to_checkout(+ checkout_info, product_with_two_variants.variants.first(), 3+ )+ add_variant_to_checkout(checkout_info, product_with_two_variants.variants.last(), 5)checkout.save()return checkoutdiff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 3161b55707..3760107398 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -2195,7 +2195,8 @@ def test_checkout_shipping_address_update_changes_checkout_country(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)assert checkout.shipping_address is Nonecheckout_id = graphene.Node.to_global_id("Checkout", checkout.pk)@@ -2246,7 +2247,8 @@ def test_checkout_shipping_address_update_insufficient_stocks(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)Stock.objects.filter(warehouse__shipping_zones__countries__contains="US", product_variant=variant).update(quantity=0)diff --git a/saleor/graphql/checkout/tests/test_checkout_digital.py b/saleor/graphql/checkout/tests/test_checkout_digital.pyindex cbbc6aff63..26861daa3f 100644--- a/saleor/graphql/checkout/tests/test_checkout_digital.py+++ b/saleor/graphql/checkout/tests/test_checkout_digital.py@@ -178,7 +178,8 @@ def test_checkout_lines_update_remove_shipping_if_removed_product_with_shipping(checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.save()- add_variant_to_checkout(checkout, digital_variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, digital_variant, 1)line = checkout.lines.first()variant = line.variant@@ -207,7 +208,8 @@ def test_checkout_line_delete_remove_shipping_if_removed_product_with_shipping(checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.save()- add_variant_to_checkout(checkout, digital_variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, digital_variant, 1)line = checkout.lines.first()line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex 5d1f68d79b..12c1f6f4fe 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -80,7 +80,9 @@ def validate_order_lines(order, country):)if line.variant.track_inventory:try:- check_stock_quantity(line.variant, country, line.quantity)+ check_stock_quantity(+ line.variant, country, order.channel.slug, line.quantity+ )except InsufficientStock as exc:errors = prepare_insufficient_stock_order_validation_errors(exc)raise ValidationError({"lines": errors})diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.pyindex 2f91256816..dca5049a3c 100644--- a/saleor/plugins/avatax/tests/test_avatax.py+++ b/saleor/plugins/avatax/tests/test_avatax.py@@ -194,13 +194,11 @@ def test_calculate_checkout_total_uses_default_calculation(product_with_single_variant.charge_taxes = Falseproduct_with_single_variant.category = non_default_categoryproduct_with_single_variant.save()- add_variant_to_checkout(- checkout_with_item, product_with_single_variant.variants.get()- )-discounts = [discount_info] if with_discount else None+ checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())lines = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)+total = manager.calculate_checkout_total(checkout_info, lines, address, discounts)total = quantize_price(total, total.currency)assert total == TaxedMoney(@@ -265,13 +263,10 @@ def test_calculate_checkout_total(product_with_single_variant.charge_taxes = Falseproduct_with_single_variant.category = non_default_categoryproduct_with_single_variant.save()- add_variant_to_checkout(- checkout_with_item, product_with_single_variant.variants.get()- )-discounts = [discount_info] if with_discount else None+ checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())lines = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address, discounts)@@ -360,9 +355,10 @@ def test_calculate_checkout_subtotal(checkout_with_item.save()discounts = [discount_info] if with_discount else None- add_variant_to_checkout(checkout_with_item, variant, 2)++ checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ add_variant_to_checkout(checkout_info, variant, 2)lines = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)total = manager.calculate_checkout_subtotal(checkout_info, lines, address, discounts)diff --git a/saleor/plugins/vatlayer/tests/test_vatlayer.py b/saleor/plugins/vatlayer/tests/test_vatlayer.pyindex bddfcf9213..f7d10a8154 100644--- a/saleor/plugins/vatlayer/tests/test_vatlayer.py+++ b/saleor/plugins/vatlayer/tests/test_vatlayer.py@@ -295,9 +295,9 @@ def test_calculate_checkout_subtotal(product.save()discounts = [discount_info] if with_discount else None- add_variant_to_checkout(checkout_with_item, variant, 2)+ checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ add_variant_to_checkout(checkout_info, variant, 2)lines = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)total = manager.calculate_checkout_subtotal(checkout_info, lines, address, discounts)diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex f21ccde6be..2f5a2195cc 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -35,6 +35,7 @@ from ..attribute.models import (AttributeValueTranslation,)from ..attribute.utils import associate_attribute_values_to_instance+from ..checkout.fetch import fetch_checkout_infofrom ..checkout.models import Checkoutfrom ..checkout.utils import add_variant_to_checkoutfrom ..core import JobStatus@@ -66,6 +67,7 @@ from ..page.models import Page, PageTranslation, PageTypefrom ..payment import ChargeStatus, TransactionKindfrom ..payment.interface import GatewayConfig, PaymentDatafrom ..payment.models import Payment+from ..plugins.manager import get_plugins_managerfrom ..plugins.models import PluginConfigurationfrom ..plugins.vatlayer.plugin import VatlayerPluginfrom ..product import ProductMediaTypes@@ -259,7 +261,8 @@ def checkout(db, channel_USD):@pytest.fixturedef checkout_with_item(checkout, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 3)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 3)checkout.save()return checkout@@ -317,7 +320,8 @@ def checkout_ready_to_complete(checkout_with_item, address, shipping_method, gifdef checkout_with_digital_item(checkout, digital_content):"""Create a checkout with a digital line."""variant = digital_content.product_variant- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)checkout.email = "[email protected]"checkout.save()return checkout@@ -327,7 +331,8 @@ def checkout_with_digital_item(checkout, digital_content):def checkout_with_shipping_required(checkout_with_item, product):checkout = checkout_with_itemvariant = product.variants.get()- add_variant_to_checkout(checkout, variant, 3)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 3)checkout.save()return checkout@@ -351,7 +356,8 @@ def other_shipping_method(shipping_zone, channel_USD):@pytest.fixturedef checkout_without_shipping_required(checkout, product_without_shipping):variant = product_without_shipping.variants.get()- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)checkout.save()return checkout@@ -359,7 +365,8 @@ def checkout_without_shipping_required(checkout, product_without_shipping):@pytest.fixturedef checkout_with_single_item(checkout, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)checkout.save()return checkout@@ -369,7 +376,8 @@ def checkout_with_variant_without_inventory_tracking(checkout, variant_without_inventory_tracking, address, shipping_method):variant = variant_without_inventory_tracking- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.billing_address = address@@ -382,10 +390,11 @@ def checkout_with_variant_without_inventory_tracking(@pytest.fixturedef checkout_with_items(checkout, product_list, product):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 1)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 1)for prod in product_list:variant = prod.variants.get()- add_variant_to_checkout(checkout, variant, 1)+ add_variant_to_checkout(checkout_info, variant, 1)checkout.refresh_from_db()return checkout@@ -393,7 +402,8 @@ def checkout_with_items(checkout, product_list, product):@pytest.fixturedef checkout_with_voucher(checkout, product, voucher):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 3)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 3)checkout.voucher_code = voucher.codecheckout.discount = Money("20.00", "USD")checkout.save()@@ -403,7 +413,8 @@ def checkout_with_voucher(checkout, product, voucher):@pytest.fixturedef checkout_with_voucher_percentage(checkout, product, voucher_percentage):variant = product.variants.get()- add_variant_to_checkout(checkout, variant, 3)+ checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ add_variant_to_checkout(checkout_info, variant, 3)checkout.voucher_code = voucher_percentage.codecheckout.discount = Money("3.00", "USD")checkout.save()@@ -544,9 +555,10 @@ def user_checkout_PLN(customer_user, channel_PLN):@pytest.fixturedef user_checkout_with_items(user_checkout, product_list):+ checkout_info = fetch_checkout_info(user_checkout, [], [], get_plugins_manager())for product in product_list:variant = product.variants.get()- add_variant_to_checkout(user_checkout, variant, 1)+ add_variant_to_checkout(checkout_info, variant, 1)user_checkout.refresh_from_db()return user_checkoutdiff --git a/saleor/warehouse/availability.py b/saleor/warehouse/availability.pyindex 342264e3b9..9609e235e8 100644--- a/saleor/warehouse/availability.py+++ b/saleor/warehouse/availability.py@@ -22,14 +22,18 @@ def _get_available_quantity(stocks: StockQuerySet) -> int:return max(total_quantity - quantity_allocated, 0)-def check_stock_quantity(variant: "ProductVariant", country_code: str, quantity: int):+def check_stock_quantity(+ variant: "ProductVariant", country_code: str, channel_slug: str, quantity: int+):"""Validate if there is stock available for given variant in given country.If so - returns None. If there is less stock then required raise InsufficientStockexception."""if variant.track_inventory:- stocks = Stock.objects.get_variant_stocks_for_country(country_code, variant)+ stocks = Stock.objects.get_variant_stocks_for_country(+ country_code, channel_slug, variant+ )if not stocks:raise InsufficientStock([InsufficientStockData(variant=variant)])diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.pyindex 00294f4412..7f1124d530 100644--- a/saleor/warehouse/models.py+++ b/saleor/warehouse/models.py@@ -84,13 +84,15 @@ class StockQuerySet(models.QuerySet):)def get_variant_stocks_for_country(- self, country_code: str, product_variant: ProductVariant+ self, country_code: str, channel_slug: str, product_variant: ProductVariant):"""Return the stock information about the a stock for a given country.Note it will raise a 'Stock.DoesNotExist' exception if no such stock is found."""- return self.for_country(country_code).filter(product_variant=product_variant)+ return self.for_country(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: Productdiff --git a/saleor/warehouse/tests/test_stock_availability.py b/saleor/warehouse/tests/test_stock_availability.pyindex aa8d4c9e07..4e973a48b7 100644--- a/saleor/warehouse/tests/test_stock_availability.py+++ b/saleor/warehouse/tests/test_stock_availability.py@@ -10,39 +10,61 @@ from ..availability import (COUNTRY_CODE = "US"-def test_check_stock_quantity(variant_with_many_stocks):- assert check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 7) is None+def test_check_stock_quantity(variant_with_many_stocks, channel_USD):+ assert (+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 7+ )+ is None+ )-def test_check_stock_quantity_out_of_stock(variant_with_many_stocks):+def test_check_stock_quantity_out_of_stock(variant_with_many_stocks, channel_USD):with pytest.raises(InsufficientStock):- check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 8)+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 8+ )def test_check_stock_quantity_with_allocations(variant_with_many_stocks,order_line_with_allocation_in_many_stocks,order_line_with_one_allocation,+ channel_USD,):- assert check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 3) is None+ assert (+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 3+ )+ is None+ )def test_check_stock_quantity_with_allocations_out_of_stock(- variant_with_many_stocks, order_line_with_allocation_in_many_stocks+ variant_with_many_stocks, order_line_with_allocation_in_many_stocks, channel_USD):with pytest.raises(InsufficientStock):- check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 5)+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 5+ )-def test_check_stock_quantity_without_stocks(variant_with_many_stocks):+def test_check_stock_quantity_without_stocks(variant_with_many_stocks, channel_USD):variant_with_many_stocks.stocks.all().delete()with pytest.raises(InsufficientStock):- check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 1)+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 1+ )-def test_check_stock_quantity_without_one_stock(variant_with_many_stocks):+def test_check_stock_quantity_without_one_stock(variant_with_many_stocks, channel_USD):variant_with_many_stocks.stocks.get(quantity=3).delete()- assert check_stock_quantity(variant_with_many_stocks, COUNTRY_CODE, 4) is None+ assert (+ check_stock_quantity(+ variant_with_many_stocks, COUNTRY_CODE, channel_USD.slug, 4+ )+ is None+ )def test_check_stock_quantity_bulk(variant_with_many_stocks, channel_USD):diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.pyindex a5bbc5158f..a127a81a62 100644--- a/saleor/webhook/payloads.py+++ b/saleor/webhook/payloads.py@@ -354,12 +354,15 @@ def generate_fulfillment_payload(fulfillment: Fulfillment):# fulfillment fields to serializefulfillment_fields = ("status", "tracking_code", "order__user_email")- order_country = get_order_country(fulfillment.order)+ order = fulfillment.order+ order_country = get_order_country(order)fulfillment_line = fulfillment.lines.first()if fulfillment_line and fulfillment_line.stock:warehouse = fulfillment_line.stock.warehouseelse:- warehouse = Warehouse.objects.for_country(order_country).first()+ warehouse = Warehouse.objects.for_country(+ order_country, order.channel.slug+ ).first()fulfillment_data = serializer.serialize([fulfillment],fields=fulfillment_fields,