[FIX] base: fallback on model_id to fill related field
Scenario:
- go to a model in technical
- create a new field and set "Related Field" to id
=> error "Unknown field name 'id' in related field 'id'" because we
get the field in self.model which is not present in the form view.
Fix:
Fallback to self.model_id.model as was the case before 16.0 commit:
76f699ca0b
Note: without the change, the added tests fails with:
Warning Unknown field name 'id' in related field 'id'
AssertionError: False != 'integer
opw-3138440
closes #112495
closes odoo/odoo#140583
X-original-commit: aa406352541abd8bbf188da84fc4e370029ffc12
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
@@ -632,7 +632,7 @@ class IrModelFields(models.Model):
|
||||
""" Return the ``ir.model.fields`` record corresponding to ``self.related``. """
|
||||
names = self.related.split(".")
|
||||
last = len(names) - 1
|
||||
model_name = self.model
|
||||
model_name = self.model or self.model_id.model
|
||||
for index, name in enumerate(names):
|
||||
field = self._get(model_name, name)
|
||||
if not field:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase, HttpCase, tagged
|
||||
from odoo.tests.common import Form, TransactionCase, HttpCase, tagged
|
||||
from odoo.tools import mute_logger
|
||||
from odoo import Command
|
||||
|
||||
@@ -424,6 +424,19 @@ class TestIrModel(TransactionCase):
|
||||
self.assertEqual(monetary_field.currency_field, "x_good_currency",
|
||||
"The currency field in monetary should have x_good_currency as name")
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestIrModelEdition(TransactionCase):
|
||||
def test_new_ir_model_fields_related(self):
|
||||
"""Check that related field are handled correctly on new field"""
|
||||
model = self.env['ir.model'].create({
|
||||
'name': 'Bananas',
|
||||
'model': 'x_bananas'
|
||||
})
|
||||
with self.debug_mode():
|
||||
form = Form(self.env['ir.model.fields'].with_context(default_model_id=model.id))
|
||||
form.related = 'id'
|
||||
self.assertEqual(form.ttype, 'integer')
|
||||
|
||||
@tagged('test_eval_context')
|
||||
class TestEvalContext(TransactionCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user