Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add taxType to ProductType
Maciej Korycinskib022d4724f54
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex 13aead3dbc..3c2dca5dfc 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -583,6 +583,9 @@ class ProductType(CountableDjangoObjectType):prefetch_related=prefetch_products,)tax_rate = TaxRateType(description="A type of tax rate.")+ tax_type = graphene.Field(+ TaxType, description="A type of tax. Assigned by enabled tax gateway"+ )variant_attributes = graphene.List(Attribute, description="Variant attributes of that product type.")@@ -602,8 +605,14 @@ class ProductType(CountableDjangoObjectType):"is_shipping_required","name","weight",+ "tax_type",]+ @staticmethod+ def resolve_tax_type(root: models.ProductType, _info):+ tax_data = tax_interface.get_tax_from_object_meta(root)+ return TaxType(tax_code=tax_data.code, description=tax_data.description)+@staticmethoddef resolve_tax_rate(root: models.ProductType, info, **_kwargs):# FIXME this resolver should be dropped after we drop tax_rate from APIdiff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 3ca772d337..64d547e549 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2329,6 +2329,7 @@ type ProductType implements Node {weight: Weightproducts(before: String, after: String, first: Int, last: Int): ProductCountableConnectiontaxRate: TaxRateType+ taxType: TaxTypevariantAttributes: [Attribute]productAttributes: [Attribute]}diff --git a/tests/api/test_product.py b/tests/api/test_product.pyindex 0475d83669..9624faab25 100644--- a/tests/api/test_product.py+++ b/tests/api/test_product.py@@ -1266,6 +1266,11 @@ def test_product_type_query("vatlayer_interface.get_tax_from_object_meta",lambda x: TaxType(code="standard", description=""),)+ monkeypatch.setattr(+ "saleor.graphql.product.types.products."+ "tax_interface.get_tax_from_object_meta",+ lambda x: TaxType(code="123", description="Standard Taxes"),+ )query = """query getProductType($id: ID!) {productType(id: $id) {@@ -1279,6 +1284,10 @@ def test_product_type_query(}}taxRate+ taxType {+ taxCode+ description+ }}}"""@@ -1298,6 +1307,8 @@ def test_product_type_query(data = content["data"]assert data["productType"]["products"]["totalCount"] == no_productsassert data["productType"]["taxRate"] == "STANDARD"+ assert data["productType"]["taxType"]["taxCode"] == "123"+ assert data["productType"]["taxType"]["description"] == "Standard Taxes"def test_product_type_create_mutation(