تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3127 أدوات العرض

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') 
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 16
8664
1
أكتوبر 20
3538
1
سبتمبر 20
4515
1
ديسمبر 19
7029
0
مارس 15
4598