From be6dcba9a9cf028ae81e251275b61a9f941221e6 Mon Sep 17 00:00:00 2001 From: Ethan Hildick Date: Mon, 21 Aug 2023 13:10:52 +0200 Subject: [PATCH] [IMP] sale_triple_discount: Compute amount with decimal precision of 16 Equivalent to the current computation in invoices https://github.com/OCA/account-invoicing/blob/d2e12c03b50011bb788cf482346710f0fefe0de3/account_invoice_triple_discount/models/account_move_line.py#L73-L74 --- sale_triple_discount/models/sale_order_line.py | 3 +++ sale_triple_discount/tests/test_sale_triple_discount.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/sale_triple_discount/models/sale_order_line.py b/sale_triple_discount/models/sale_order_line.py index 992ecaec478..f89b1a6e8ed 100644 --- a/sale_triple_discount/models/sale_order_line.py +++ b/sale_triple_discount/models/sale_order_line.py @@ -107,6 +107,8 @@ def _aggregated_discount(self): # to invalidate the cache to avoid to flush the records to the database. # This is safe because we are going to restore the original value at the end # of the method. + digits = discount_field._digits + self.env["sale.order.line"]._fields["discount"]._digits = (16, 16) with self.env.protecting([discount_field], self): old_values = {} for line in self: @@ -120,6 +122,7 @@ def _aggregated_discount(self): line.with_context( restoring_triple_discount=True, ).update({"discount": old_values[line.id]}) + self.env["sale.order.line"]._fields["discount"]._digits = digits def _convert_to_tax_base_line_dict(self): self.ensure_one() diff --git a/sale_triple_discount/tests/test_sale_triple_discount.py b/sale_triple_discount/tests/test_sale_triple_discount.py index 069e796cb1e..199673bbc84 100644 --- a/sale_triple_discount/tests/test_sale_triple_discount.py +++ b/sale_triple_discount/tests/test_sale_triple_discount.py @@ -208,3 +208,11 @@ def test_06_discount_0(self): self.assertAlmostEqual(self.so_line2.price_subtotal, 600.0) self.assertAlmostEqual(self.order.amount_untaxed, 1200.0) self.assertAlmostEqual(self.order.amount_tax, 180.0) + + def test_07_discount_16_digits(self): + self.so_line1.product_uom_qty = 2.0 + self.so_line1.price_unit = 138.0 + self.so_line1.discount = 45.0 + self.so_line1.discount2 = 5.0 + self.so_line1.discount3 = 10.0 + self.assertAlmostEqual(self.so_line1.price_subtotal, 129.79)