Skip to content

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

Return default tax code for product type

Maciej Korycinskia1ff3b052e46
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index f3ac1ff646..64c43f44c8 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -39,6 +39,7 @@ COMMON_DISCOUNT_VOUCHER_CODE = "OD010000"
# Temporary Unmapped Other SKU - taxable default
DEFAULT_TAX_CODE = "O9999999"
+DEFAULT_TAX_DESCRIPTION = "Unmapped Other SKU - taxable default"
@dataclass
diff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.py
index 7708d61786..00d27ee8b1 100644
--- a/saleor/plugins/avatax/plugin.py
+++ b/saleor/plugins/avatax/plugin.py
@@ -10,9 +10,12 @@ from prices import Money, TaxedMoney, TaxedMoneyRange
from ...checkout import base_calculations
from ...core.taxes import TaxError, TaxType, charge_taxes_on_shipping, zero_taxed_money
from ...discount import DiscountInfo
+from ...product.models import Product, ProductType
from ..base_plugin import BasePlugin, ConfigurationTypeField
from ..error_codes import PluginErrorCode
from . import (
+ DEFAULT_TAX_CODE,
+ DEFAULT_TAX_DESCRIPTION,
META_CODE_KEY,
META_DESCRIPTION_KEY,
AvataxConfiguration,
@@ -35,7 +38,6 @@ if TYPE_CHECKING:
# flake8: noqa
from ...checkout.models import Checkout, CheckoutLine
from ...order.models import Order, OrderLine
- from ...product.models import Product, ProductType
from ..models import PluginConfiguration
@@ -417,8 +419,18 @@ class AvataxPlugin(BasePlugin):
) -> TaxType:
if not self.active:
return previous_value
- tax_code = obj.get_value_from_metadata(META_CODE_KEY, None)
- tax_description = obj.get_value_from_metadata(META_DESCRIPTION_KEY, None)
+
+ # Product has None as it determines if we overwrite taxes for the product
+ default_tax_code = None
+ default_tax_description = None
+ if isinstance(obj, ProductType):
+ default_tax_code = DEFAULT_TAX_CODE
+ default_tax_description = DEFAULT_TAX_DESCRIPTION
+
+ tax_code = obj.get_value_from_metadata(META_CODE_KEY, default_tax_code)
+ tax_description = obj.get_value_from_metadata(
+ META_DESCRIPTION_KEY, default_tax_description
+ )
return TaxType(code=tax_code, description=tax_description,)
def show_taxes_on_storefront(self, previous_value: bool) -> bool:
diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.py
index 58f537f377..61a8f8e476 100644
--- a/saleor/plugins/vatlayer/plugin.py
+++ b/saleor/plugins/vatlayer/plugin.py
@@ -14,6 +14,7 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
from ...checkout import calculations
from ...core.taxes import TaxType
from ...graphql.core.utils.error_codes import PluginErrorCode
+from ...product.models import Product, ProductType
from ..base_plugin import BasePlugin, ConfigurationTypeField
from . import (
DEFAULT_TAX_RATE_NAME,
@@ -28,7 +29,7 @@ if TYPE_CHECKING:
# flake8: noqa
from ...checkout.models import Checkout, CheckoutLine
from ...discount import DiscountInfo
- from ...product.models import Product, ProductType
+
from ...account.models import Address
from ...order.models import OrderLine, Order
from ..models import PluginConfiguration
@@ -266,8 +267,18 @@ class VatlayerPlugin(BasePlugin):
def __get_tax_code_from_object_meta(
self, obj: Union["Product", "ProductType"]
) -> "TaxType":
- tax_code = obj.get_value_from_metadata(self.META_CODE_KEY, None)
- tax_description = obj.get_value_from_metadata(self.META_DESCRIPTION_KEY, None)
+
+ # Product has None as it determines if we overwrite taxes for the product
+ default_tax_code = None
+ default_tax_description = None
+ if isinstance(obj, ProductType):
+ default_tax_code = DEFAULT_TAX_RATE_NAME
+ default_tax_description = DEFAULT_TAX_RATE_NAME
+
+ tax_code = obj.get_value_from_metadata(self.META_CODE_KEY, default_tax_code)
+ tax_description = obj.get_value_from_metadata(
+ self.META_DESCRIPTION_KEY, default_tax_description
+ )
return TaxType(code=tax_code, description=tax_description)
def get_tax_rate_percentage_value(