From 54b1cb8bb95bfd1f30243556b99d2bf278aea1e7 Mon Sep 17 00:00:00 2001 From: Rahul Prajapati Date: Thu, 18 May 2023 11:51:54 +0000 Subject: [PATCH] [FIX] base: validation for studio fields compute dependencies Before this commit: `id` cannot be set as the dependency for a field's compute method. So, when a user configures `id` as a dependency for a studio field's compute, there is no error shown to the user and the field is saved with `id` as a dependency. After this commit: It will throw a `UserError` to the user. sentry-3979435039 closes odoo/odoo#124660 X-original-commit: 9eab433e09aafafd3015f731b9ec449965d97748 Signed-off-by: Xavier Morel (xmo) --- odoo/addons/base/i18n/base.pot | 7 +++++++ odoo/addons/base/models/ir_model.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index b365aaa0dbd..f90d38001b7 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -12443,6 +12443,13 @@ msgstr "" msgid "Compute" msgstr "" +#. module: base +#. odoo-python +#: code:addons/base/models/ir_model.py:0 +#, python-format +msgid "Compute method cannot depend on field 'id'" +msgstr "" + #. module: base #: model:ir.module.module,summary:base.module_sale_subscription_taxcloud msgid "Compute taxes with TaxCloud after automatic invoice creation." diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 9a7f5864a9d..8eb30f158ee 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -672,6 +672,8 @@ class IrModelFields(models.Model): names = seq.strip().split(".") last = len(names) - 1 for index, name in enumerate(names): + if name == 'id': + raise UserError(_("Compute method cannot depend on field 'id'")) field = model._fields.get(name) if field is None: raise UserError(_("Unknown field %r in dependency %r") % (name, seq.strip()))