Skip to Content
Menu
This question has been flagged
1 Reply
16543 Views

Hello,


I'm using Odoo 13 Community Edition.


I need some help to understand self.env.search and self.env.search clearly.


In my case I need to search some ids, but it only should find the ids that match to every given value. For example:


        for rec in self:

            zb_get = rec.env['stock.location'].sudo().search([('name', '=', 'MGtec: Umschlaglager')], limit=1)

            domain_done = [('sale_order_id_mg', '=', rec.id), ('location_id', '=', zb_get.id), ('state', '=', 'done')]

            lief_zb_ids_done = self.env['stock.picking'].sudo().search_count(domain_done)


'zb_get' catches the right id and 'sale_order_id_mg' is working too (that is a field from my custom module).

The problem is that it returns much more ids than it should.


I tried also:

domain_done = ['&', '&', ('sale_order_id_mg', '=', rec.id), ('location_id', '=', zb_get.id), ('state', '=', 'done')]


And:

domain_done = ['|', '|', ('sale_order_id_mg', '=', rec.id), ('location_id', '=', zb_get.id), ('state', '=', 'done')]


So I think I dont understand how self.env.search and self.env.search_count are working correctly.

Avatar
Discard
Best Answer

SEARCH COUNT

Returns the count of results matching search domain:

>>>self.env['account.invoice'].search_count([('get_patient_barcode','=',self.get_patient_barcode),('state','in',['open','paid'])])

20
Avatar
Discard

can you compare performance between search and search_count? If I use search, I can use len() to count recordset. If I use search_count, I will not have recordset

Related Posts Replies Views Activity
2
Feb 23
11354
1
Mar 22
1377
1
Aug 24
4281
1
Dec 19
6323
1
Mar 17
11218