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

I created custom field 'A' for sale.order table. field 'A' is defined as String in db. A values are numbers most of the time (eg. 50011) and sometimes default strings(eg. 'default'). I want to get top 10 A field numbers in a query. I wrote:

`recent_orders = request.env['sale.order'].sudo().search(
[('...')],
limit=10,
order='A desc')`
but it compares A data as strings. How can I make it compare them as integers and ignore string fields.
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

If default string is always 'default', you could try writing SQL query with cast function which converts value to your specified type:

result = self._cr.execute('select * from sale_order where A != 'default' order by cast(A as integer) desc limit 10') 
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 16
8684
1
ต.ค. 20
3547
Odoo13 override validate action method แก้ไขแล้ว
1
ก.ย. 20
4535
1
ธ.ค. 19
7038
0
มี.ค. 15
4606