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 committed Aug 29, 2023
1 parent 0b84ffc commit ab1059b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sale_triple_discount/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def triple_discount_preprocess(self):
this method is called multiple times."""

prev_values = dict()
digits = self._fields["discount"]._digits
self.env["sale.order.line"]._fields["discount"]._digits = (16, 16)
prev_values["discount_digits"] = digits
for line in self:
prev_values[line] = dict(
discount=line.discount,
Expand All @@ -115,6 +118,8 @@ def triple_discount_preprocess(self):
@api.model
def triple_discount_postprocess(self, prev_values):
"""Restore the discounts of the lines in the dictionary prev_values."""
digits = prev_values.pop("discount_digits")
self.env["sale.order.line"]._fields["discount"]._digits = digits
for line, prev_vals_dict in list(prev_values.items()):
line.update(prev_vals_dict)

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 ab1059b

Please sign in to comment.