콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6317 화면

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
26996
2
1월 25
6721
computed fields 해결 완료
1
4월 24
2691
1
12월 23
4862
2
11월 22
4030