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

Hello everyone,

I would like to ask you if it is possible to sort alphabetically  m2o fields by its name ASC/DESC in read_group method. By default it is sorted just by database ID and I am not able to reference the name column for the field (categ_id.name ASC does not work, only categ_id ASC => sorting based on ID, see code below). Many thanks for your help!

@api.model

def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):

if 'categ_id' in groupby:

    orderby = 'categ_id.name ASC' + (orderby and (',' + orderby) or '')

return super(ProductTemplate, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)

アバター
破棄

In read group param you have to define the order and the param based on which you wanna order(needless to say that the param needs to be present on the model being searched on). So try this:-

super(ProductTemplate, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby="param ASC",

lazy=lazy)

最善の回答

did you find a solution?

アバター
破棄
関連投稿 返信 ビュー 活動
2
10月 22
27029
2
1月 25
6752
1
4月 24
2718
1
12月 23
4906
2
11月 22
4062