@@ -217,16 +217,10 @@ def _get_theme_models():
217217 }
218218
219219
220- FieldsPathPart = namedtuple (
221- "FieldsPathPart" ,
222- "model path part_index field_model field_name relation_model" ,
223- )
220+ FieldsPathPart = namedtuple ("FieldsPathPart" , "field_model field_name relation_model" )
224221FieldsPathPart .__doc__ = """
225222Encapsulate information about a field within a fields path.
226223
227- :param str model: model to resolve the fields ``path`` from
228- :param typing.Sequence[str] path: fields path starting from ``model``
229- :param int part_index: index of this field in ``path``
230224:param str field_model: model of the field
231225:param str field_name: name of the field
232226:param str relation_model: target model of the field, if relational, otherwise ``None``
@@ -239,8 +233,12 @@ def resolve_model_fields_path(cr, model, path):
239233 """
240234 Resolve model fields paths.
241235
242- This function returns a list of :class:`~odoo.upgrade.util.helpers.FieldsPathPart` where
243- each item describes the field in ``path`` (in the same order).
236+ This function returns a list of :class:`~odoo.upgrade.util.helpers.FieldsPathPart`
237+ where each item describes a field in ``path`` (in the same order). The returned list
238+ could be shorter than the original ``path`` due to a missing field or model, or
239+ because there is a non-relational field in the path. The only non-relational field
240+ allowed in a fields path is the last one, in which case the returned list has the same
241+ length as the input ``path``.
244242
245243 .. example::
246244
@@ -261,35 +259,35 @@ def resolve_model_fields_path(cr, model, path):
261259 """
262260 WITH RECURSIVE resolved_fields_path AS (
263261 -- non-recursive term
264- SELECT p.model AS model,
265- p.path AS path,
266- 1 AS part_index,
267- p.model AS field_model,
268- p.path[1] AS field_name,
269- imf.relation AS relation_model
262+ SELECT imf.model AS field_model,
263+ imf.name AS field_name,
264+ imf.relation AS relation_model,
265+ p.path AS path,
266+ 1 AS part_index
270267 FROM (VALUES (%(model)s, %(path)s)) p(model, path)
271- LEFT JOIN ir_model_fields imf
268+ JOIN ir_model_fields imf
272269 ON imf.model = p.model
273270 AND imf.name = p.path[1]
274271
275272 UNION ALL
276273
277274 -- recursive term
278- SELECT rfp.model,
279- rfp.path,
280- rfp.part_index + 1 AS part_index,
281- rfp.relation_model AS field_model,
282- rfp.path[rfp.part_index + 1] AS field_name,
283- rimf.relation AS relation_model
275+ SELECT rimf.model AS field_model,
276+ rimf.name AS field_name,
277+ rimf.relation AS relation_model,
278+ rfp.path AS path,
279+ rfp.part_index + 1 AS part_index
284280 FROM resolved_fields_path rfp
285- LEFT JOIN ir_model_fields rimf
281+ JOIN ir_model_fields rimf
286282 ON rimf.model = rfp.relation_model
287283 AND rimf.name = rfp.path[rfp.part_index + 1]
288284 WHERE cardinality(rfp.path) > rfp.part_index
289- AND rfp.relation_model IS NOT NULL
290285 )
291- SELECT * FROM resolved_fields_path
292- ORDER BY model, path, part_index
286+ SELECT field_model,
287+ field_name,
288+ relation_model
289+ FROM resolved_fields_path
290+ ORDER BY part_index
293291 """ ,
294292 {"model" : model , "path" : list (path )},
295293 )
0 commit comments