Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix incorect price send to avatax (#9633)
Maciej Korycinskiad8bcd72543b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2ca5d80196..389158c135 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,9 @@ All notable, unreleased changes to this project will be documented in this file.# Unreleased+### Other changes+- Fix for sending incorrect prices to Avatax - #9633 by @korycins+# 3.3.1- Drop manual calls to emit post_migrate in migrations (#9647) (b32308802)diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.pyindex 8d661bbe73..d038335a72 100644--- a/saleor/plugins/avatax/__init__.py+++ b/saleor/plugins/avatax/__init__.py@@ -365,16 +365,20 @@ def get_order_lines_data("name": line.variant.product.name,"tax_included": tax_included,}- append_line_to_data(- **append_line_to_data_kwargs,- amount=undiscounted_amount,- )+ if not invoice_transaction_type:+ append_line_to_data(+ **append_line_to_data_kwargs,+ amount=undiscounted_amount,+ )- # for invoice transaction we want to include only final price- if (- not invoice_transaction_type- and undiscounted_amount != price_with_discounts_amount- ):+ # for invoice transaction we want to include only final price+ if undiscounted_amount != price_with_discounts_amount:+ append_line_to_data(+ **append_line_to_data_kwargs,+ amount=price_with_discounts_amount,+ ref1=line.variant.sku,+ )+ else:append_line_to_data(**append_line_to_data_kwargs,amount=price_with_discounts_amount,diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.pyindex 655dbfbc81..91be7d849a 100644--- a/saleor/plugins/avatax/tests/test_avatax.py+++ b/saleor/plugins/avatax/tests/test_avatax.py@@ -3349,6 +3349,49 @@ def test_get_order_lines_data_sets_different_tax_code_for_zero_amount(assert lines_data[0]["taxCode"] == DEFAULT_TAX_CODE+def test_get_order_lines_data_with_invoice_type(+ settings, channel_USD, plugin_configuration, order, order_line+):+ # given+ settings.PLUGINS = ["saleor.plugins.avatax.plugin.AvataxPlugin"]+ plugin_configuration(channel=channel_USD)++ order_line.unit_price_gross_amount = Decimal("10")+ order_line.undiscounted_unit_price_gross_amount = Decimal("20")+ order_line.quantity = 1+ order_line.save(+ update_fields=[+ "quantity",+ "unit_price_gross_amount",+ "undiscounted_unit_price_gross_amount",+ ]+ )+ variant = order_line.variant+ variant.product.store_value_in_metadata(+ {META_CODE_KEY: "taxcode", META_DESCRIPTION_KEY: "tax_description"}+ )+ variant.product.save()++ config = AvataxConfiguration(+ username_or_account="test",+ password_or_license="test",+ use_sandbox=False,+ from_street_address="Tęczowa 7",+ from_city="WROCŁAW",+ from_country_area="",+ from_postal_code="53-601",+ from_country="PL",+ )++ # when+ lines_data = get_order_lines_data(order, config, invoice_transaction_type=True)++ # then+ assert len(lines_data) == 1+ line_data = lines_data[0]+ assert line_data["amount"] == "10.000"++def test_get_order_lines_data_sets_different_tax_code_only_for_zero_amount(settings, channel_USD, plugin_configuration, order_with_lines, avatax_config):