Skip to content

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

Remove some saleor's dependencies from plugins

Maciej Korycinski4d0c18c79688
diff --git a/saleor/core/extensions/manager.py b/saleor/core/extensions/manager.py
index 5e42782a6c..ce25d01942 100644
--- a/saleor/core/extensions/manager.py
+++ b/saleor/core/extensions/manager.py
@@ -8,11 +8,11 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRange
from ..taxes import TaxType, quantize_price
if TYPE_CHECKING:
+ from .plugin import BasePlugin
from ...checkout.models import Checkout, CheckoutLine
from ...product.models import Product
from ...account.models import Address
from ...order.models import OrderLine, Order
- from .plugin import BasePlugin
class ExtensionsManager:
diff --git a/saleor/core/extensions/plugins/avatax/__init__.py b/saleor/core/extensions/plugins/avatax/__init__.py
index 64472f320e..0bd31d70bd 100644
--- a/saleor/core/extensions/plugins/avatax/__init__.py
+++ b/saleor/core/extensions/plugins/avatax/__init__.py
@@ -6,13 +6,11 @@ from urllib.parse import urljoin
import requests
from django.conf import settings
+from django.contrib.sites.models import Site
from django.core.cache import cache
from django.utils.translation import pgettext_lazy
from requests.auth import HTTPBasicAuth
-from ....taxes import charge_taxes_on_shipping, include_taxes_in_prices
-from ....utils import get_company_address # FIXME shouldn't use logic from saleor
-
if TYPE_CHECKING:
from .....checkout.models import Checkout
from .....order.models import Order
@@ -171,7 +169,7 @@ def append_line_to_data(
tax_included: Optional[bool] = None,
):
if tax_included is None:
- tax_included = include_taxes_in_prices()
+ tax_included = Site.objects.get_current().settings.include_taxes_in_prices
data.append(
{
"quantity": quantity,
@@ -210,7 +208,10 @@ def get_checkout_lines_data(
description=description,
)
- if charge_taxes_on_shipping() and checkout.shipping_method:
+ charge_taxes_on_shipping = (
+ Site.objects.get_current().settings.charge_taxes_on_shipping
+ )
+ if charge_taxes_on_shipping and checkout.shipping_method:
append_line_to_data(
data,
quantity=1,
@@ -253,7 +254,10 @@ def get_order_lines_data(order: "Order") -> List[Dict[str, str]]:
description=order.discount_name,
tax_included=True, # Voucher should be always applied as a gross amount
)
- if charge_taxes_on_shipping() and order.shipping_method:
+ charge_taxes_on_shipping = (
+ Site.objects.get_current().settings.charge_taxes_on_shipping
+ )
+ if charge_taxes_on_shipping and order.shipping_method:
append_line_to_data(
data,
quantity=1,
@@ -274,7 +278,7 @@ def generate_request_data(
commit=False,
currency=settings.DEFAULT_CURRENCY,
):
- company_address = get_company_address()
+ company_address = Site.objects.get_current().settings.company_address
if company_address:
company_address = company_address.as_data()
else:
diff --git a/saleor/core/extensions/plugins/avatax/plugin.py b/saleor/core/extensions/plugins/avatax/plugin.py
index e7c7891613..8b0eadcd48 100644
--- a/saleor/core/extensions/plugins/avatax/plugin.py
+++ b/saleor/core/extensions/plugins/avatax/plugin.py
@@ -6,7 +6,6 @@ from urllib.parse import urljoin
from django.conf import settings
from prices import Money, TaxedMoney, TaxedMoneyRange
-from .....checkout import models as checkout_models
from ....taxes import TaxType, zero_taxed_money
from ....taxes.errors import TaxError
from ...plugin import BasePlugin
@@ -26,7 +25,7 @@ from . import (
from .tasks import api_post_request_task
if TYPE_CHECKING:
- from .....checkout.models import Checkout
+ from .....checkout.models import Checkout, CheckoutLine
from .....order.models import Order, OrderLine
logger = logging.getLogger(__name__)
@@ -56,7 +55,7 @@ class AvataxPlugin(BasePlugin):
def calculate_checkout_total(
self,
- checkout: "checkout_models.Checkout",
+ checkout: "Checkout",
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
@@ -83,7 +82,7 @@ class AvataxPlugin(BasePlugin):
def calculate_checkout_subtotal(
self,
- checkout: "checkout_models.Checkout",
+ checkout: "Checkout",
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
@@ -114,7 +113,7 @@ class AvataxPlugin(BasePlugin):
def calculate_checkout_shipping(
self,
- checkout: "checkout_models.Checkout",
+ checkout: "Checkout",
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
@@ -182,7 +181,7 @@ class AvataxPlugin(BasePlugin):
def calculate_checkout_line_total(
self,
- checkout_line: "checkout_models.CheckoutLine",
+ checkout_line: "CheckoutLine",
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney: