How it works...

Step 1 is just defining the method. In step 2 , we call the mapped(path) method to traverse the fields of the recordset; path is a string that contains field names separated by dots. For each field in the path, mapped() produces a new recordset that contains all the records related by this field to all elements in the current recordset. It then applies the next element in the path on that new recordset. If the last field in the path is a relational field, mapped() will return a recordset; otherwise, a Python list is returned.

The mapped() method has two useful properties:

  • If the path is a single scalar field name, then the returned list is in the same order as the processed recordset
  • If the path contains a relational field, then the order is not preserved, but duplicates are removed from the result
This second property is very useful in a method that's decorated with @api.multi, where you want to perform an operation on all the records that are pointed to by a Many2many field for all the records in self, but you need to ensure that the action is performed only once (even if two records of self share the same target record).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset