Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix incorrect tax calculation for klarna
Maciej Korycinskica383441496b
diff --git a/saleor/payment/gateways/adyen/tests/test_utils.py b/saleor/payment/gateways/adyen/tests/test_utils.pyindex e0dfa14e41..4cbaee3a58 100644--- a/saleor/payment/gateways/adyen/tests/test_utils.py+++ b/saleor/payment/gateways/adyen/tests/test_utils.py@@ -71,9 +71,9 @@ def test_append_klarna_data_tax_included(mocked_checkout_line_total, dummy_payment_data, payment_dummy, checkout_with_item):# given- tax_percent = 5- net = Money(10, "USD")- gross = tax_percent * net / 100 + net+ net = Money(100, "USD")+ gross = Money(123, "USD")+ # tax 23 %mocked_checkout_line_total.return_value = quantize_price(TaxedMoney(net=net, gross=gross), "USD")@@ -100,7 +100,7 @@ def test_append_klarna_data_tax_included("quantity": line.quantity,"id": line.variant.sku,"taxAmount": to_adyen_price((gross - net).amount, "USD"),- "taxPercentage": tax_percent,+ "taxPercentage": 2300,"amountExcludingTax": to_adyen_price(net.amount, "USD"),"amountIncludingTax": to_adyen_price(gross.amount, "USD"),}diff --git a/saleor/payment/gateways/adyen/utils.py b/saleor/payment/gateways/adyen/utils.pyindex 648c421364..42c485076f 100644--- a/saleor/payment/gateways/adyen/utils.py+++ b/saleor/payment/gateways/adyen/utils.py@@ -125,10 +125,19 @@ def append_klarna_data(payment_information: "PaymentData", payment_data: dict):total_gross = total.gross.amounttotal_net = total.net.amounttax_amount = total.tax.amount++ tax_percentage_in_adyen_format = 0+ if total_gross:+ # get tax percent in adyen format+ gross_percentage = total_gross / total_net+ gross_percentage = gross_percentage.quantize(Decimal(".01")) # 1.23+ tax_percentage = gross_percentage * 100 - 100 # 23.00+ tax_percentage_in_adyen_format = int(tax_percentage * 100) # 2300+line_data = {"quantity": line.quantity,"amountExcludingTax": to_adyen_price(total_net, currency),- "taxPercentage": round(tax_amount / total_gross * 100),+ "taxPercentage": tax_percentage_in_adyen_format,"description": f"{line.variant.product.name}, {line.variant.name}","id": line.variant.sku,"taxAmount": to_adyen_price(tax_amount, currency),