From 04157311cbfcdafdd95413e9285bd6fd267cf887 Mon Sep 17 00:00:00 2001 From: sesn-odoo Date: Wed, 22 Nov 2023 08:58:50 +0100 Subject: [PATCH] [FIX] account: prevent currency rounding change through multi-company MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, increasing the rounding factor for a currency is not allowed if accounting entries have already been generated in that currency. However, the restriction currently only applies to the current company. And since currency records are shared between multiple companies, a user can create a new company with no accounting entries and then change the currency's rounding factor, affecting all companies. This commit checks for the restriction on all companies, and fixes a few tests that were broken by this change. opw-3586785 closes odoo/odoo#144226 X-original-commit: 7f8b76ac7ad3730a662203aa88a03d067c1230cb Signed-off-by: de Wouters de Bouchout Jean-Benoît (jbw) Signed-off-by: Séna Serge Nshimiyimana (sesn) --- addons/account/models/res_currency.py | 5 ++--- addons/account/tests/test_tax.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/account/models/res_currency.py b/addons/account/models/res_currency.py index 024faf59d3a..5060337d443 100644 --- a/addons/account/models/res_currency.py +++ b/addons/account/models/res_currency.py @@ -36,11 +36,10 @@ class ResCurrency(models.Model): def _has_accounting_entries(self): """ Returns True iff this currency has been used to generate (hence, round) - some move lines (either as their foreign currency, or as the main currency - of their company). + some move lines (either as their foreign currency, or as the main currency). """ self.ensure_one() - return bool(self.env['account.move.line'].search_count(['|', ('currency_id', '=', self.id), ('company_currency_id', '=', self.id)])) + return bool(self.env['account.move.line'].sudo().search_count(['|', ('currency_id', '=', self.id), ('company_currency_id', '=', self.id)])) @api.model def _get_query_currency_table(self, company_ids, conversion_date): diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py index e3ef9370009..0b043c5efe7 100644 --- a/addons/account/tests/test_tax.py +++ b/addons/account/tests/test_tax.py @@ -13,6 +13,16 @@ class TestTaxCommon(AccountTestInvoicingCommon): cls.currency_data['currency'].rounding = 1.0 cls.currency_no_decimal = cls.currency_data['currency'] cls.company_data_2 = cls.setup_company_data('company_2', currency_id=cls.currency_no_decimal.id) + + cls.currency_5_round = cls.env['res.currency'].create({ + 'name': 'Platinum Coin', + 'symbol': 'P$', + 'rounding': 0.05, + 'position': 'after', + 'currency_unit_label': 'Platinum', + 'currency_subunit_label': 'Palladium', + }) + cls.company_data_3 = cls.setup_company_data('company_3', currency_id=cls.currency_5_round.id) cls.env.user.company_id = cls.company_data['company'] cls.fixed_tax = cls.env['account.tax'].create({ @@ -119,7 +129,7 @@ class TestTaxCommon(AccountTestInvoicingCommon): 'amount': 0, }) - cls.tax_5_percent = cls.env['account.tax'].with_company(cls.company_data['company']).create({ + cls.tax_5_percent = cls.env['account.tax'].with_company(cls.company_data_3['company']).create({ 'name': "test_5_percent", 'amount_type': 'percent', 'amount': 5,