Use mapped() in odoo 10

Karara Mohamed picture Karara Mohamed · Sep 25, 2017 · Viewed 7.4k times · Source

What is mapped and how use this in odoo 10? And how to use mapped and filter in Odoo 10? example

result = sum( order.order_line.filtered(
                lambda r: r.state != "state" ).mapped( "field_name" ) 
)

and multiply each value of field1 by other field2 in same table an return all sum.

Answer

dani herrera picture dani herrera · Sep 25, 2017

Is fully documented on Odoo docs:

mapped(): applies the provided function to each record in the recordset, returns a recordset if the results are recordsets. The provided function can be a string to get field values.

# returns a list of names
records.mapped('name')

In your code the expression order.order_line.filtered( lambda r: r.state != "state" ).mapped( "field_name" ) returns a list of field_name from order. Then sum python function do the sum.