Odoo Help


How can I pass a variable to .filtered to filter a recordset dynamically?

Jesse Rye
on 11/11/16, 6:41 PM 1,099 views

I am trying to pass a list of order_ids to .filtered so as to exclude them from my recordset but I seem to be getting an error global name "order_ids" is not defined. Below is an example of my code.

active_ids = ['34','35',36']
p = self.env['stock.pack.operation']
p_obj = p.search([['id','in',active_ids]])
order_ids = ['1','2','3'] 
p_obj.filtered(lambda r: r.origin_id.id IN order_ids)

This issue is regarding Odoo 9.

Jesse Rye
on 11/11/16, 6:42 PM
Nicolas JEUDY
On 3/1/17, 12:40 PM


I use with_context to enable this:


p_obj.with_context(filter_order_ids=order_ids).filtered(lambda r: r.origin_id.id IN r._context['filter_order_ids'])


Think it can be your solution ...

Jesse Rye
On 11/12/16, 6:10 PM

Thanks for your reply. I wanted to use filtered so I could filter the recordset already being used rather than creating a completely new recordset.


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 11/12/16, 5:22 PM

Search for specific ids makes no sense(at least that you want to make sure that an id really exists), use a direct browse to that like:


or you could directly search for that using the proper domain, because 

p_obj = self.env['stock.pack.operation'].search([('id', 'in, [34,35,36]), ('origin_id.id', 'in', [1,2,3]))

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/11/16, 6:41 PM
Seen: 1099 times
Last updated: 3/1/17, 12:40 PM