Skip to content
Advertisement

Read one2many field in inherited model

In odoo v13, the crm.lead model is inherited and modified by the sale_crm module.

In the sale_crm module, the model crm.lead is inherited and a one2many field is added, order_ids. This is an array of sales orders associated with the lead.

I am trying to inherit the crm.lead model, and create a new field that is computed using the order_ids field.

  1. I added sale_crm in the manifest dependencies

  2. I inherit the crm.lead model and attempt to concat the names of all the associated SOs:

    JavaScript

Unfortunately, this causes a stack overflow (haha!)

I believe I need to use .browse on the order_ids field but I’m not able to find any examples on how to do this.

Advertisement

Answer

The compute method must assign the computed value to the field. If it uses the values of other fields (order_ids.name), it should specify those fields using depends().

You don’t need to use super here, self is a record set, so loop over it to access the value of order_ids for each record.

Example:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement