diff --git a/account_invoice_triple_discount/README.rst b/account_invoice_triple_discount/README.rst index d4d31d376a0..b4226c98a47 100644 --- a/account_invoice_triple_discount/README.rst +++ b/account_invoice_triple_discount/README.rst @@ -7,7 +7,7 @@ Account Invoice Triple Discount !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:89bbe50c0f673cb6d1bce75de0d3031cc5e37537320b310b3bb29bac0ee7724a + !! source digest: sha256:9ad7382e62c36c90b601a9fc2a61570cc2eaa85957cf82e46d405a4718dda37d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -81,6 +81,9 @@ Contributors * David Vidal * Pedro M. Baeza * Nikul Chaudhary +* `Aion Tech `_: + + * Simone Rubino Maintainers ~~~~~~~~~~~ diff --git a/account_invoice_triple_discount/models/account_move.py b/account_invoice_triple_discount/models/account_move.py index 99856cd6f46..258582904d5 100644 --- a/account_invoice_triple_discount/models/account_move.py +++ b/account_invoice_triple_discount/models/account_move.py @@ -1,8 +1,9 @@ # Copyright 2017 Tecnativa - David Vidal # Copyright 2017 Tecnativa - Pedro M. Baeza +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, models class AccountMove(models.Model): @@ -17,3 +18,26 @@ def _has_discount(self): for line in self.invoice_line_ids ] ) + + @api.model + def _field_will_change(self, record, vals, field_name): + result = super()._field_will_change(record, vals, field_name) + is_discount_field = ( + record._name == self.line_ids._name and field_name == "discount" + ) + if ( + not result + and self.env.context.get("restoring_triple_discount") + and is_discount_field + ): + # Discount value in the cache has many digits (e.g. 100.00000000000009), + # but we have just restored the original digits (e.g. 2) in the field + # and want to write the correct value (e.g. 100.00). + # The method in super compares: + # - the cache value rounded with the field's digits: 100.00 + # - the value we want to write: 100.00 + # and concludes that the value won't change, + # thus leaving the cache value (100.00000000000009) + # instead of updating the cache with the value we actually want (100.00) + result = True + return result diff --git a/account_invoice_triple_discount/models/account_move_line.py b/account_invoice_triple_discount/models/account_move_line.py index b391e16f849..e6fd258aca4 100644 --- a/account_invoice_triple_discount/models/account_move_line.py +++ b/account_invoice_triple_discount/models/account_move_line.py @@ -1,4 +1,5 @@ # Copyright 2020 ACSONE SA/NV +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import functools @@ -81,7 +82,9 @@ def _compute_totals(self): for line in self: if line.id not in old_values_by_line_id: continue - line.update(old_values_by_line_id[line.id]) + line.with_context( + restoring_triple_discount=True, + ).update(old_values_by_line_id[line.id]) return res @api.depends( @@ -114,7 +117,9 @@ def _compute_all_tax(self): for line in self: if line.id not in old_values_by_line_id: continue - line.update(old_values_by_line_id[line.id]) + line.with_context( + restoring_triple_discount=True, + ).update(old_values_by_line_id[line.id]) return res def _convert_to_tax_base_line_dict(self): diff --git a/account_invoice_triple_discount/readme/CONTRIBUTORS.rst b/account_invoice_triple_discount/readme/CONTRIBUTORS.rst index 6f532df62ef..cf39e4923fb 100644 --- a/account_invoice_triple_discount/readme/CONTRIBUTORS.rst +++ b/account_invoice_triple_discount/readme/CONTRIBUTORS.rst @@ -1,3 +1,6 @@ * David Vidal * Pedro M. Baeza * Nikul Chaudhary +* `Aion Tech `_: + + * Simone Rubino diff --git a/account_invoice_triple_discount/static/description/index.html b/account_invoice_triple_discount/static/description/index.html index 3dbd14185e8..fba3019de37 100644 --- a/account_invoice_triple_discount/static/description/index.html +++ b/account_invoice_triple_discount/static/description/index.html @@ -367,7 +367,7 @@

Account Invoice Triple Discount

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:89bbe50c0f673cb6d1bce75de0d3031cc5e37537320b310b3bb29bac0ee7724a +!! source digest: sha256:9ad7382e62c36c90b601a9fc2a61570cc2eaa85957cf82e46d405a4718dda37d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/account-invoicing Translate me on Weblate Try me on Runboat

This module allows to have three successive discounts on each invoice line.

@@ -430,6 +430,10 @@

Contributors

  • David Vidal <david.vidal@tecnativa.com>
  • Pedro M. Baeza <pedro.baeza@tecnativa.com>
  • Nikul Chaudhary <nikulchaudhary2112@gmail.com>
  • +
  • Aion Tech: +
  • diff --git a/account_invoice_triple_discount/tests/test_invoice_triple_discount.py b/account_invoice_triple_discount/tests/test_invoice_triple_discount.py index 0ad48266a50..032e4dde79a 100644 --- a/account_invoice_triple_discount/tests/test_invoice_triple_discount.py +++ b/account_invoice_triple_discount/tests/test_invoice_triple_discount.py @@ -1,4 +1,5 @@ # Copyright 2017 Tecnativa - David Vidal +# Copyright 2023 Simone Rubino - Aion Tech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests import TransactionCase @@ -186,3 +187,18 @@ def test_05_has_discount(self): line_form.discount3 = 50.0 invoice_form.save() self.assertTrue(invoice._has_discount()) + + def test_06_round_discount(self): + """Discount value is rounded correctly""" + invoice = self.create_simple_invoice(0) + invoice_line = invoice.invoice_line_ids[0] + invoice_line.discount = 100 + self.assertEqual(invoice_line.discount, 100) + + def test_07_round_tax_discount(self): + """Discount value is rounded correctly when taxes change""" + invoice = self.create_simple_invoice(0) + invoice_line = invoice.invoice_line_ids[0] + invoice_line.discount = 100 + invoice_line.tax_ids = False + self.assertEqual(invoice_line.discount, 100)