Skip to content

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

Fix problem with updating draft order with active avalara (#10183)

Iga Karbowiakaf270b8c9fc5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4716a01277..739d7ff88b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,7 +26,7 @@ All notable, unreleased changes to this project will be documented in this file.
Usage:
- Database backend: `celery --app saleor.celeryconf:app beat --scheduler saleor.schedulers.schedulers.DatabaseScheduler`
- Shelve backend: `celery --app saleor.celeryconf:app beat --scheduler saleor.schedulers.schedulers.PersistentScheduler`
-
+- Fix problem with updating draft order with active avalara - #10183 by @IKarbowiak
# 3.5.0
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index 9795eedc41..f936d0a1b7 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -159,11 +159,12 @@ def _validate_order(order: "Order") -> bool:
)
if not valid_address_details:
return False
- channel_listing = shipping_method.channel_listings.filter( # type: ignore
- channel_id=order.channel_id
- ).first()
- if not channel_listing:
- return False
+ if shipping_required:
+ channel_listing = shipping_method.channel_listings.filter( # type: ignore
+ channel_id=order.channel_id
+ ).first()
+ if not channel_listing:
+ return False
return True
diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.py
index ac9da8289c..58f788c028 100644
--- a/saleor/plugins/avatax/tests/test_avatax.py
+++ b/saleor/plugins/avatax/tests/test_avatax.py
@@ -33,6 +33,7 @@ from .. import (
AvataxConfiguration,
TransactionType,
_validate_adddress_details,
+ _validate_order,
api_get_request,
api_post_request,
generate_request_data_from_checkout,
@@ -4062,6 +4063,35 @@ def test_validate_adddress_details(
assert is_valid is expected_is_valid
+def test_validate_order_no_lines(order):
+ # given
+ assert not order.lines.all()
+
+ # when
+ response = _validate_order(order)
+
+ # then
+ assert response is False
+
+
+def test_validate_order_not_shipping_required_no_shipping_method(order_line, address):
+ # given
+ order = order_line.order
+ order_line.is_shipping_required = False
+ order_line.save(update_fields=["is_shipping_required"])
+
+ order.shipping_method = None
+ order.shipping_address = address
+ order.billing_address = address
+ order.save(update_fields=["shipping_address", "billing_address", "shipping_method"])
+
+ # when
+ response = _validate_order(order)
+
+ # then
+ assert response is True
+
+
def test_get_checkout_lines_data_sets_different_tax_code_for_zero_amount(
settings, channel_USD, plugin_configuration, checkout_with_item, avatax_config
):