Search code examples
odoo-11

Apply filter to t-foreach


Is there any t-filter tag capability in odoo 11 qweb template?

sample :

<tr t-foreach="o.line_ids" t-as="line_ids" t-filter="line_ids.name == 'car'">

Solution

  • You can use 'filtered' for filtering the records. So, you can do it like this:

    <tr t-foreach="o.line_ids.filtered(lambda x: x.name == 'car')" t-as="line_ids">
    

    According to the example from Odoo ORM API documentation:

    records.filtered(lambda r: r.company_id == user.company_id)
    

    filtered()

    returns a recordset containing only records satisfying the provided predicate function. The predicate can also be a string to filter by a field being true or false:
    

    This can also be applied in Qweb reports. You can read more about this here - https://www.odoo.com/documentation/online/reference/orm.html