Fix get_views: include comodel field metadata for O2M/M2M inline views

The web client needs field metadata for sub-models when rendering
inline list views inside form views (e.g., sale.order.line inside
sale.order form). Now iterates all relational fields and adds their
comodel to the models dict in the get_views response.

Fixes "Cannot read properties of undefined (reading 'fields')" error
on sale.order and account.move stored form views with O2M tabs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc
2026-04-02 21:40:16 +02:00
parent 03fd58a852
commit e8fe84b913

View File

@@ -75,13 +75,32 @@ func handleGetViews(env *orm.Environment, model string, params CallKWParams) (in
} }
} }
// Build models dict with field metadata // Build models dict with field metadata.
// Include the main model + all comodels referenced by relational fields.
// Mirrors: odoo/addons/web/models/models.py _get_view_fields()
models := map[string]interface{}{ models := map[string]interface{}{
model: map[string]interface{}{ model: map[string]interface{}{
"fields": fieldsGetForModel(model), "fields": fieldsGetForModel(model),
}, },
} }
// Add comodels (needed for O2M/M2M inline views and M2O dropdowns)
m := orm.Registry.Get(model)
if m != nil {
for _, f := range m.Fields() {
if f.Comodel != "" {
if _, exists := models[f.Comodel]; !exists {
comodelFields := fieldsGetForModel(f.Comodel)
if len(comodelFields) > 0 {
models[f.Comodel] = map[string]interface{}{
"fields": comodelFields,
}
}
}
}
}
}
return map[string]interface{}{ return map[string]interface{}{
"views": views, "views": views,
"models": models, "models": models,