Skip to content

Commit

Permalink
add taxConfiguration to Channel for Avalara tax calculation preci…
Browse files Browse the repository at this point in the history
…sion. (#15658)
  • Loading branch information
Air-t committed Mar 21, 2024
1 parent 4fba0b2 commit 7234b19
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 110 deletions.
14 changes: 14 additions & 0 deletions saleor/graphql/channel/tests/queries/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
stockSettings{
allocationStrategy
}
taxConfiguration {
id
pricesEnteredWithTax
}
}
}
"""
Expand All @@ -29,6 +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)
Expand All @@ -45,12 +52,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)
Expand All @@ -67,6 +79,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):
Expand Down
17 changes: 17 additions & 0 deletions saleor/graphql/channel/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
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
Expand Down Expand Up @@ -405,12 +407,27 @@ class Channel(ModelObjectType):
],
)

tax_configuration = PermissionsField(
"saleor.graphql.tax.types.TaxConfiguration",
description="Channel specific tax configuration.",
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 (
Expand Down
227 changes: 117 additions & 110 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5168,6 +5168,13 @@ type Channel implements Node & ObjectWithMetadata @doc(category: "Channels") {
Requires one of the following permissions: MANAGE_CHANNELS, HANDLE_PAYMENTS.
"""
paymentSettings: PaymentSettings!

"""
Channel specific tax configuration.

Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.
"""
taxConfiguration: TaxConfiguration!

Check notice on line 5177 in saleor/graphql/schema.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector

Field 'Channel.taxConfiguration' description changed from 'Channel specific tax configuration. Added in Saleor 3.20. Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.' to 'Channel specific tax configuration. Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.'

Field 'Channel.taxConfiguration' description changed from 'Channel specific tax configuration. Added in Saleor 3.20. Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.' to 'Channel specific tax configuration. Requires one of the following permissions: AUTHENTICATED_STAFF_USER, AUTHENTICATED_APP.'
}

"""
Expand Down Expand Up @@ -5685,6 +5692,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."""
Expand Down Expand Up @@ -9755,116 +9872,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!
Expand Down

0 comments on commit 7234b19

Please sign in to comment.