Repository: saleor/saleor

Issue:
Bug: [Simple Taxes] SubTotal.tax is different then TotalPrice.tax when avalara is active.
### What are you trying to achieve?

When Avalara plugin is activated then after createCheckout mutation then subtotal.tax contains taxes and totaPrice.tax does not.

### Steps to reproduce the problem

1.turn on avalara in channel
2.go to taxes and in channel where avalara was activated choose Use tax app 
3.select product with some tax class 
4.create checkout with that product in this channel 

### What did you expect to happen?

totalPrice.tax and subTotal.price tax should be same.

### Logs

![image](https://user-images.githubusercontent.com/29308910/196651430-e26762bc-4beb-4a7c-97f2-3d871efe4695.png)
![image](https://user-images.githubusercontent.com/29308910/196651456-984e97ef-257a-4032-8601-363789b889e8.png)
![image](https://user-images.githubusercontent.com/29308910/196651561-307a350f-cc19-4dee-8df1-8952efa69b69.png)


### Environment

Saleor version: simpleTax env



Discussion:

Resolving patch:
diff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.py
--- a/saleor/plugins/avatax/plugin.py
+++ b/saleor/plugins/avatax/plugin.py
@@ -287,7 +287,9 @@ def calculate_checkout_shipping(
     ) -> TaxedMoney:
         base_shipping_price = previous_value
 
-        response = get_checkout_tax_data(checkout_info, lines, discounts, self.config)
+        response = self._get_checkout_tax_data(
+            checkout_info, lines, discounts, self.config
+        )
         if response is None:
             return previous_value
 
@@ -389,7 +391,9 @@ def calculate_checkout_line_total(
             _get_prices_entered_with_tax_for_checkout, checkout_info
         )
 
-        taxes_data = get_checkout_tax_data(checkout_info, lines, discounts, self.config)
+        taxes_data = self._get_checkout_tax_data(
+            checkout_info, lines, discounts, self.config
+        )
         variant = checkout_line_info.variant
 
         return self._calculate_checkout_line_total_price(
@@ -521,7 +525,9 @@ def calculate_checkout_line_unit_price(
         variant = checkout_line_info.variant
 
         quantity = checkout_line_info.line.quantity
-        taxes_data = get_checkout_tax_data(checkout_info, lines, discounts, self.config)
+        taxes_data = self._get_checkout_tax_data(
+            checkout_info, lines, discounts, self.config
+        )
         default_total = previous_value * quantity
         taxed_total_price = self._calculate_checkout_line_total_price(
             taxes_data,


Test patch:
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
@@ -4880,3 +4880,101 @@ def test_assign_tax_code_to_object_meta_no_obj_id(
         META_CODE_KEY: tax_code,
         META_DESCRIPTION_KEY: description,
     }
+
+
+@patch("saleor.plugins.avatax.plugin.get_checkout_tax_data")
+def test_calculate_checkout_shipping_validates_checkout(
+    mocked_func, settings, channel_USD, plugin_configuration, checkout_with_item
+):
+    # given
+    settings.PLUGINS = ["saleor.plugins.avatax.plugin.AvataxPlugin"]
+    plugin_configuration(channel=channel_USD)
+    manager = get_plugins_manager()
+    checkout = checkout_with_item
+    lines, _ = fetch_checkout_lines(checkout)
+
+    checkout.shipping_method = None
+    checkout.save(update_fields=["shipping_method"])
+
+    for line in lines:
+        line.product_type.is_shipping_required = True
+        line.product_type.save()
+
+    checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+
+    # when
+    manager.calculate_checkout_shipping(
+        checkout_info,
+        lines,
+        checkout.shipping_address,
+        discounts=[],
+    )
+
+    # then
+    assert not mocked_func.called
+
+
+@patch("saleor.plugins.avatax.plugin.get_checkout_tax_data")
+def test_calculate_checkout_line_total_validates_checkout(
+    mocked_func, settings, channel_USD, plugin_configuration, checkout_with_item
+):
+    # given
+    settings.PLUGINS = ["saleor.plugins.avatax.plugin.AvataxPlugin"]
+    plugin_configuration(channel=channel_USD)
+    manager = get_plugins_manager()
+    checkout = checkout_with_item
+    lines, _ = fetch_checkout_lines(checkout)
+
+    checkout.shipping_method = None
+    checkout.save(update_fields=["shipping_method"])
+
+    for line in lines:
+        line.product_type.is_shipping_required = True
+        line.product_type.save()
+
+    checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+
+    # when
+    manager.calculate_checkout_line_total(
+        checkout_info,
+        lines,
+        lines[0],
+        checkout.shipping_address,
+        discounts=[],
+    )
+
+    # then
+    assert not mocked_func.called
+
+
+@patch("saleor.plugins.avatax.plugin.get_checkout_tax_data")
+def test_calculate_checkout_line_unit_price_validates_checkout(
+    mocked_func, settings, channel_USD, plugin_configuration, checkout_with_item
+):
+    # given
+    settings.PLUGINS = ["saleor.plugins.avatax.plugin.AvataxPlugin"]
+    plugin_configuration(channel=channel_USD)
+    manager = get_plugins_manager()
+    checkout = checkout_with_item
+    lines, _ = fetch_checkout_lines(checkout)
+
+    checkout.shipping_method = None
+    checkout.save(update_fields=["shipping_method"])
+
+    for line in lines:
+        line.product_type.is_shipping_required = True
+        line.product_type.save()
+
+    checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+
+    # when
+    manager.calculate_checkout_line_unit_price(
+        checkout_info,
+        lines,
+        lines[0],
+        checkout.shipping_address,
+        discounts=[],
+    )
+
+    # then
+    assert not mocked_func.called