[FIX] account: prevent currency rounding change through multi-company

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) <jbw@odoo.com>
Signed-off-by: Séna Serge Nshimiyimana (sesn) <sesn@odoo.com>
This commit is contained in:
sesn-odoo
2023-11-30 18:38:00 +00:00
parent d769aba6c5
commit 04157311cb
2 changed files with 13 additions and 4 deletions
+2 -3
View File
@@ -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):
+11 -1
View File
@@ -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,