Skip to content

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

add `taxConfiguration` to `Channel` for Avalara tax calculation precision. (#15610)

Artur64c99525a4bd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3281ffbb8e..6905499609 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,4 @@
+
# Changelog
All notable, unreleased changes to this project will be documented in this file. For the released changes, please visit the [Releases](https://github.com/saleor/saleor/releases) page.
@@ -10,6 +11,8 @@ All notable, unreleased changes to this project will be documented in this file.
### GraphQL API
+- Add a `taxConfiguration` to a `Channel` - #15610 by @Air-t
+
### Saleor Apps
### Other changes
diff --git a/saleor/graphql/channel/tests/queries/test_channel.py b/saleor/graphql/channel/tests/queries/test_channel.py
index dc3aeed4b1..e1e13b4fc4 100644
--- a/saleor/graphql/channel/tests/queries/test_channel.py
+++ b/saleor/graphql/channel/tests/queries/test_channel.py
@@ -20,6 +20,10 @@ QUERY_CHANNEL = """
stockSettings{
allocationStrategy
}
+ taxConfiguration {
+ id
+ pricesEnteredWithTax
+ }
}
}
"""
@@ -29,7 +33,9 @@ def test_query_channel_as_staff_user(staff_api_client, channel_USD):
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {"id": channel_id}
-
+ tax_configuration_id = graphene.Node.to_global_id(
+ "TaxConfiguration", channel_USD.tax_configuration.id
+ )
# when
response = staff_api_client.post_graphql(QUERY_CHANNEL, variables=variables)
content = get_graphql_content(response)
@@ -45,12 +51,17 @@ def test_query_channel_as_staff_user(staff_api_client, channel_USD):
AllocationStrategyEnum[allocation_strategy].value
== channel_USD.allocation_strategy
)
+ assert channel_data["taxConfiguration"]["id"] == tax_configuration_id
+ assert channel_data["taxConfiguration"]["pricesEnteredWithTax"] is True
def test_query_channel_as_app(app_api_client, channel_USD):
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {"id": channel_id}
+ tax_configuration_id = graphene.Node.to_global_id(
+ "TaxConfiguration", channel_USD.tax_configuration.id
+ )
# when
response = app_api_client.post_graphql(QUERY_CHANNEL, variables=variables)
@@ -67,6 +78,8 @@ def test_query_channel_as_app(app_api_client, channel_USD):
AllocationStrategyEnum[allocation_strategy].value
== channel_USD.allocation_strategy
)
+ assert channel_data["taxConfiguration"]["id"] == tax_configuration_id
+ assert channel_data["taxConfiguration"]["pricesEnteredWithTax"] is True
def test_query_channel_as_customer(user_api_client, channel_USD):
diff --git a/saleor/graphql/channel/types.py b/saleor/graphql/channel/types.py
index 5722e0fcc1..71af5463a4 100644
--- a/saleor/graphql/channel/types.py
+++ b/saleor/graphql/channel/types.py
@@ -31,6 +31,7 @@ from ..core.descriptions import (
ADDED_IN_315,
ADDED_IN_316,
ADDED_IN_318,
+ ADDED_IN_320,
DEPRECATED_IN_3X_FIELD,
PREVIEW_FEATURE,
)
@@ -39,11 +40,13 @@ from ..core.doc_category import (
DOC_CATEGORY_ORDERS,
DOC_CATEGORY_PAYMENTS,
DOC_CATEGORY_PRODUCTS,
+ DOC_CATEGORY_TAXES,
)
from ..core.fields import PermissionsField
from ..core.scalars import Day, Minute
from ..core.types import BaseObjectType, CountryDisplay, ModelObjectType, NonNullList
from ..meta.types import ObjectWithMetadata
+from ..tax.dataloaders import TaxConfigurationByChannelId
from ..translations.resolvers import resolve_translation
from ..warehouse.dataloaders import WarehousesByChannelIdLoader
from ..warehouse.types import Warehouse
@@ -405,12 +408,27 @@ class Channel(ModelObjectType):
],
)
+ tax_configuration = PermissionsField(
+ "saleor.graphql.tax.types.TaxConfiguration",
+ description="Channel specific tax configuration." + ADDED_IN_320,
+ required=True,
+ permissions=[
+ AuthorizationFilters.AUTHENTICATED_STAFF_USER,
+ AuthorizationFilters.AUTHENTICATED_APP,
+ ],
+ doc_category=DOC_CATEGORY_TAXES,
+ )
+
class Meta:
description = "Represents channel."
model = models.Channel
interfaces = [graphene.relay.Node, ObjectWithMetadata]
metadata_since = ADDED_IN_315
+ @staticmethod
+ def resolve_tax_configuration(root: models.Channel, info: ResolveInfo):
+ return TaxConfigurationByChannelId(info.context).load(root.id)
+
@staticmethod
def resolve_has_orders(root: models.Channel, info: ResolveInfo):
return (
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 1033af1bf9..28142631a1 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -5168,6 +5168,15 @@ type Channel implements Node & ObjectWithMetadata @doc(category: "Channels") {
Requires one of the following permissions: MANAGE_CHANNELS, HANDLE_PAYMENTS.
"""
paymentSettings: PaymentSettings!
+
+ """
+ Channel specific tax configuration.
+
+ Added in Saleor 3.20.
+
+ Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.
+ """
+ taxConfiguration: TaxConfiguration!
}
"""
@@ -5685,6 +5694,116 @@ enum TransactionFlowStrategyEnum @doc(category: "Payments") {
CHARGE
}
+"""
+Channel-specific tax configuration.
+
+Added in Saleor 3.9.
+"""
+type TaxConfiguration implements Node & ObjectWithMetadata @doc(category: "Taxes") {
+ """The ID of the object."""
+ id: ID!
+
+ """List of private metadata items. Requires staff permissions to access."""
+ privateMetadata: [MetadataItem!]!
+
+ """
+ A single key from private metadata. Requires staff permissions to access.
+
+ Tip: Use GraphQL aliases to fetch multiple keys.
+
+ Added in Saleor 3.3.
+ """
+ privateMetafield(key: String!): String
+
+ """
+ Private metadata. Requires staff permissions to access. Use `keys` to control which fields you want to include. The default is to include everything.
+
+ Added in Saleor 3.3.
+ """
+ privateMetafields(keys: [String!]): Metadata
+
+ """List of public metadata items. Can be accessed without permissions."""
+ metadata: [MetadataItem!]!
+
+ """
+ A single key from public metadata.
+
+ Tip: Use GraphQL aliases to fetch multiple keys.
+
+ Added in Saleor 3.3.
+ """
+ metafield(key: String!): String
+
+ """
+ Public metadata. Use `keys` to control which fields you want to include. The default is to include everything.
+
+ Added in Saleor 3.3.
+ """
+ metafields(keys: [String!]): Metadata
+
+ """A channel to which the tax configuration applies to."""
+ channel: Channel!
+
+ """Determines whether taxes are charged in the given channel."""
+ chargeTaxes: Boolean!
+
+ """
+ The default strategy to use for tax calculation in the given channel. Taxes can be calculated either using user-defined flat rates or with a tax app. Empty value means that no method is selected and taxes are not calculated.
+ """
+ taxCalculationStrategy: TaxCalculationStrategy
+
+ """Determines whether displayed prices should include taxes."""
+ displayGrossPrices: Boolean!
+
+ """Determines whether prices are entered with the tax included."""
+ pricesEnteredWithTax: Boolean!
+
+ """List of country-specific exceptions in tax configuration."""
+ countries: [TaxConfigurationPerCountry!]!
+
+ """
+ The tax app `App.identifier` that will be used to calculate the taxes for the given channel. Empty value for `TAX_APP` set as `taxCalculationStrategy` means that Saleor will iterate over all installed tax apps. If multiple tax apps exist with provided tax app id use the `App` with newest `created` date. Will become mandatory in 4.0 for `TAX_APP` `taxCalculationStrategy`.
+
+ Added in Saleor 3.19.
+ """
+ taxAppId: String
+}
+
+enum TaxCalculationStrategy @doc(category: "Taxes") {
+ FLAT_RATES
+ TAX_APP
+}
+
+"""
+Country-specific exceptions of a channel's tax configuration.
+
+Added in Saleor 3.9.
+"""
+type TaxConfigurationPerCountry @doc(category: "Taxes") {
+ """Country in which this configuration applies."""
+ country: CountryDisplay!
+
+ """Determines whether taxes are charged in this country."""
+ chargeTaxes: Boolean!
+
+ """
+ A country-specific strategy to use for tax calculation. Taxes can be calculated either using user-defined flat rates or with a tax app. If not provided, use the value from the channel's tax configuration.
+ """
+ taxCalculationStrategy: TaxCalculationStrategy
+
+ """
+ Determines whether displayed prices should include taxes for this country.
+ """
+ displayGrossPrices: Boolean!
+
+ """
+ The tax app `App.identifier` that will be used to calculate the taxes for the given channel and country. If not provided, use the value from the channel's tax configuration.
+
+ Added in Saleor 3.19.
+ """
+ taxAppId: String
+}
+
"""Represents shipping method postal code rule."""
type ShippingMethodPostalCodeRule implements Node @doc(category: "Shipping") {
"""The ID of the object."""
@@ -9755,116 +9874,6 @@ enum TranslatableKinds {
VOUCHER
}
-"""
-Channel-specific tax configuration.
-
-Added in Saleor 3.9.
-"""
-type TaxConfiguration implements Node & ObjectWithMetadata @doc(category: "Taxes") {
- """The ID of the object."""
- id: ID!
-
- """List of private metadata items. Requires staff permissions to access."""
- privateMetadata: [MetadataItem!]!
-
- """
- A single key from private metadata. Requires staff permissions to access.
-
- Tip: Use GraphQL aliases to fetch multiple keys.
-
- Added in Saleor 3.3.
- """
- privateMetafield(key: String!): String
-
- """
- Private metadata. Requires staff permissions to access. Use `keys` to control which fields you want to include. The default is to include everything.
-
- Added in Saleor 3.3.
- """
- privateMetafields(keys: [String!]): Metadata
-
- """List of public metadata items. Can be accessed without permissions."""
- metadata: [MetadataItem!]!
-
- """
- A single key from public metadata.
-
- Tip: Use GraphQL aliases to fetch multiple keys.
-
- Added in Saleor 3.3.
- """
- metafield(key: String!): String
-
- """
- Public metadata. Use `keys` to control which fields you want to include. The default is to include everything.
-
- Added in Saleor 3.3.
- """
- metafields(keys: [String!]): Metadata
-
- """A channel to which the tax configuration applies to."""
- channel: Channel!
-
- """Determines whether taxes are charged in the given channel."""
- chargeTaxes: Boolean!
-
- """
- The default strategy to use for tax calculation in the given channel. Taxes can be calculated either using user-defined flat rates or with a tax app. Empty value means that no method is selected and taxes are not calculated.
- """
- taxCalculationStrategy: TaxCalculationStrategy
-
- """Determines whether displayed prices should include taxes."""
- displayGrossPrices: Boolean!
-
- """Determines whether prices are entered with the tax included."""
- pricesEnteredWithTax: Boolean!
-
- """List of country-specific exceptions in tax configuration."""
- countries: [TaxConfigurationPerCountry!]!
-
- """
- The tax app `App.identifier` that will be used to calculate the taxes for the given channel. Empty value for `TAX_APP` set as `taxCalculationStrategy` means that Saleor will iterate over all installed tax apps. If multiple tax apps exist with provided tax app id use the `App` with newest `created` date. Will become mandatory in 4.0 for `TAX_APP` `taxCalculationStrategy`.
-
- Added in Saleor 3.19.
- """
- taxAppId: String
-}
-
-enum TaxCalculationStrategy @doc(category: "Taxes") {
- FLAT_RATES
- TAX_APP
-}
-
-"""
-Country-specific exceptions of a channel's tax configuration.
-
-Added in Saleor 3.9.
-"""
-type TaxConfigurationPerCountry @doc(category: "Taxes") {
- """Country in which this configuration applies."""
- country: CountryDisplay!
-
- """Determines whether taxes are charged in this country."""
- chargeTaxes: Boolean!
-
- """
- A country-specific strategy to use for tax calculation. Taxes can be calculated either using user-defined flat rates or with a tax app. If not provided, use the value from the channel's tax configuration.
- """
- taxCalculationStrategy: TaxCalculationStrategy
-
- """
- Determines whether displayed prices should include taxes for this country.
- """
- displayGrossPrices: Boolean!
-
- """
- The tax app `App.identifier` that will be used to calculate the taxes for the given channel and country. If not provided, use the value from the channel's tax configuration.
-
- Added in Saleor 3.19.
- """
- taxAppId: String
-}
-
type TaxConfigurationCountableConnection @doc(category: "Taxes") {
"""Pagination data for this connection."""
pageInfo: PageInfo!