From 3c87077d1243090b211e05acd25dbed0e5ee82d1 Mon Sep 17 00:00:00 2001 From: Walid Date: Wed, 31 Jan 2024 10:53:42 +0100 Subject: [PATCH] [FIX] account: Cash rounding Steps to reproduce: - Enable Automated Valuation. - Set the cost of Acoustic Bloc Screens to 287.33. - Set the Product Category on the product to have AVCO automated valuation. - Enable Cash Rounding. - Create a Cash Rounding (see tests). - Make an invoice selling one Acoustic Bloc Screen and remove the tax. - Set the Cash Rounding on the invoice under "Other Info". - Confirm the invoice. Bug: when summing the ammount of all the lines the result is slightly off (float accuracy) this will create an unnecessary cash rounding to compensate Fix: round the sum to the currency precision before checking for the cash rounding opw-3681307 closes odoo/odoo#152112 X-original-commit: 4a6ec1a667ee3d2fba00d277b4c7e8a730a45ecd Signed-off-by: Walid Hanniche (waha) --- .../account/models/account_cash_rounding.py | 1 + .../tests/test_account_move_in_invoice.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/addons/account/models/account_cash_rounding.py b/addons/account/models/account_cash_rounding.py index d73ada9c3cd..139a764cad5 100644 --- a/addons/account/models/account_cash_rounding.py +++ b/addons/account/models/account_cash_rounding.py @@ -61,5 +61,6 @@ class AccountCashRounding(models.Model): :param amount: The amount :return: round(difference) """ + amount = currency.round(amount) difference = self.round(amount) - amount return currency.round(difference) diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 63237fbf523..e3739e3e15a 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -758,6 +758,38 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): 'amount_total': 1384.0, }) + def test_compute_cash_rounding_lines(self): + cash_rounding_add_invoice_line = self.env['account.cash.rounding'].create({ + 'name': 'Add invoice line Rounding Down', + 'rounding': .1, + 'strategy': 'add_invoice_line', + 'profit_account_id': self.company_data['default_account_revenue'].id, + 'loss_account_id': self.company_data['default_account_expense'].id, + 'rounding_method': 'DOWN', + }) + move = self.env['account.move'].create({ + 'move_type': 'in_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2019-01-01', + 'invoice_cash_rounding_id': cash_rounding_add_invoice_line.id, + 'invoice_line_ids': [ + Command.create({ + 'name': 'line', + 'price_unit': 295, + 'tax_ids': [], + }), + Command.create({ + 'name': 'cost', + 'price_unit': 280.33, + }), + Command.create({ + 'name': 'cost neg', + 'price_unit': -280.33, + }), + ], + }) + self.assertFalse(move.line_ids.filtered(lambda line: line.display_type == 'rounding')) + def test_in_invoice_line_onchange_cash_rounding_1(self): # Required for `invoice_cash_rounding_id` to be visible in the view self.env.user.groups_id += self.env.ref('account.group_cash_rounding')