Skip to content

Commit

Permalink
[IMP] sale_triple_discount: Compute amount with decimal precision of 16
Browse files Browse the repository at this point in the history
  • Loading branch information
hildickethan authored and sbiosca-s73 committed Oct 17, 2024
1 parent f32db33 commit be6dcba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sale_triple_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions sale_triple_discount/tests/test_sale_triple_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit be6dcba

Please sign in to comment.