Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
18531 Vues

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
Ignorer
Meilleure réponse

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
Ignorer

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

Publications associées Réponses Vues Activité
2
févr. 23
12620
1
mars 22
2120
1
août 24
5834
1
déc. 19
7390
1
mars 17
12173