Skip to content

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

Update method for preparing checkout lines data for avalara plugin

IKarbowiaka15d6327b876
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index d0e87c0fb8..f1432d7ac6 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -243,6 +243,8 @@ def get_checkout_lines_data(
data: List[Dict[str, Union[str, int, bool, None]]] = []
channel = checkout_info.channel
for line_info in lines_info:
+ if not line_info.product.charge_taxes:
+ continue
product = line_info.product
name = product.name
product_type = line_info.product_type
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_total_not_charged_product_and_shipping_with_0_price.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_total_not_charged_product_and_shipping_with_0_price.yaml
new file mode 100644
index 0000000000..85d401879e
--- /dev/null
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_total_not_charged_product_and_shipping_with_0_price.yaml
@@ -0,0 +1,70 @@
+interactions:
+- request:
+ body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesOrder",
+ "lines": [{"quantity": 1, "amount": "0.000", "taxCode": "FR020100", "taxIncluded":
+ true, "itemCode": "Shipping", "description": null}], "code": "dd5c408f-b533-494c-b2a1-2985140b71be",
+ "date": "2021-06-24", "customerCode": 0, "addresses": {"shipFrom": {"line1":
+ "Teczowa 7", "line2": null, "city": "Wroclaw", "region": "", "country": "PL",
+ "postalCode": "53-601"}, "shipTo": {"line1": "O\u0142awska 10", "line2": "",
+ "city": "WROC\u0141AW", "region": "", "country": "PL", "postalCode": "53-105"}},
+ "commit": false, "currencyCode": "USD", "email": ""}}'
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Authorization:
+ - Basic Og==
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '626'
+ User-Agent:
+ - python-requests/2.25.1
+ method: POST
+ uri: https://rest.avatax.com/api/v2/transactions/create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J0PZd5z16rYmom018VgOhk5k2IpM48NZplTlkEFXr6eB1gf
+ j2A3uqjWm5sdQ+HaNATCrElh7J0yFUQloVtNcr1plPtJ2B3R5h3s+7bTcZSDo5abZiMhPyjSVJMx
+ H4nVEgTDhrcTeiKWzy+y7KMP1jA++1kmfprv4izik2SjVwD+2IWfW8a8+PT5YTaejD7DsDsafC4x
+ j8h83/1uJwq5+qsrs+L5wR0aMzAO+1EI/cVvirS46vqRrFDr3deX83fU94OBFpT8Kn6Ksyu08f48
+ ukgw/AfzXIZO4P2VetX43/NgXabKc/5vh39ZXsGzw3MvMP6uxjt1+DsdQmNH5wtpxfG2qhNC/SMt
+ SsHEADCIeUMnmitH4MHtI/7gPwiO4aNqVa6T09rLnz/EWoydOuPKX76+/AEOKTBmtAoAAA==
+ headers:
+ Connection:
+ - keep-alive
+ Content-Encoding:
+ - gzip
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Thu, 24 Jun 2021 08:36:35 GMT
+ Location:
+ - /api/v2/companies/242975/transactions/0
+ Server:
+ - Kestrel
+ ServerDuration:
+ - '00:00:00.0130762'
+ Transfer-Encoding:
+ - chunked
+ Vary:
+ - Accept-Encoding
+ status:
+ code: 201
+ message: Created
+version: 1
diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.py
index b7b40c8934..f8f04b883b 100644
--- a/saleor/plugins/avatax/tests/test_avatax.py
+++ b/saleor/plugins/avatax/tests/test_avatax.py
@@ -323,6 +323,65 @@ def test_calculate_checkout_total(
)
+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
+def test_calculate_checkout_total_not_charged_product_and_shipping_with_0_price(
+ checkout_with_item,
+ shipping_zone,
+ address,
+ ship_to_pl_address,
+ site_settings,
+ monkeypatch,
+ plugin_configuration,
+):
+ plugin_configuration()
+ monkeypatch.setattr(
+ "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",
+ lambda _: {"PS081282": "desc"},
+ )
+ monkeypatch.setattr(
+ "saleor.plugins.avatax.plugin.AvataxPlugin._skip_plugin", lambda *_: False
+ )
+ manager = get_plugins_manager()
+ checkout_with_item.shipping_address = ship_to_pl_address
+ checkout_with_item.save()
+ site_settings.company_address = address
+ site_settings.include_taxes_in_prices = True
+ site_settings.save()
+
+ channel = checkout_with_item.channel
+ shipping_method = shipping_zone.shipping_methods.get()
+ shipping_channel_listing = shipping_method.channel_listings.get(channel=channel)
+ shipping_channel_listing.price = Money(0, "USD")
+ shipping_channel_listing.save()
+
+ checkout_with_item.shipping_method = shipping_method
+ checkout_with_item.save()
+
+ line = checkout_with_item.lines.first()
+ variant = line.variant
+ product = variant.product
+ product.charge_taxes = False
+ product.metadata = {}
+ manager.assign_tax_code_to_object_meta(product.product_type, "PS081282")
+ product.save()
+ product.product_type.save()
+
+ discounts = None
+ checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)
+ lines = fetch_checkout_lines(checkout_with_item)
+ total = manager.calculate_checkout_total(
+ checkout_info, lines, ship_to_pl_address, discounts
+ )
+ total = quantize_price(total, total.currency)
+
+ channel_listing = variant.channel_listings.get(channel=channel)
+ expected_amount = (line.quantity * channel_listing.price).amount
+ assert total == TaxedMoney(
+ net=Money(expected_amount, "USD"), gross=Money(expected_amount, "USD")
+ )
+
+
@pytest.mark.vcr
@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
def test_calculate_checkout_shipping(