Skip to content

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

Set default value for country

Mira Szewczykf0ffe545fe67
diff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.py
index ad7418c29f..c4c7028b03 100644
--- a/saleor/product/utils/availability.py
+++ b/saleor/product/utils/availability.py
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Iterable, Optional, Tuple, Union
+from django.conf import settings
from prices import TaxedMoney, TaxedMoneyRange
from saleor.graphql.core.types import MoneyRange
@@ -63,15 +64,8 @@ def get_product_availability_status(product: "Product") -> ProductAvailabilitySt
return ProductAvailabilityStatus.READY_FOR_PURCHASE
-<<<<<<< HEAD
-def get_variant_availability_status(
- variant: ProductVariant,
-) -> VariantAvailabilityStatus:
- if not variant.is_in_stock():
-=======
def get_variant_availability_status(variant, country):
if not is_variant_in_stock(variant, country):
->>>>>>> Remove utils module from stock app
return VariantAvailabilityStatus.OUT_OF_STOCK
return VariantAvailabilityStatus.AVAILABLE
@@ -155,10 +149,6 @@ def get_product_availability(
is_available = product.is_visible and is_product_in_stock(product, country)
return ProductAvailability(
-<<<<<<< HEAD
-=======
- available=is_available,
->>>>>>> Remove utils module from stock app
on_sale=is_on_sale,
price_range=discounted,
price_range_undiscounted=undiscounted,
@@ -187,6 +177,9 @@ def get_variant_availability(
discount = _get_total_discount(undiscounted, discounted)
+ if country is None:
+ country = settings.DEFAULT_COUNTRY
+
if local_currency:
price_local_currency = to_local_currency(discounted, local_currency)
discount_local_currency = to_local_currency(discount, local_currency)
@@ -197,10 +190,6 @@ def get_variant_availability(
is_on_sale = variant.is_visible and discount is not None
return VariantAvailability(
-<<<<<<< HEAD
-=======
- available=is_variant_in_stock(variant, country),
->>>>>>> Remove utils module from stock app
on_sale=is_on_sale,
price=discounted,
price_undiscounted=undiscounted,
diff --git a/tests/api/benchmark/test_checkout.py b/tests/api/benchmark/test_checkout.py
index 7841e0f00e..0315f0d757 100644
--- a/tests/api/benchmark/test_checkout.py
+++ b/tests/api/benchmark/test_checkout.py
@@ -9,7 +9,8 @@ from tests.api.utils import get_graphql_content
@pytest.fixture()
-def checkout_with_variant(checkout, variant):
+def checkout_with_variant(checkout, stock):
+ variant = stock.product_variant
add_variant_to_checkout(checkout, variant, 1)
checkout.save()
return checkout
diff --git a/tests/api/benchmark/test_variant.py b/tests/api/benchmark/test_variant.py
index 8c5f83d6a3..8b8c8d95be 100644
--- a/tests/api/benchmark/test_variant.py
+++ b/tests/api/benchmark/test_variant.py
@@ -77,7 +77,6 @@ def test_retrieve_variant_list(product_variant_list, api_client, count_queries):
edges {
node {
...ProductVariantFields
- stockQuantity
product {
...BasicProductFields
}
diff --git a/tests/api/test_variant.py b/tests/api/test_variant.py
index bb4ab21fc5..80da3174e8 100644
--- a/tests/api/test_variant.py
+++ b/tests/api/test_variant.py
@@ -1003,22 +1003,18 @@ def test_product_variant_bulk_create_many_errors(
variants = [
{
"sku": str(uuid4())[:12],
- "quantity": -1000,
"attributes": [{"id": size_attribute_id, "values": ["Test-value1"]}],
},
{
"sku": str(uuid4())[:12],
- "quantity": 100,
"attributes": [{"id": size_attribute_id, "values": ["Test-value4"]}],
},
{
"sku": sku,
- "quantity": 100,
"attributes": [{"id": size_attribute_id, "values": ["Test-value2"]}],
},
{
"sku": str(uuid4())[:12],
- "quantity": 100,
"attributes": [{"id": invalid_attribute_id, "values": ["Test-value3"]}],
},
]
@@ -1030,15 +1026,9 @@ def test_product_variant_bulk_create_many_errors(
)
content = get_graphql_content(response)
data = content["data"]["productVariantBulkCreate"]
- assert len(data["bulkProductErrors"]) == 3
+ assert len(data["bulkProductErrors"]) == 2
errors = data["bulkProductErrors"]
expected_errors = [
- {
- "field": "quantity",
- "index": 0,
- "code": ProductErrorCode.INVALID.name,
- "message": ANY,
- },
{
"field": "sku",
"index": 2,
diff --git a/tests/api/test_variant_pricing.py b/tests/api/test_variant_pricing.py
index f6e8b51f06..1c650f45fb 100644
--- a/tests/api/test_variant_pricing.py
+++ b/tests/api/test_variant_pricing.py
@@ -98,7 +98,7 @@ def test_get_variant_pricing_not_on_sale(api_client, product):
assert pricing["price"]["net"]["amount"] == product.price.amount
-def test_variant_pricing(variant: ProductVariant, monkeypatch, settings):
+def test_variant_pricing(variant: ProductVariant, monkeypatch, settings, stock):
taxed_price = TaxedMoney(Money("10.0", "USD"), Money("12.30", "USD"))
monkeypatch.setattr(
ExtensionsManager, "apply_taxes_to_product", Mock(return_value=taxed_price)
@@ -116,7 +116,7 @@ def test_variant_pricing(variant: ProductVariant, monkeypatch, settings):
settings.DEFAULT_COUNTRY = "PL"
settings.OPENEXCHANGERATES_API_KEY = "fake-key"
- pricing = get_variant_availability(variant, local_currency="PLN")
+ pricing = get_variant_availability(variant, local_currency="PLN", country="US")
assert pricing.price_local_currency.currency == "PLN"
pricing = get_variant_availability(variant)
diff --git a/tests/extensions/plugins/test_avatax.py b/tests/extensions/plugins/test_avatax.py
index 656c1ecc58..6190dff344 100644
--- a/tests/extensions/plugins/test_avatax.py
+++ b/tests/extensions/plugins/test_avatax.py
@@ -191,7 +191,7 @@ def test_calculate_checkout_subtotal(
taxes_in_prices,
discount_info,
checkout_with_item,
- variant,
+ stock,
monkeypatch,
site_settings,
address_usa,
@@ -199,6 +199,7 @@ def test_calculate_checkout_subtotal(
address,
settings,
):
+ variant = stock.product_variant
settings.AVATAX_USERNAME_OR_ACCOUNT = "test"
settings.AVATAX_PASSWORD_OR_LICENSE = "test"
settings.PLUGINS = ["saleor.extensions.plugins.avatax.plugin.AvataxPlugin"]
diff --git a/tests/extensions/plugins/test_vatlayer.py b/tests/extensions/plugins/test_vatlayer.py
index 4ca207de84..e5eff750cb 100644
--- a/tests/extensions/plugins/test_vatlayer.py
+++ b/tests/extensions/plugins/test_vatlayer.py
@@ -262,8 +262,9 @@ def test_calculate_checkout_subtotal(
expected_net,
expected_gross,
taxes_in_prices,
- variant,
+ stock,
):
+ variant = stock.product_variant
site_settings.include_taxes_in_prices = taxes_in_prices
site_settings.save()