Skip to content

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

Check availabilty per country - currently use DEFAULT_COUNTRY

Mira Szewczykf60d03528ce2
diff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.py
index e5f8cf36f6..58f63dc1a9 100644
--- a/saleor/data_feeds/google_merchant.py
+++ b/saleor/data_feeds/google_merchant.py
@@ -13,6 +13,7 @@ from ..core.taxes import zero_money
from ..discount import DiscountInfo
from ..discount.utils import fetch_discounts
from ..product.models import Attribute, AttributeValue, Category, ProductVariant
+from ..stock.availability import is_variant_in_stock
CATEGORY_SEPARATOR = " > "
@@ -144,7 +145,7 @@ def item_image_link(item: ProductVariant, current_site):
def item_availability(item: ProductVariant):
- if item.quantity_available:
+ if is_variant_in_stock(item, settings.DEFAULT_COUNTRY):
return "in stock"
return "out of stock"
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 0ed80b1683..9f6999d0c7 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -154,7 +154,7 @@ def test_send_confirmation_emails_without_addresses_for_payment(
add_variant_to_order(order, digital_content.product_variant, quantity=1)
order.shipping_address = None
order.shipping_method = None
- order.billing_address = None
+ order.billing_address = address
order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])
emails.send_payment_confirmation(order.pk)
diff --git a/tests/test_order_actions.py b/tests/test_order_actions.py
index 6e66aef7ae..7b5bff9cd1 100644
--- a/tests/test_order_actions.py
+++ b/tests/test_order_actions.py
@@ -17,15 +17,17 @@ from saleor.order.actions import (
from saleor.order.models import Fulfillment
from saleor.payment import ChargeStatus, PaymentError
from saleor.product.models import DigitalContent
+from saleor.stock.models import Stock
from .utils import create_image
@pytest.fixture
-def order_with_digital_line(order, digital_content, variant, site_settings):
+def order_with_digital_line(order, digital_content, stock, site_settings):
site_settings.automatic_fulfillment_digital_products = True
site_settings.save()
+ variant = stock.product_variant
variant.digital_content = digital_content
variant.digital_content.save()
@@ -165,12 +167,13 @@ def test_fulfill_order_line(order_with_lines):
line = order.lines.first()
quantity_fulfilled_before = line.quantity_fulfilled
variant = line.variant
- stock_quantity_after = variant.quantity - line.quantity
+ stock = Stock.objects.get(product_variant=variant)
+ stock_quantity_after = stock.quantity - line.quantity
fulfill_order_line(line, line.quantity)
- variant.refresh_from_db()
- assert variant.quantity == stock_quantity_after
+ stock.refresh_from_db()
+ assert stock.quantity == stock_quantity_after
assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity
@@ -190,14 +193,15 @@ def test_fulfill_order_line_without_inventory_tracking(order_with_lines):
variant = line.variant
variant.track_inventory = False
variant.save()
+ stock = Stock.objects.get(product_variant=variant)
# stock should not change
- stock_quantity_after = variant.quantity
+ stock_quantity_after = stock.quantity
fulfill_order_line(line, line.quantity)
- variant.refresh_from_db()
- assert variant.quantity == stock_quantity_after
+ stock.refresh_from_db()
+ assert stock.quantity == stock_quantity_after
assert line.quantity_fulfilled == quantity_fulfilled_before + line.quantity