Skip to content

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

GraphQL changes

Pacu279cec0f79517
diff --git a/requirements.txt b/requirements.txt
index 7b21743cae..49c9888622 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -55,7 +55,7 @@ django-storages==1.6.6
django-templated-email==2.2.0
django-versatileimagefield==1.9
django-webpack-loader==0.6.0
-django==2.1
+django==2.0.8
docutils==0.14 # via botocore
elasticsearch-dsl==5.4.0
elasticsearch==5.5.3
diff --git a/saleor/graphql/core/fields.py b/saleor/graphql/core/fields.py
index 2471efca44..24cb35de22 100644
--- a/saleor/graphql/core/fields.py
+++ b/saleor/graphql/core/fields.py
@@ -1,7 +1,9 @@
import graphene
+from django_measurement.models import MeasurementField
from django_prices.models import MoneyField, TaxedMoneyField
from graphene_django.converter import convert_django_field
+from .types.common import Weight
from .types.money import Money, TaxedMoney
@@ -13,3 +15,8 @@ def convert_field_taxed_money(field, registry=None):
@convert_django_field.register(MoneyField)
def convert_field_money(field, registry=None):
return graphene.Field(Money)
+
+
+@convert_django_field.register(MeasurementField)
+def convert_field_measurements(field, registry=None):
+ return graphene.Field(Weight)
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
index 5348338bce..9fdf84ad31 100644
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -85,3 +85,11 @@ class PermissionDisplay(graphene.ObjectType):
class SeoInput(graphene.InputObjectType):
title = graphene.String(description='SEO title.')
description = graphene.String(description='SEO description.')
+
+
+class Weight(graphene.ObjectType):
+ unit = graphene.String(description='Weight unit', required=True)
+ value = graphene.Float(description='Weight value', required=True)
+
+ class Meta:
+ description = 'Represents weight value in a specific weight unit.'
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 73054aeb81..a87aa6bd3c 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -7,6 +7,7 @@ from ....product import models
from ....product.utils.attributes import get_name_from_attributes
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
from ...core.types.common import Decimal, Error, SeoInput
+from ...shipping.types import WeightScalar
from ...core.utils import clean_seo_fields
from ...file_upload.types import Upload
from ...utils import get_attributes_dict_from_list
@@ -234,6 +235,8 @@ class ProductInput(graphene.InputObjectType):
price = Decimal(description='Product price.')
tax_rate = graphene.String(description='Tax rate.')
seo = SeoInput(description='Search engine optimization fields.')
+ weight = WeightScalar(
+ description='Weight of the Product.', required=False)
class ProductCreate(ModelMutation):
@@ -321,6 +324,8 @@ class ProductVariantInput(graphene.InputObjectType):
description="""Determines if the inventory of this variant should
be tracked. If false, the quantity won't change when customers
buy this item.""")
+ weight = WeightScalar(
+ description='Weight of the Product Variant.', required=False)
class ProductVariantCreate(ModelMutation):
@@ -412,6 +417,7 @@ class ProductTypeInput(graphene.InputObjectType):
is_shipping_required = graphene.Boolean(
description="""Determines if shipping is required for products
of this variant.""")
+ weight = WeightScalar(description='Weight of the ProductType items.')
class ProductTypeCreate(ModelMutation):
diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.py
index 3817ca9e14..043cdf47ea 100644
--- a/saleor/graphql/shipping/mutations.py
+++ b/saleor/graphql/shipping/mutations.py
@@ -3,12 +3,27 @@ import graphene
from ...shipping import models
from ..core.mutations import ModelDeleteMutation, ModelMutation
from ..core.types.common import Decimal
+from .types import ShippingMethodTypeEnum, WeightScalar
class ShippingPriceInput(graphene.InputObjectType):
name = graphene.String(
description='Name of the shipping method.')
price = Decimal(description='Shipping price of the shipping method.')
+ minimum_order_price = Decimal(
+ description='Minimum order price to use this shipping method',
+ required=False)
+ maximum_order_price = Decimal(
+ description='Maximum order price to use this shipping method',
+ required=False)
+ minimum_order_weight = WeightScalar(
+ description='Minimum order price to use this shipping method',
+ required=False)
+ maximum_order_weight = WeightScalar(
+ description='Maximum order price to use this shipping method',
+ required=False)
+ type = ShippingMethodTypeEnum(
+ description='Shipping type: price or weight based.')
shipping_zone = graphene.ID(
description='Related shipping zone name.', name='shippingZone')
@@ -66,7 +81,47 @@ class ShippingZoneDelete(ModelDeleteMutation):
return user.has_perm('shipping.manage_shipping')
-class ShippingPriceCreate(ModelMutation):
+class ShippingPriceMixin(object):
+
+ @classmethod
+ def clean_input(cls, info, instance, input, errors):
+ cleaned_input = super().clean_input(info, instance, input, errors)
+ type = cleaned_input.get('type', None)
+ if not type:
+ return cleaned_input
+
+ field_errors = []
+ if type == ShippingMethodTypeEnum.PRICE_BASED:
+ min_price = cleaned_input.get('minimum_order_price', None)
+ max_price = cleaned_input.get('maximum_order_price', None)
+ if min_price is None:
+ field_errors.append((
+ 'minimum_order_price',
+ 'Minimum order price is required'
+ ' for Price Based shipping.'))
+ elif max_price is not None and max_price < min_price:
+ field_errors.append((
+ 'maximum_order_price',
+ 'Maximum order price cannot be smaller than the minimum.'))
+ else:
+ min_weight = cleaned_input.get('minimum_order_weight', None)
+ max_weight = cleaned_input.get('maximum_order_weight', None)
+ if min_weight is None:
+ field_errors.append((
+ 'minimum_order_weight',
+ 'Minimum order weight is required for'
+ ' Weight Based shipping.'))
+ elif max_weight is not None and max_weight < min_price:
+ field_errors.append((
+ 'maximum_order_weight',
+ 'Maximum order weight cannot be'
+ ' smaller than the minimum.'))
+ for err in field_errors:
+ cls.add_error(errors, field=err[0], message=err[1])
+ return cleaned_input
+
+
+class ShippingPriceCreate(ShippingPriceMixin, ModelMutation):
class Arguments:
input = ShippingPriceInput(
description='Fields required to create a shipping price',
@@ -81,7 +136,7 @@ class ShippingPriceCreate(ModelMutation):
return user.has_perm('shipping.manage_shipping')
-class ShippingPriceUpdate(ModelMutation):
+class ShippingPriceUpdate(ShippingPriceMixin, ModelMutation):
class Arguments:
id = graphene.ID(
description='ID of a shipping price to update.', required=True)
diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.py
index 191aba594c..67fab3d4e1 100644
--- a/saleor/graphql/shipping/types.py
+++ b/saleor/graphql/shipping/types.py
@@ -2,9 +2,12 @@ import graphene
from graphene import relay
from graphene_django import DjangoObjectType
+from ...shipping import ShippingMethodType
from ...shipping import models
from ..core.types.common import CountableDjangoObjectType
from ..core.types.money import MoneyRange
+from graphene.types import Scalar
+from measurement.measures import Mass
class ShippingZone(CountableDjangoObjectType):
@@ -21,8 +24,7 @@ class ShippingZone(CountableDjangoObjectType):
filter_fields = {
'name': ['icontains'],
'countries': ['icontains'],
- 'shipping_methods__price': ['gte', 'lte']
- }
+ 'shipping_methods__price': ['gte', 'lte']}
def resolve_price_range(self, info):
return self.price_range
@@ -31,9 +33,36 @@ class ShippingZone(CountableDjangoObjectType):
return self.countries
+class WeightScalar(Scalar):
+
+ @staticmethod
+ def parse_value(value):
+ """Excepts value to be a string "amount unit"
+ separated by a single space.
+ """
+ amount, unit = value.split(' ')
+ return Mass(**{unit: amount})
+
+ @staticmethod
+ def serialize(mass):
+ if isinstance(mass, Mass):
+ return str(mass)
+ return None
+
+ @staticmethod
+ def parse_literal(node):
+ return node
+
+
class ShippingMethod(DjangoObjectType):
+
class Meta:
description = 'Shipping method within a shipping zone.'
model = models.ShippingMethod
interfaces = [relay.Node]
exclude_fields = ['shipping_zone', 'orders']
+
+
+class ShippingMethodTypeEnum(graphene.Enum):
+ PRICE_BASED = ShippingMethodType.PRICE_BASED
+ WEIGHT_BASED = ShippingMethodType.WEIGHT_BASED
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 6bb0df8d1f..35db6eac29 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -83,11 +83,11 @@ def update_order_prices(order, discounts):
line.unit_price = line.variant.get_price(discounts, taxes)
line.tax_rate = get_tax_rate_by_name(
line.variant.product.tax_rate, taxes)
- line.save(update_fields=['unit_price', 'tax_rate'])
+ line.save()
if order.shipping_method:
order.shipping_price = order.shipping_method.get_total_price(taxes)
- order.save(update_fields=['shipping_price'])
+ order.save()
recalculate_order(order)
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index c2399f4c8a..14c8ab0ba5 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -99,13 +99,14 @@ class ShippingMethod(models.Model):
on_delete=models.CASCADE)
minimum_order_price = MoneyField(
currency=settings.DEFAULT_CURRENCY, max_digits=12,
- decimal_places=settings.DEFAULT_DECIMAL_PLACES, default=0, blank=True)
+ decimal_places=settings.DEFAULT_DECIMAL_PLACES, default=0, blank=True,
+ null=True)
maximum_order_price = MoneyField(
currency=settings.DEFAULT_CURRENCY, max_digits=12,
decimal_places=settings.DEFAULT_DECIMAL_PLACES, blank=True, null=True)
minimum_order_weight = MeasurementField(
measurement=Weight, unit_choices=settings.DEFAULT_WEIGHT_UNITS,
- default=0)
+ default=0, blank=True, null=True)
maximum_order_weight = MeasurementField(
measurement=Weight, unit_choices=settings.DEFAULT_WEIGHT_UNITS,
blank=True, null=True)
diff --git a/templates/dashboard/product/product_type/form.html b/templates/dashboard/product/product_type/form.html
index 12f037335a..790988e9e1 100644
--- a/templates/dashboard/product/product_type/form.html
+++ b/templates/dashboard/product/product_type/form.html
@@ -98,6 +98,14 @@
{{ form.tax_rate|materializecss }}
</div>
</div>
+ <div class="row">
+ <div class="col s12">
+ <span class="card-title">{% trans "Shipping" %}</span>
+ </div>
+ <div class="col s12 m8">
+ {{ form.weight|materializecss }}
+ </div>
+ </div>
</div>
{% if perms.product.manage_products %}
<div class="card-action right-align">
diff --git a/tests/api/test_shipping_method.py b/tests/api/test_shipping_method.py
index d270c0760b..a9307b212f 100644
--- a/tests/api/test_shipping_method.py
+++ b/tests/api/test_shipping_method.py
@@ -4,6 +4,8 @@ import graphene
import pytest
from django.shortcuts import reverse
from tests.utils import get_graphql_content
+from saleor.graphql.shipping.types import ShippingMethodTypeEnum
+from saleor.shipping import ShippingMethodType
def test_shipping_zone_query(user_api_client, shipping_zone):
@@ -136,30 +138,37 @@ def test_delete_shipping_zone(admin_api_client, shipping_zone):
def test_create_shipping_method(admin_api_client, shipping_zone):
query = """
- mutation createShippingPrice(
- $name: String!, $price: Decimal, $shippingZone: ID!){
- shippingPriceCreate(
- input: {
- name: $name, price: $price,
- shippingZone: $shippingZone}) {
+ mutation createShipipngPrice(
+ $type: ShippingMethodTypeEnum, $name: String!, $price: Decimal,
+ $shippingZone: ID!, $minimumOrderPrice: Decimal) {
+ shippingPriceCreate(input: {
+ name: $name, price: $price, shippingZone: $shippingZone,
+ minimumOrderPrice: $minimumOrderPrice, type: $type}) {
shippingMethod {
name
price {
amount
}
+ minimumOrderPrice {
+ amount
+ }
+ type
}
}
}
"""
name = 'DHL'
price = '12.34'
+ order_price = '13.00'
shipping_zone_id = graphene.Node.to_global_id(
'ShippingZone', shipping_zone.pk)
variables = json.dumps(
{
'shippingZone': shipping_zone_id,
'name': name,
- 'price': price})
+ 'price': price,
+ 'minimumOrderPrice': order_price,
+ 'type': ShippingMethodTypeEnum.PRICE_BASED.name})
response = admin_api_client.post(
reverse('api'), {'query': query, 'variables': variables})
content = get_graphql_content(response)
@@ -167,23 +176,36 @@ def test_create_shipping_method(admin_api_client, shipping_zone):
data = content['data']['shippingPriceCreate']['shippingMethod']
assert data['name'] == name
assert data['price']['amount'] == float(price)
+ assert data['minimumOrderPrice']['amount'] == float(order_price)
+ assert data['type'] == ShippingMethodType.PRICE_BASED.upper()
-def test_update_shipping_method(admin_api_client, shipping_zone, shipping_method):
+def test_update_shipping_method(admin_api_client, shipping_zone):
query = """
mutation updateShippingPrice(
- $id: ID!, $price: Decimal, $shippingZone: ID!) {
+ $id: ID!, $price: Decimal, $shippingZone: ID!,
+ $type: ShippingMethodTypeEnum!, $minimumOrderPrice: Decimal) {
shippingPriceUpdate(
- id: $id, input: {price: $price, shippingZone: $shippingZone}) {
+ id: $id, input: {
+ price: $price, shippingZone: $shippingZone,
+ type: $type, minimumOrderPrice: $minimumOrderPrice}) {
+ errors {
+ field
+ message
+ }
shippingMethod {
price {
amount
}
+ minimumOrderPrice {
+ amount
+ }
+ type
}
}
}
"""
- # shipping_method = shipping_zone.shipping_methods.first()
+ shipping_method = shipping_zone.shipping_methods.first()
price = '12.34'
assert not str(shipping_method.price) == price
shipping_zone_id = graphene.Node.to_global_id(
@@ -194,7 +216,9 @@ def test_update_shipping_method(admin_api_client, shipping_zone, shipping_method
{
'shippingZone': shipping_zone_id,
'price': price,
- 'id': shipping_method_id})
+ 'id': shipping_method_id,
+ 'minimumOrderPrice': '12.00',
+ 'type': ShippingMethodTypeEnum.PRICE_BASED.name})
response = admin_api_client.post(
reverse('api'), {'query': query, 'variables': variables})
content = get_graphql_content(response)
@@ -203,6 +227,10 @@ def test_update_shipping_method(admin_api_client, shipping_zone, shipping_method
assert data['price']['amount'] == float(price)
+def test_create_weight_based_shipping_method():
+ pass
+
+
def test_delete_shipping_method(admin_api_client, shipping_method):
query = """
mutation deleteShippingPrice($id: ID!) {
diff --git a/tests/api/test_variant.py b/tests/api/test_variant.py
index 1461026c69..3d047feffa 100644
--- a/tests/api/test_variant.py
+++ b/tests/api/test_variant.py
@@ -71,6 +71,7 @@ def test_create_variant(admin_api_client, product, product_type):
$costPrice: Decimal,
$quantity: Int!,
$attributes: [AttributeValueInput],
+ $weight: WeightScalar,
$trackInventory: Boolean!) {
productVariantCreate(
input: {
@@ -80,7 +81,8 @@ def test_create_variant(admin_api_client, product, product_type):
costPrice: $costPrice,
quantity: $quantity,
attributes: $attributes,
- trackInventory: $trackInventory
+ trackInventory: $trackInventory,
+ weight: $weight
}) {
productVariant {
name
@@ -104,6 +106,10 @@ def test_create_variant(admin_api_client, product, product_type):
amount
localized
}
+ weight {
+ value
+ unit
+ }
}
}
}
@@ -123,6 +129,7 @@ def test_create_variant(admin_api_client, product, product_type):
'quantity': quantity,
'costPrice': cost_price,
'priceOverride': price_override,
+ 'weight': '10 kg',
'attributes': [
{'slug': variant_slug, 'value': variant_value}],
'trackInventory': True})
@@ -138,6 +145,8 @@ def test_create_variant(admin_api_client, product, product_type):
assert data['sku'] == sku
assert data['attributes'][0]['attribute']['slug'] == variant_slug
assert data['attributes'][0]['value']['slug'] == variant_value
+ assert data['weight']['unit'] == 'kg'
+ assert data['weight']['value'] == float(10)
def test_update_product_variant(admin_api_client, product):
diff --git a/tests/conftest.py b/tests/conftest.py
index 99072a9b48..52b3e49567 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -35,7 +35,7 @@ from saleor.product.models import (
ProductAttributeTranslation, ProductImage, ProductTranslation, ProductType,
ProductVariant)
from saleor.shipping.models import (
- ShippingZone, ShippingMethod, ShippingMethod, ShippingZone)
+ ShippingMethod, ShippingMethodType, ShippingZone)
from saleor.site.models import AuthorizationKey, SiteSettings
@@ -217,16 +217,16 @@ def shipping_zone(db): # pylint: disable=W0613
shipping_zone = ShippingZone.objects.create(
name='Europe', countries=[code for code, name in countries])
shipping_zone.shipping_methods.create(
- name='DHL', price=10)
+ name='DHL', minimum_order_price=0, type=ShippingMethodType.PRICE_BASED,
+ price=10, shipping_zone=shipping_zone)
return shipping_zone
@pytest.fixture
def shipping_method(shipping_zone):
return ShippingMethod.objects.create(
- name='DHL',
- price=10,
- shipping_zone=shipping_zone)
+ name='DHL', minimum_order_price=0, type=ShippingMethodType.PRICE_BASED,
+ price=10, shipping_zone=shipping_zone)
@pytest.fixture
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index ce3399b66d..c414aa7531 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -290,7 +290,8 @@ def test_view_product_type_create(
'name': 'Testing Type',
'product_attributes': [color_attribute.pk],
'variant_attributes': [size_attribute.pk],
- 'has_variants': True}
+ 'has_variants': True,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
@@ -308,7 +309,8 @@ def test_view_product_type_create_invalid(
'name': 'Testing Type',
'product_attributes': [size_attribute.pk],
'variant_attributes': [color_attribute.pk, size_attribute.pk],
- 'has_variants': True}
+ 'has_variants': True,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
@@ -323,7 +325,8 @@ def test_view_product_type_create_missing_variant_attributes(
'name': 'Testing Type',
'product_attributes': [color_attribute.pk],
'variant_attributes': [size_attribute.pk],
- 'has_variants': False}
+ 'has_variants': False,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
assert response.status_code == 200
@@ -337,7 +340,8 @@ def test_view_product_type_create_variantless(
'name': 'Testing Type',
'product_attributes': [color_attribute.pk],
'variant_attributes': [],
- 'has_variants': False}
+ 'has_variants': False,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
assert response.status_code == 302
@@ -354,7 +358,8 @@ def test_view_product_type_create_variantless_invalid(
'name': 'Testing Type',
'product_attributes': [color_attribute.pk],
'variant_attributes': [size_attribute.pk],
- 'has_variants': False}
+ 'has_variants': False,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
assert response.status_code == 200
@@ -377,7 +382,8 @@ def test_view_product_type_edit_to_no_variants_valid(admin_client, product):
'pk', flat=True),
'variant_attributes': product_type.variant_attributes.values_list(
'pk', flat=True),
- 'has_variants': False}
+ 'has_variants': False,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
@@ -406,7 +412,8 @@ def test_view_product_type_edit_to_no_variants_invalid(admin_client, product):
'pk', flat=True),
'variant_attributes': product_type.variant_attributes.values_list(
'pk', flat=True),
- 'has_variants': False}
+ 'has_variants': False,
+ 'weight_0': ['3.47'], 'weight_1': ['kg']}
response = admin_client.post(url, data)
diff --git a/tests/test_cart.py b/tests/test_cart.py
index a53a66c772..e2ed88edfe 100644
--- a/tests/test_cart.py
+++ b/tests/test_cart.py
@@ -627,9 +627,11 @@ def test_get_or_create_db_cart(customer_user, db, rf):
def test_get_cart_data(request_cart_with_item, shipping_zone, vatlayer):
- shipment_option = shipping_price_estimate('PL', vatlayer)
+ cart = request_cart_with_item
+ shipment_option = shipping_price_estimate(
+ cart.get_subtotal().gross, cart.get_total_weight(), 'PL', vatlayer)
cart_data = utils.get_cart_data(
- request_cart_with_item, shipment_option, 'USD', None, vatlayer)
+ cart, shipment_option, 'USD', None, vatlayer)
assert cart_data['cart_total'] == TaxedMoney(
net=Money('8.13', 'USD'), gross=Money(10, 'USD'))
assert cart_data['total_with_shipping'].start == TaxedMoney(
@@ -637,9 +639,11 @@ def test_get_cart_data(request_cart_with_item, shipping_zone, vatlayer):
def test_get_cart_data_no_shipping(request_cart_with_item, vatlayer):
- shipment_option = shipping_price_estimate('PL', vatlayer)
+ cart = request_cart_with_item
+ shipment_option = shipping_price_estimate(
+ cart.get_subtotal().gross, cart.get_total_weight(), 'PL', vatlayer)
cart_data = utils.get_cart_data(
- request_cart_with_item, shipment_option, 'USD', None, vatlayer)
+ cart, shipment_option, 'USD', None, vatlayer)
cart_total = cart_data['cart_total']
assert cart_total == TaxedMoney(
net=Money('8.13', 'USD'), gross=Money(10, 'USD'))
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 4451193a96..5a4f3be94f 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -539,6 +539,7 @@ def test_get_discount_for_cart_shipping_voucher(
subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
shipping_total = TaxedMoney(
net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))
+ #FIXME below should be the cart not the mock
cart = Mock(
get_subtotal=Mock(return_value=subtotal),
is_shipping_required=Mock(return_value=True),
@@ -572,21 +573,24 @@ def test_get_discount_for_cart_shipping_voucher(
DiscountValueType.FIXED, [], 5, Money(2, 'USD'),
'This offer is only valid for orders over $5.00.')])
def test_get_discount_for_cart_shipping_voucher_not_applicable(
- is_shipping_required, shipping_method, discount_value,
+ is_shipping_required, shipping_method, discount_value, cart_with_item,
discount_type, countries, min_amount_spent, subtotal, error_msg):
- subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)
- cart = Mock(
- get_subtotal=Mock(return_value=subtotal_price),
- is_shipping_required=Mock(return_value=is_shipping_required),
- shipping_method=shipping_method)
+ variant = cart_with_item.lines.first().variant
+ variant.price_override = subtotal
+ variant.save()
+ cart_with_item.is_shipping_required = is_shipping_required
+ cart_with_item.shipping_method = shipping_method
+ cart_with_item.save()
voucher = Voucher(
code='unique', type=VoucherType.SHIPPING,
discount_value_type=discount_type,
discount_value=discount_value,
- min_amount_spent=Money(min_amount_spent, 'USD') if min_amount_spent is not None else None,
+ min_amount_spent=(
+ Money(min_amount_spent, 'USD')
+ if min_amount_spent is not None else None),
countries=countries)
with pytest.raises(NotApplicable) as e:
- get_voucher_discount_for_cart(voucher, cart)
+ get_voucher_discount_for_cart(voucher, cart_with_item)
assert str(e.value) == error_msg