@@ -217,16 +217,10 @@ def _get_theme_models():
217
217
}
218
218
219
219
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" )
224
221
FieldsPathPart .__doc__ = """
225
222
Encapsulate information about a field within a fields path.
226
223
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``
230
224
:param str field_model: model of the field
231
225
:param str field_name: name of the field
232
226
: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):
239
233
"""
240
234
Resolve model fields paths.
241
235
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``.
244
242
245
243
.. example::
246
244
@@ -261,35 +259,35 @@ def resolve_model_fields_path(cr, model, path):
261
259
"""
262
260
WITH RECURSIVE resolved_fields_path AS (
263
261
-- 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
270
267
FROM (VALUES (%(model)s, %(path)s)) p(model, path)
271
- LEFT JOIN ir_model_fields imf
268
+ JOIN ir_model_fields imf
272
269
ON imf.model = p.model
273
270
AND imf.name = p.path[1]
274
271
275
272
UNION ALL
276
273
277
274
-- 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
284
280
FROM resolved_fields_path rfp
285
- LEFT JOIN ir_model_fields rimf
281
+ JOIN ir_model_fields rimf
286
282
ON rimf.model = rfp.relation_model
287
283
AND rimf.name = rfp.path[rfp.part_index + 1]
288
284
WHERE cardinality(rfp.path) > rfp.part_index
289
- AND rfp.relation_model IS NOT NULL
290
285
)
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
293
291
""" ,
294
292
{"model" : model , "path" : list (path )},
295
293
)
0 commit comments