Search code examples
pythonpython-2.7odooodoo-10

Use mapped() in odoo 10


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.


Solution

  • 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.