Repository: saleor/saleor

Issue:
Bug: Unable to update order data for digital order with Avalara
### What are you trying to achieve?

Update order data for digital order with Avalara.

### Steps to reproduce the problem

 1. Turn on Avalara 
 2. Create a product without shipping with taxes
 3. Create and finalize digital checkout
 4. Try to update the order. eg.
 ```graphql
mutation {
  orderUpdate(id: "T3JkZXI6MjU=", input: { userEmail: "aaa@example.com" }) {
    errors {
      field
      message
      code
      warehouse
      orderLines
    }
  }
}

```

### What did you expect to happen?

Mutation should be performed without errors.

### Logs

_No response_

### Environment

Saleor version: 3.1 to 3.5
OS and version: Local (MacOS 13)



Discussion:
Sentry issue: [SALEOR-CORE-J](https://sentry.io/organizations/saleor/issues/3307097554/?referrer=github_integration)

Resolving patch:
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -155,11 +155,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
 
 


Test patch:
diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.py
--- a/saleor/order/tests/test_order_actions.py
+++ b/saleor/order/tests/test_order_actions.py
@@ -1,8 +1,6 @@
-from decimal import Decimal
 from unittest.mock import patch
 
 import pytest
-from prices import Money, TaxedMoney
 
 from ...order.fetch import OrderLineInfo, fetch_order_info
 from ...payment import ChargeStatus, PaymentError, TransactionKind
@@ -29,46 +27,6 @@
 )
 
 
-@pytest.fixture
-def order_with_digital_line(order, digital_content, stock, site_settings):
-    site_settings.automatic_fulfillment_digital_products = True
-    site_settings.save()
-
-    variant = stock.product_variant
-    variant.digital_content = digital_content
-    variant.digital_content.save()
-
-    product_type = variant.product.product_type
-    product_type.is_shipping_required = False
-    product_type.is_digital = True
-    product_type.save()
-
-    quantity = 3
-    product = variant.product
-    channel = order.channel
-    variant_channel_listing = variant.channel_listings.get(channel=channel)
-    net = variant.get_price(product, [], channel, variant_channel_listing, None)
-    gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
-    unit_price = TaxedMoney(net=net, gross=gross)
-    line = order.lines.create(
-        product_name=str(product),
-        variant_name=str(variant),
-        product_sku=variant.sku,
-        product_variant_id=variant.get_global_id(),
-        is_shipping_required=variant.is_shipping_required(),
-        is_gift_card=variant.is_gift_card(),
-        quantity=quantity,
-        variant=variant,
-        unit_price=unit_price,
-        total_price=unit_price * quantity,
-        tax_rate=Decimal("0.23"),
-    )
-
-    Allocation.objects.create(order_line=line, stock=stock, quantity_allocated=quantity)
-
-    return order
-
-
 @patch(
     "saleor.order.actions.send_fulfillment_confirmation_to_customer",
     wraps=send_fulfillment_confirmation_to_customer,
diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.py
--- a/saleor/plugins/avatax/tests/test_avatax.py
+++ b/saleor/plugins/avatax/tests/test_avatax.py
@@ -33,6 +33,7 @@
     AvataxConfiguration,
     TransactionType,
     _validate_adddress_details,
+    _validate_order,
     api_get_request,
     api_post_request,
     generate_request_data_from_checkout,
@@ -3233,6 +3234,17 @@ def test_validate_adddress_details(
     assert is_valid is expected_is_valid
 
 
+def test_validate_order_for_digital_order(order_with_digital_line):
+    # given
+    order = order_with_digital_line
+
+    # when
+    is_valid = _validate_order(order)
+
+    # then
+    assert is_valid 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
 ):
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -3634,6 +3634,46 @@ def order_with_lines(
     return order
 
 
+@pytest.fixture
+def order_with_digital_line(order, digital_content, stock, site_settings):
+    site_settings.automatic_fulfillment_digital_products = True
+    site_settings.save()
+
+    variant = stock.product_variant
+    variant.digital_content = digital_content
+    variant.digital_content.save()
+
+    product_type = variant.product.product_type
+    product_type.is_shipping_required = False
+    product_type.is_digital = True
+    product_type.save()
+
+    quantity = 3
+    product = variant.product
+    channel = order.channel
+    variant_channel_listing = variant.channel_listings.get(channel=channel)
+    net = variant.get_price(product, [], channel, variant_channel_listing, None)
+    gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
+    unit_price = TaxedMoney(net=net, gross=gross)
+    line = order.lines.create(
+        product_name=str(product),
+        variant_name=str(variant),
+        product_sku=variant.sku,
+        product_variant_id=variant.get_global_id(),
+        is_shipping_required=variant.is_shipping_required(),
+        is_gift_card=variant.is_gift_card(),
+        quantity=quantity,
+        variant=variant,
+        unit_price=unit_price,
+        total_price=unit_price * quantity,
+        tax_rate=Decimal("0.23"),
+    )
+
+    Allocation.objects.create(order_line=line, stock=stock, quantity_allocated=quantity)
+
+    return order
+
+
 @pytest.fixture
 def order_with_lines_for_cc(
     warehouse_for_cc,