Difference between Search and Filter method in recordset in odoo12Community
Please Help..
Thanks in Advance...
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Difference between Search and Filter method in recordset in odoo12Community
Please Help..
Thanks in Advance...
Hi Aswathy,
With the search option you'll search for records within a table. For example to get out all contacts which are not archived:
# partner_ids will only give back all res.partner records that are not archived (so active) active_partner_ids = self.env['res.partner'].search([('active', '=', True)])
The filter method is to filter out specific records from a recordset. For example: you did a search for all partners that are active but now you want to filter out those records and only get out the customers:
customer_ids = active_partner_ids.filtered(lambda partner: partner.customer == True)
The filtered option is even documented in the official docs at https://www\\\\\.odoo\\\\\.com/documentation/12\\\\\.0/reference/orm\\\\\.html\\\\\#odoo\\\\\.models\\\\\.Model\\\\\.filtered\\\\\ \\\\\-\\\\\ in\\\\\ general\\\\\ the\\\\\ whole\\\\\ documentation\\\\\ about\\\\\ the\\\\\ ORM\\\\\ is\\\\\ a\\\\\ great\\\\\ topic\\\\\ to\\\\\ read\\\\\.\\\\\ See https://www.odoo.com/documentation/12.0/reference/orm.html#recordsets
In general you usually use a .search for doing database queries and getting specific results from the database. You'll use filtered() mostly when you want to filter out a part of a recordset in the Python code without doing database operations anymore.
Regards,
omar....12
still Yenthe, both returning back sub-list of the recordset the key difference between filter and search is that the search get the specified subset rather than return all the recordset and then filter it, which means big performance difference>
in such cases that we need to use search over filter :
1- comparing two operands {fields} no field against value
2- if you will domain with non-stored field
Create an account today to enjoy exclusive features and engage with our awesome community!
Registracija