Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6327 Visualizzazioni

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)

Avatar
Abbandona

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)

Risposta migliore

did you find a solution?

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
ott 22
27007
2
gen 25
6728
1
apr 24
2697
1
dic 23
4865
2
nov 22
4037