Skip to content

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

Move tax_rate to meta field

Maciej Korycinski3bee42b5748b
diff --git a/saleor/core/taxes/avatax/interface.py b/saleor/core/taxes/avatax/interface.py
index f5e9850c98..9b83e69a27 100644
--- a/saleor/core/taxes/avatax/interface.py
+++ b/saleor/core/taxes/avatax/interface.py
@@ -185,4 +185,4 @@ def get_tax_from_object_meta(obj: Union["Product", "ProductType"]) -> TaxType:
return TaxType(code="", description="")
tax = obj.meta.get("taxes", {}).get(META_FIELD, {})
- return TaxType(code=tax.get("code", ""), description=tax.get("description"))
+ return TaxType(code=tax.get("code", ""), description=tax.get("description", ""))
diff --git a/saleor/core/taxes/vatlayer/interface.py b/saleor/core/taxes/vatlayer/interface.py
index a97a5f3250..6aca7810f1 100644
--- a/saleor/core/taxes/vatlayer/interface.py
+++ b/saleor/core/taxes/vatlayer/interface.py
@@ -85,7 +85,10 @@ def apply_taxes_to_variant(
taxes = None
if variant.product.charge_taxes and country:
taxes = get_taxes_for_country(country)
- tax_rate = variant.product.tax_rate or variant.product.product_type.tax_rate
+ product_tax_rate = get_tax_from_object_meta(variant.product).code
+ tax_rate = (
+ product_tax_rate or get_tax_from_object_meta(variant.product.product_type).code
+ )
return apply_tax_to_price(taxes, tax_rate, price)
@@ -95,7 +98,8 @@ def apply_taxes_to_product(
taxes = None
if product.charge_taxes and country:
taxes = get_taxes_for_country(country)
- tax_rate = product.tax_rate or product.product_type.tax_rate
+ product_tax_rate = get_tax_from_object_meta(product).code
+ tax_rate = product_tax_rate or get_tax_from_object_meta(product.product_type).code
return apply_tax_to_price(taxes, tax_rate, price)
@@ -121,6 +125,6 @@ def assign_tax_to_object_meta(obj: Union["Product", "ProductType"], tax_code: st
def get_tax_from_object_meta(obj: Union["Product", "ProductType"]) -> TaxType:
if not hasattr(obj, "meta"):
return TaxType(code="", description="")
- tax = obj.meta.get("taxes", {}).get(META_FIELD)
+ tax = obj.meta.get("taxes", {}).get(META_FIELD, {})
- return TaxType(code=tax.get("code", ""), description=tax.get("description"))
+ return TaxType(code=tax.get("code", ""), description=tax.get("description", ""))
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 0a3de29f98..e48b2cc348 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -10,7 +10,7 @@ from django.utils.translation import pgettext_lazy
from mptt.forms import TreeNodeChoiceField
from ...core.taxes import include_taxes_in_prices
-from ...core.taxes.interface import get_tax_rate_type_choices
+from ...core.taxes.interface import get_tax_from_object_meta, get_tax_rate_type_choices
from ...core.weight import WeightField
from ...product.models import (
Attribute,
@@ -278,7 +278,10 @@ class ProductForm(forms.ModelForm, AttributesMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
product_type = self.instance.product_type
- self.initial["tax_rate"] = self.instance.tax_rate or product_type.tax_rate
+ product_tax_rate = get_tax_from_object_meta(self.instance).code
+ self.initial["tax_rate"] = (
+ product_tax_rate or get_tax_from_object_meta(product_type).code
+ )
self.available_attributes = product_type.product_attributes.prefetch_related(
"values"
).all()
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 240fac7072..1a9d31c2c8 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -7,6 +7,7 @@ from django.template.defaultfilters import slugify
from graphene.types import InputObjectType
from ....core.taxes import interface as tax_interface
+from ....core.taxes.vatlayer import interface as vatlayer_interface
from ....product import models
from ....product.tasks import update_variants_names
from ....product.thumbnails import (
@@ -359,7 +360,11 @@ class ProductInput(graphene.InputObjectType):
Product price. Note: this field is deprecated, use basePrice instead."""
)
base_price = Decimal(description="Product price.")
- tax_rate = graphene.String(description="Tax rate for enabled tax gateway")
+ tax_rate = TaxRateType(
+ description="Tax rate.",
+ deprecation_reason=("taxRate is deprecated, Use taxCode"),
+ )
+ tax_code = graphene.String(description="Tax rate for enabled tax gateway")
seo = SeoInput(description="Search engine optimization fields.")
weight = WeightScalar(description="Weight of the Product.", required=False)
sku = graphene.String(
@@ -417,9 +422,14 @@ class ProductCreate(ModelMutation):
if price is not None:
cleaned_input["price"] = price
+ # FIXME tax_rate logic should be dropped after we remove tax_rate from input
tax_rate = cleaned_input.pop("tax_rate", "")
if tax_rate:
- tax_interface.assign_tax_to_object_meta(instance, tax_rate)
+ vatlayer_interface.assign_tax_to_object_meta(instance, tax_rate)
+
+ tax_code = cleaned_input.pop("tax_code", "")
+ if tax_code:
+ tax_interface.assign_tax_to_object_meta(instance, tax_code)
if attributes and product_type:
qs = product_type.product_attributes.prefetch_related("values")
@@ -667,7 +677,11 @@ class ProductTypeInput(graphene.InputObjectType):
description="Determines if products are digital.", required=False
)
weight = WeightScalar(description="Weight of the ProductType items.")
- tax_rate = TaxRateType(description="A type of goods.")
+ tax_rate = TaxRateType(
+ description="Tax rate.",
+ deprecation_reason=("taxRate is deprecated, Use taxCode"),
+ )
+ tax_code = graphene.String(description="Tax rate for enabled tax gateway")
class ProductTypeCreate(ModelMutation):
@@ -681,6 +695,21 @@ class ProductTypeCreate(ModelMutation):
model = models.ProductType
permissions = ("product.manage_products",)
+ @classmethod
+ def clean_input(cls, info, instance, data):
+ cleaned_input = super().clean_input(info, instance, data)
+
+ # FIXME tax_rate logic should be dropped after we remove tax_rate from input
+ tax_rate = cleaned_input.pop("tax_rate", "")
+ if tax_rate:
+ vatlayer_interface.assign_tax_to_object_meta(instance, tax_rate)
+
+ tax_code = cleaned_input.pop("tax_code", "")
+ if tax_code:
+ tax_interface.assign_tax_to_object_meta(instance, tax_code)
+
+ return cleaned_input
+
@classmethod
def _save_m2m(cls, info, instance, cleaned_data):
super()._save_m2m(info, instance, cleaned_data)
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index 157780d91d..7c40c6eed6 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -6,6 +6,7 @@ from graphql.error import GraphQLError
from graphql_jwt.decorators import permission_required
from ....core.taxes import interface as tax_interface
+from ....core.taxes.vatlayer import interface as vatlayer_interface
from ....product import models
from ....product.templatetags.product_images import (
get_product_image_thumbnail,
@@ -373,6 +374,14 @@ class Product(CountableDjangoObjectType):
description="The product's default base price.",
deprecation_reason=("Has been replaced by 'basePrice'"),
)
+ tax_rate = TaxRateType(
+ description="A type of tax rate.",
+ deprecation_reason=(
+ "taxRate is deprecated. Use tax_type to obtain tax_code for given tax "
+ "gateway"
+ ),
+ )
+
tax_type = graphene.Field(
TaxType, description="A type of tax. Assigned by enabled tax gateway"
)
@@ -439,6 +448,12 @@ class Product(CountableDjangoObjectType):
"weight",
]
+ @staticmethod
+ def resolve_tax_rate(root: models.ProductType, info, **_kwargs):
+ # FIXME this resolver should be dropped after we drop tax_rate from API
+ tax_rate = vatlayer_interface.get_tax_from_object_meta(root).code
+ return tax_rate or None
+
@staticmethod
def resolve_tax_type(root: models.Product, _info):
tax_data = tax_interface.get_tax_from_object_meta(root)
@@ -472,7 +487,7 @@ class Product(CountableDjangoObjectType):
@staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=("variants", "collections"),
- only=["publication_date", "charge_taxes", "price", "tax_rate"],
+ only=["publication_date", "charge_taxes", "price", "meta"],
)
def resolve_pricing(root: models.Product, info):
context = info.context
@@ -495,7 +510,7 @@ class Product(CountableDjangoObjectType):
@staticmethod
@gql_optimizer.resolver_hints(
prefetch_related=("variants", "collections"),
- only=["publication_date", "charge_taxes", "price", "tax_rate"],
+ only=["publication_date", "charge_taxes", "price", "meta"],
)
def resolve_price(root: models.Product, info):
price_range = root.get_price_range(info.context.discounts)
@@ -586,6 +601,12 @@ class ProductType(CountableDjangoObjectType):
"weight",
]
+ @staticmethod
+ def resolve_tax_rate(root: models.ProductType, info, **_kwargs):
+ # FIXME this resolver should be dropped after we drop tax_rate from API
+ tax_rate = vatlayer_interface.get_tax_from_object_meta(root).code
+ return tax_rate or None
+
@staticmethod
@gql_optimizer.resolver_hints(prefetch_related="product_attributes")
def resolve_product_attributes(root: models.ProductType, *_args, **_kwargs):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 0011342135..2a94683973 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2134,6 +2134,7 @@ type Product implements Node {
isAvailable: Boolean
basePrice: Money
price: Money @deprecated(reason: "Has been replaced by 'basePrice'")
+ taxRate: TaxRateType @deprecated(reason: "taxRate is deprecated. Use tax_type to obtain tax_code for given tax gateway")
taxType: TaxType
attributes: [SelectedAttribute!]!
purchaseCost: MoneyRange
@@ -2184,7 +2185,8 @@ input ProductCreateInput {
name: String
price: Decimal
basePrice: Decimal
- taxRate: String
+ taxRate: TaxRateType
+ taxCode: String
seo: SeoInput
weight: WeightScalar
sku: String
@@ -2267,7 +2269,8 @@ input ProductInput {
name: String
price: Decimal
basePrice: Decimal
- taxRate: String
+ taxRate: TaxRateType
+ taxCode: String
seo: SeoInput
weight: WeightScalar
sku: String
@@ -2374,6 +2377,7 @@ input ProductTypeInput {
isDigital: Boolean
weight: WeightScalar
taxRate: TaxRateType
+ taxCode: String
}
type ProductTypeUpdate {
diff --git a/saleor/product/migrations/0095_auto_20190618_0842.py b/saleor/product/migrations/0095_auto_20190618_0842.py
new file mode 100644
index 0000000000..8776b011ae
--- /dev/null
+++ b/saleor/product/migrations/0095_auto_20190618_0842.py
@@ -0,0 +1,42 @@
+from django.db import migrations
+
+
+def move_tax_rate_to_meta(apps, schema_editor):
+ ProductType = apps.get_model("product", "ProductType")
+ Product = apps.get_model("product", "Product")
+ product_types = ProductType.objects.filter(tax_rate__isnull=False).exclude(
+ tax_rate=""
+ )
+ products = Product.objects.filter(tax_rate__isnull=False).exclude(tax_rate="")
+ product_types_list = []
+ for product_type in product_types:
+ if "taxes" not in product_type.meta:
+ product_type.meta["taxes"] = {}
+ product_type.meta["taxes"]["vatlayer"] = {
+ "code": product_type.tax_rate,
+ "description": product_type.tax_rate,
+ }
+ product_types_list.append(product_type)
+ ProductType.objects.bulk_update(product_types_list, ["meta"])
+
+ product_list = []
+ for product in products:
+ if "taxes" not in product.meta:
+ product.meta["taxes"] = {}
+ product.meta["taxes"]["vatlayer"] = {
+ "code": product.tax_rate,
+ "description": product.tax_rate,
+ }
+ product_list.append(product)
+ Product.objects.bulk_update(product_list, ["meta"])
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("product", "0094_auto_20190618_0430")]
+
+ operations = [
+ migrations.RunPython(move_tax_rate_to_meta),
+ migrations.RemoveField(model_name="product", name="tax_rate"),
+ migrations.RemoveField(model_name="producttype", name="tax_rate"),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index a4252cc3de..ac447e8beb 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -20,7 +20,6 @@ from prices import MoneyRange
from text_unidecode import unidecode
from versatileimagefield.fields import PPOIField, VersatileImageField
-from ..core import TaxRateType
from ..core.exceptions import InsufficientStock
from ..core.models import PublishableModel, PublishedQuerySet, SortableModel
from ..core.utils import build_absolute_uri
@@ -88,7 +87,6 @@ class ProductType(models.Model):
is_shipping_required = models.BooleanField(default=True)
is_digital = models.BooleanField(default=False)
# FIXME This should be moved to meta
- tax_rate = models.CharField(max_length=128, choices=TaxRateType.CHOICES)
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES, default=zero_weight
)
@@ -138,7 +136,6 @@ class Product(SeoModel, PublishableModel):
updated_at = models.DateTimeField(auto_now=True, null=True)
charge_taxes = models.BooleanField(default=True)
# FIXME This should be moved to meta
- tax_rate = models.CharField(max_length=128, blank=True, choices=TaxRateType.CHOICES)
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES, blank=True, null=True
)
diff --git a/saleor/product/utils/variants_picker.py b/saleor/product/utils/variants_picker.py
index 15844cad7e..0bb6a55295 100644
--- a/saleor/product/utils/variants_picker.py
+++ b/saleor/product/utils/variants_picker.py
@@ -3,7 +3,11 @@ from collections import defaultdict
from django_prices.templatetags import prices_i18n
from ...core.taxes import display_gross_prices
-from ...core.taxes.interface import apply_taxes_to_variant, show_taxes_on_storefront
+from ...core.taxes.interface import (
+ apply_taxes_to_variant,
+ get_tax_from_object_meta,
+ show_taxes_on_storefront,
+)
from ...core.taxes.vatlayer import get_tax_rate_by_name
from ...core.utils import to_local_currency
from ...seo.schema.product import variant_json_ld
@@ -72,7 +76,7 @@ def get_variant_picker_data(
data["availability"] = {
"discount": price_as_dict(availability.discount),
# FIXME this should use plugin hooks after we will introduce plugin architecure.
- "taxRate": get_tax_rate_by_name(product.tax_rate, taxes),
+ "taxRate": get_tax_rate_by_name(get_tax_from_object_meta(product).code, taxes),
"priceRange": price_range_as_dict(availability.price_range),
"priceRangeUndiscounted": price_range_as_dict(
availability.price_range_undiscounted
diff --git a/saleor/static/populatedb_data.json b/saleor/static/populatedb_data.json
index 7236213fd3..61ce1eef09 100644
--- a/saleor/static/populatedb_data.json
+++ b/saleor/static/populatedb_data.json
@@ -102,7 +102,7 @@
"name": "Paint",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -113,7 +113,7 @@
"name": "Music",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.2 kg"
}
},
@@ -124,7 +124,7 @@
"name": "Juice",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -135,7 +135,7 @@
"name": "Wine",
"has_variants": false,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -146,7 +146,7 @@
"name": "Beer",
"has_variants": false,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -157,7 +157,7 @@
"name": "Cushion",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.5 kg"
}
},
@@ -168,7 +168,7 @@
"name": "Shoe",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -179,7 +179,7 @@
"name": "Top (clothing)",
"has_variants": true,
"is_shipping_required": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -213,7 +213,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:35.666Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -247,7 +247,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:35.878Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -281,7 +281,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:36.096Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -315,7 +315,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:36.309Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -349,7 +349,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:36.514Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -383,7 +383,7 @@
"attributes": "{\"16\": \"49\"}",
"updated_at": "2019-03-06T12:47:36.727Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -417,7 +417,7 @@
"attributes": "{\"16\": \"3\"}",
"updated_at": "2019-03-06T12:47:36.885Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -451,7 +451,7 @@
"attributes": "{\"16\": \"52\"}",
"updated_at": "2019-03-06T12:47:37.040Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -485,7 +485,7 @@
"attributes": "{\"16\": \"50\"}",
"updated_at": "2019-03-06T12:47:37.201Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -519,7 +519,7 @@
"attributes": "{\"16\": \"1\"}",
"updated_at": "2019-03-06T12:47:37.363Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -553,7 +553,7 @@
"attributes": "{\"16\": \"2\"}",
"updated_at": "2019-03-06T12:47:37.517Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -587,7 +587,7 @@
"attributes": "{\"16\": \"54\"}",
"updated_at": "2019-03-06T12:47:37.679Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -621,7 +621,7 @@
"attributes": "{\"16\": \"53\"}",
"updated_at": "2019-03-06T12:47:37.844Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -655,7 +655,7 @@
"attributes": "{\"16\": \"51\"}",
"updated_at": "2019-03-06T12:47:38.007Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -689,7 +689,7 @@
"attributes": "{\"20\": \"67\"}",
"updated_at": "2019-03-06T12:47:38.171Z",
"charge_taxes": true,
- "tax_rate": "",
+ "meta": {"taxes":{"vatlayer": ""}},
"weight": "0.0 kg"
}
},
@@ -723,7 +723,7 @@
"attributes": "{\"20\": \"67\"}",
"updated_at": "2019-03-06T12:47:38.362Z",
"charge_taxes": true,
- "tax_rate": "",
+ "meta": {"taxes":{"vatlayer": ""}},
"weight": "0.0 kg"
}
},
@@ -757,7 +757,7 @@
"attributes": "{\"15\": \"46\", \"21\": \"68\"}",
"updated_at": "2019-03-06T12:47:38.530Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -791,7 +791,7 @@
"attributes": "{\"15\": \"46\", \"21\": \"69\"}",
"updated_at": "2019-03-06T12:47:38.875Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -825,7 +825,7 @@
"attributes": "{\"23\": \"72\"}",
"updated_at": "2019-03-06T12:47:39.256Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -859,7 +859,7 @@
"attributes": "{\"23\": \"72\"}",
"updated_at": "2019-03-06T12:47:39.501Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -893,7 +893,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:39.769Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -927,7 +927,7 @@
"attributes": "{}",
"updated_at": "2019-03-06T12:47:40.537Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "1.0 kg"
}
},
@@ -961,7 +961,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:41.280Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -995,7 +995,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:41.681Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1029,7 +1029,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:41.972Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1063,7 +1063,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:42.283Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1097,7 +1097,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:42.524Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1131,7 +1131,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:42.771Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1165,7 +1165,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:43.640Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1199,7 +1199,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:44.067Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1233,7 +1233,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:44.582Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1267,7 +1267,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:45.080Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1301,7 +1301,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:45.376Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1335,7 +1335,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:45.669Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
@@ -1369,7 +1369,7 @@
"attributes": "{\"25\": \"82\"}",
"updated_at": "2019-03-06T12:47:45.937Z",
"charge_taxes": true,
- "tax_rate": "standard",
+ "meta": {"taxes":{"vatlayer": "standard"}},
"weight": "0.0 kg"
}
},
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index 50f668b588..542ba64fad 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -11,7 +11,7 @@ from django.utils.text import slugify
from graphql_relay import to_global_id
from prices import Money
-from saleor.core.taxes import TaxType
+from saleor.core.taxes import TaxType, interface as tax_interface
from saleor.graphql.core.enums import ReportingPeriod
from saleor.graphql.product.enums import StockAvailability
from saleor.graphql.product.types.products import resolve_attribute_list
@@ -681,7 +681,7 @@ def test_create_product(
$descriptionJson: JSONString!,
$isPublished: Boolean!,
$chargeTaxes: Boolean!,
- $taxRate: String!,
+ $taxCode: String!,
$basePrice: Decimal!,
$attributes: [AttributeValueInput!]) {
productCreate(
@@ -693,7 +693,7 @@ def test_create_product(
descriptionJson: $descriptionJson,
isPublished: $isPublished,
chargeTaxes: $chargeTaxes,
- taxRate: $taxRate,
+ taxCode: $taxCode,
basePrice: $basePrice,
attributes: $attributes
}) {
@@ -768,7 +768,7 @@ def test_create_product(
"descriptionJson": product_description_json,
"isPublished": product_is_published,
"chargeTaxes": product_charge_taxes,
- "taxRate": product_tax_rate,
+ "taxCode": product_tax_rate,
"basePrice": product_price,
"attributes": [
{"slug": color_attr_slug, "value": color_value_slug},
@@ -1006,7 +1006,7 @@ def test_update_product(
$description: String!,
$isPublished: Boolean!,
$chargeTaxes: Boolean!,
- $taxRate: String!,
+ $taxCode: String!,
$basePrice: Decimal!,
$attributes: [AttributeValueInput!]) {
productUpdate(
@@ -1017,7 +1017,7 @@ def test_update_product(
description: $description,
isPublished: $isPublished,
chargeTaxes: $chargeTaxes,
- taxRate: $taxRate,
+ taxCode: $taxCode,
basePrice: $basePrice,
attributes: $attributes
}) {
@@ -1077,7 +1077,7 @@ def test_update_product(
"description": product_description,
"isPublished": product_is_published,
"chargeTaxes": product_charge_taxes,
- "taxRate": product_tax_rate,
+ "taxCode": product_tax_rate,
"basePrice": product_price,
}
@@ -1255,8 +1255,18 @@ def test_product_type(user_api_client, product_type):
def test_product_type_query(
- user_api_client, staff_api_client, product_type, product, permission_manage_products
+ user_api_client,
+ staff_api_client,
+ product_type,
+ product,
+ permission_manage_products,
+ monkeypatch,
):
+ monkeypatch.setattr(
+ "saleor.graphql.product.types.products."
+ "vatlayer_interface.get_tax_from_object_meta",
+ lambda x: TaxType(code="standard", description=""),
+ )
query = """
query getProductType($id: ID!) {
productType(id: $id) {
@@ -1288,16 +1298,22 @@ def test_product_type_query(
content = get_graphql_content(response)
data = content["data"]
assert data["productType"]["products"]["totalCount"] == no_products
- assert data["productType"]["taxRate"] == product_type.tax_rate.upper()
+ assert data["productType"]["taxRate"] == "STANDARD"
def test_product_type_create_mutation(
- staff_api_client, product_type, permission_manage_products
+ staff_api_client, product_type, permission_manage_products, monkeypatch, settings
):
+ settings.VATLAYER_ACCESS_KEY = "test"
+ monkeypatch.setattr(
+ "saleor.graphql.product.types.products."
+ "vatlayer_interface.get_tax_from_object_meta",
+ lambda x: TaxType(code="standard", description=""),
+ )
query = """
mutation createProductType(
$name: String!,
- $taxRate: TaxRateType!,
+ $taxCode: String!,
$hasVariants: Boolean!,
$isShippingRequired: Boolean!,
$productAttributes: [ID],
@@ -1305,7 +1321,7 @@ def test_product_type_create_mutation(
productTypeCreate(
input: {
name: $name,
- taxRate: $taxRate,
+ taxCode: $taxCode,
hasVariants: $hasVariants,
isShippingRequired: $isShippingRequired,
productAttributes: $productAttributes,
@@ -1346,7 +1362,7 @@ def test_product_type_create_mutation(
variables = {
"name": product_type_name,
"hasVariants": has_variants,
- "taxRate": "STANDARD",
+ "taxCode": "STANDARD",
"isShippingRequired": require_shipping,
"productAttributes": product_attributes_ids,
"variantAttributes": variant_attributes_ids,
@@ -1377,7 +1393,8 @@ def test_product_type_create_mutation(
)
new_instance = ProductType.objects.latest("pk")
- assert new_instance.tax_rate == "standard"
+ tax_code = tax_interface.get_tax_from_object_meta(new_instance).code
+ assert tax_code == "standard"
def test_product_type_update_mutation(
diff --git a/tests/conftest.py b/tests/conftest.py
index 907aa0baaa..b1f1ef53eb 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -21,7 +21,6 @@ from saleor.account.models import Address, User
from saleor.checkout import utils
from saleor.checkout.models import Checkout
from saleor.checkout.utils import add_variant_to_checkout
-from saleor.core.taxes.vatlayer import DEFAULT_TAX_RATE_NAME
from saleor.dashboard.menu.utils import update_menu
from saleor.discount import VoucherType
from saleor.discount.models import Sale, Voucher, VoucherTranslation
@@ -376,10 +375,7 @@ def permission_manage_orders():
@pytest.fixture
def product_type(color_attribute, size_attribute):
product_type = ProductType.objects.create(
- name="Default Type",
- has_variants=True,
- is_shipping_required=True,
- tax_rate=DEFAULT_TAX_RATE_NAME,
+ name="Default Type", has_variants=True, is_shipping_required=True
)
product_type.product_attributes.add(color_attribute)
product_type.variant_attributes.add(size_attribute)
@@ -406,7 +402,6 @@ def product(product_type, category):
product_type=product_type,
attributes=attributes,
category=category,
- tax_rate=DEFAULT_TAX_RATE_NAME,
)
variant_attr = product_type.variant_attributes.first()
diff --git a/tests/taxes/test_vatlayer.py b/tests/taxes/test_vatlayer.py
index 851d9ef8fd..90a81daec4 100644
--- a/tests/taxes/test_vatlayer.py
+++ b/tests/taxes/test_vatlayer.py
@@ -62,6 +62,9 @@ def test_view_checkout_with_taxes(
checkout = request_checkout_with_item
checkout.shipping_address = address
checkout.save()
+ product = checkout.lines.first().variant.product
+ product.meta = {"taxes": {"vatlayer": {"code": "standard", "description": ""}}}
+ product.save()
response = client.get(reverse("checkout:index"))
response_checkout_line = response.context[0]["checkout_lines"][0]
line_net = Money(amount="8.13", currency="USD")