[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) <xmo@odoo.com>
This commit is contained in:
Rahul Prajapati
2023-06-13 10:13:29 +02:00
parent c77fd9285e
commit 54b1cb8bb9
2 changed files with 9 additions and 0 deletions
+7
View File
@@ -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."
+2
View File
@@ -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()))