Skip to content

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

Fix incorrect type definition

Maciej Korycinski2a7f13c25908
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 49774989f2..6162088be3 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple
from django.core.exceptions import ValidationError
from django.db.models import Max, Min, Sum
from django.utils import timezone
+from django_countries.fields import Country
from prices import Money, MoneyRange, TaxedMoneyRange
from ..account.models import User
@@ -558,7 +559,7 @@ def get_valid_shipping_methods_for_checkout(
checkout,
channel_id=checkout.channel_id,
price=subtotal.gross,
- country_code=country_code,
+ country_code=country_code, # type: ignore
lines=lines,
)
@@ -612,7 +613,9 @@ def get_shipping_price_estimate(
start=Money(min_price_amount, checkout.currency),
stop=Money(max_price_amount, checkout.currency),
)
- return manager.apply_taxes_to_shipping_price_range(prices, country_code)
+ return manager.apply_taxes_to_shipping_price_range(
+ prices, country_code # type: ignore
+ )
def clear_shipping_method(checkout: Checkout):
diff --git a/saleor/graphql/product/tests/test_variant_pricing.py b/saleor/graphql/product/tests/test_variant_pricing.py
index f800f29729..9b2b46da3f 100644
--- a/saleor/graphql/product/tests/test_variant_pricing.py
+++ b/saleor/graphql/product/tests/test_variant_pricing.py
@@ -1,5 +1,6 @@
from unittest.mock import Mock
+from django_countries.fields import Country
from prices import Money, TaxedMoney
from ....plugins.manager import PluginsManager
@@ -142,7 +143,7 @@ def test_variant_pricing(
discounts=[],
channel=channel_USD,
local_currency="PLN",
- country="US",
+ country=Country("US"),
)
assert pricing.price_local_currency.currency == "PLN" # type: ignore
diff --git a/saleor/product/tests/test_product_availability.py b/saleor/product/tests/test_product_availability.py
index 760513586b..7767254c88 100644
--- a/saleor/product/tests/test_product_availability.py
+++ b/saleor/product/tests/test_product_availability.py
@@ -2,6 +2,7 @@ import datetime
from decimal import Decimal
from unittest.mock import Mock
+from django_countries.fields import Country
from freezegun import freeze_time
from prices import Money, TaxedMoney, TaxedMoneyRange
@@ -29,7 +30,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):
channel=channel_USD,
collections=[],
discounts=[],
- country="PL",
+ country=Country("PL"),
)
taxed_price_range = TaxedMoneyRange(start=taxed_price, stop=taxed_price)
assert availability.price_range == taxed_price_range
@@ -50,7 +51,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):
discounts=[],
channel=channel_USD,
local_currency="PLN",
- country="PL",
+ country=Country("PL"),
)
assert availability.price_range_local_currency.start.currency == "PLN"
@@ -62,7 +63,7 @@ def test_availability(stock, monkeypatch, settings, channel_USD):
collections=[],
discounts=[],
channel=channel_USD,
- country="PL",
+ country=Country("PL"),
)
assert availability.price_range.start.tax.amount
assert availability.price_range.stop.tax.amount
@@ -91,7 +92,7 @@ def test_availability_with_all_variant_channel_listings(stock, channel_USD):
channel=channel_USD,
collections=[],
discounts=[],
- country="PL",
+ country=Country("PL"),
)
# then
@@ -120,7 +121,7 @@ def test_availability_with_missing_variant_channel_listings(stock, channel_USD):
channel=channel_USD,
collections=[],
discounts=[],
- country="PL",
+ country=Country("PL"),
)
# then
@@ -147,7 +148,7 @@ def test_availability_without_variant_channel_listings(stock, channel_USD):
channel=channel_USD,
collections=[],
discounts=[],
- country="PL",
+ country=Country("PL"),
)
# then
diff --git a/saleor/product/utils/availability.py b/saleor/product/utils/availability.py
index a26c4cd6f3..b131d3064a 100644
--- a/saleor/product/utils/availability.py
+++ b/saleor/product/utils/availability.py
@@ -3,6 +3,7 @@ from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union
import opentracing
from django.conf import settings
+from django_countries.fields import Country
from prices import MoneyRange, TaxedMoney, TaxedMoneyRange
from ...channel.models import Channel
@@ -146,10 +147,11 @@ def get_product_availability(
collections: Iterable[Collection],
discounts: Iterable[DiscountInfo],
channel: Channel,
- country: Optional[str] = None,
+ country: Optional[Country] = None,
local_currency: Optional[str] = None,
plugins: Optional["PluginsManager"] = None,
) -> ProductAvailability:
+ country = country or Country(settings.DEFAULT_COUNTRY)
with opentracing.global_tracer().start_active_span("get_product_availability"):
if not plugins:
plugins = get_plugins_manager()
@@ -223,10 +225,11 @@ def get_variant_availability(
collections: Iterable[Collection],
discounts: Iterable[DiscountInfo],
channel: Channel,
- country: Optional[str] = None,
+ country: Optional[Country] = None,
local_currency: Optional[str] = None,
plugins: Optional["PluginsManager"] = None,
) -> VariantAvailability:
+ country = country or Country(settings.DEFAULT_COUNTRY)
with opentracing.global_tracer().start_active_span("get_variant_availability"):
if not plugins:
plugins = get_plugins_manager()