diff --git a/addons/test_sale_product_configurators/tests/test_sale_product_matrix.py b/addons/test_sale_product_configurators/tests/test_sale_product_matrix.py index 4ef1815b3cf..ad6777376e1 100644 --- a/addons/test_sale_product_configurators/tests/test_sale_product_matrix.py +++ b/addons/test_sale_product_configurators/tests/test_sale_product_matrix.py @@ -26,7 +26,7 @@ class TestSaleMatrixUi(TestMatrixCommon): cls.env['res.partner'].create({'name': 'Agrolait'}) # Setup currency - cls.env['res.currency'].search([('name', '!=', 'USD')]).action_archive() + cls.env['res.currency'].search([('name', '!=', 'USD')]).with_context(force_deactivate=True).action_archive() cls.currency = cls.env['res.currency'].search([('name', '=', 'USD')]) cls.currency.action_unarchive() diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index 3eb54b095bc..678eb7c2631 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -24385,3 +24385,9 @@ msgstr "" #: model:res.country,name:base.ax msgid "Ă…land Islands" msgstr "" + +#. module: base +#: code:addons/base/models/res_currency.py:0 +#, python-format +msgid "This currency is set on a company and therefore cannot be deactivated." +msgstr "" diff --git a/odoo/addons/base/models/res_currency.py b/odoo/addons/base/models/res_currency.py index d00fbe3abdf..82918af6e60 100644 --- a/odoo/addons/base/models/res_currency.py +++ b/odoo/addons/base/models/res_currency.py @@ -95,6 +95,18 @@ class Currency(models.Model): if group_user and group_mc: group_user.sudo()._remove_group(group_mc.sudo()) + @api.constrains('active') + def _check_company_currency_stays_active(self): + if self._context.get('install_mode') or self._context.get('force_deactivate'): + # install_mode : At install, when this check is run, the "active" field of a currency added to a company will + # still be evaluated as False, despite it's automatically set at True when added to the company. + # force_deactivate : Allows deactivation of a currency in tests to enable non multi_currency behaviors + return + + currencies = self.filtered(lambda c: not c.active) + if self.env['res.company'].search([('currency_id', 'in', currencies.ids)]): + raise UserError(_("This currency is set on a company and therefore cannot be deactivated.")) + def _get_rates(self, company, date): if not self.ids: return {}