コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
3146 ビュー

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
12月 16
8679
1
10月 20
3544
1
9月 20
4533
1
12月 19
7036
0
3月 15
4604