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 May 21, 2024
1 parent c81b3f0 commit c178a00
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 @@ -103,6 +103,9 @@ def triple_discount_preprocess(self):
Updating the cache provides consistency through re-computations."""
prev_values = dict()
self.invalidate_cache(fnames=self._discount_fields(), ids=self.ids)
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] = {
fname: line[fname] for fname in self._discount_fields()
Expand All @@ -118,10 +121,12 @@ def triple_discount_preprocess(self):
def triple_discount_postprocess(self, prev_values):
"""Restore the discounts of the lines in the dictionary prev_values.
Updating the cache provides consistency through re-computations."""
digits = prev_values.pop("discount_digits")
self.invalidate_cache(
fnames=self._discount_fields(),
ids=[line.id for line in list(prev_values.keys())],
)
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 c178a00

Please sign in to comment.