Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
18598 มุมมอง

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง

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 ตอบกลับ มุมมอง กิจกรรม
self search based on field แก้ไขแล้ว
2
ก.พ. 23
12671
1
มี.ค. 22
2159
Where to learn more about self.env? แก้ไขแล้ว
1
ส.ค. 24
5899
1
ธ.ค. 19
7455
1
มี.ค. 17
12225