Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Revert quantitze applied on tax rate (#17777)
Maciej Korycinski7dcf89985e0c
diff --git a/saleor/checkout/tests/test_calculations.py b/saleor/checkout/tests/test_calculations.pyindex 545fd4f3b7..fbe7992626 100644--- a/saleor/checkout/tests/test_calculations.py+++ b/saleor/checkout/tests/test_calculations.py@@ -99,6 +99,46 @@ def test_apply_tax_data(checkout_with_items, checkout_lines, tax_data):)+def test_apply_tax_data_tax_rate_matches(checkout_with_items, checkout_lines):+ # given+ net_amount = Decimal("10.000")+ tax_rate = Decimal("8.875")+ expected_tax_rate = Decimal("0.08875")+ gross_amount = net_amount + (net_amount * tax_rate / 100)+ tax_data = TaxData(+ shipping_price_net_amount=net_amount,+ shipping_price_gross_amount=gross_amount,+ shipping_tax_rate=tax_rate,+ lines=[+ TaxLineData(+ total_net_amount=net_amount,+ total_gross_amount=gross_amount,+ tax_rate=tax_rate,+ )+ for _ in checkout_lines+ ],+ )++ checkout = checkout_with_items+ lines = checkout_lines++ # when+ _apply_tax_data(+ checkout,+ [+ Mock(spec=CheckoutLineInfo, line=line, variant=line.variant)+ for line in lines+ ],+ tax_data,+ )++ # then+ assert checkout.shipping_tax_rate == expected_tax_rate++ for line in lines:+ assert line.tax_rate == expected_tax_rate++@pytest.fixturedef fetch_kwargs(checkout_with_items, plugins_manager):lines, _ = fetch_checkout_lines(checkout_with_items)diff --git a/saleor/tax/tests/test_checkout_calculations.py b/saleor/tax/tests/test_checkout_calculations.pyindex fd4259078b..bdc4d14698 100644--- a/saleor/tax/tests/test_checkout_calculations.py+++ b/saleor/tax/tests/test_checkout_calculations.py@@ -269,9 +269,9 @@ def test_calculate_checkout_shipping_with_weighted_taxes(weighted_tax_amount = weighted_tax_amount / sum(line_info.line.total_price.net.amount for line_info in lines)- assert checkout.shipping_tax_rate == Decimal(weighted_tax_amount).quantize(- Decimal("0.0001")- )+ assert checkout.shipping_tax_rate.quantize(Decimal("0.0001")) == Decimal(+ weighted_tax_amount+ ).quantize(Decimal("0.0001"))assert checkout.shipping_price == TaxedMoney(net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD"))diff --git a/saleor/tax/tests/test_order_calculations.py b/saleor/tax/tests/test_order_calculations.pyindex 9382628fe5..d333269662 100644--- a/saleor/tax/tests/test_order_calculations.py+++ b/saleor/tax/tests/test_order_calculations.py@@ -201,7 +201,7 @@ def test_calculate_order_shipping_with_weighted_taxes(line.total_price.net.amount for line in lines)assert (- order.shipping_tax_rate+ order.shipping_tax_rate.quantize(Decimal("0.0001"))== Decimal(weighted_tax_amount).quantize(Decimal("0.0001"))== Decimal(expected_shipping_tax_rate).quantize(Decimal("0.0001")))diff --git a/saleor/tax/utils.py b/saleor/tax/utils.pyindex 8d90ad38e9..469ca1a2d7 100644--- a/saleor/tax/utils.py+++ b/saleor/tax/utils.py@@ -251,7 +251,6 @@ def _get_weighted_tax_rate_for_shipping(weighted_sum = sum([rate * weight for rate, weight in tax_rates_with_weights.items()], Decimal(0))-return (weighted_sum / total_weight).quantize(Decimal(".0001"))@@ -327,7 +326,7 @@ def normalize_tax_rate_for_db(tax_rate: Decimal) -> Decimal:# Percentage values are used to represent tax rates in tax apps and flat rates, but# in the database rates are stored as fractional values. Example: tax app returns# `10%` as `10`, but in the database it's stored as `0.1`.- return (tax_rate / 100).quantize(Decimal(".0001"))+ return tax_rate / 100def denormalize_tax_rate_from_db(tax_rate: Decimal) -> Decimal: