Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
20080 Widoki

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)
Awatar
Odrzuć
Autor

This issue is regarding Odoo 9.

Autor

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.

Najlepsza odpowiedź

Hello, 

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

Awatar
Odrzuć
Najlepsza odpowiedź

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:

 self.env['stock.pack.operation'].browse([34,35,36])

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]))


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 17
7599
1
sie 17
8797
2
maj 24
3547
1
gru 19
2930
1
sie 25
302