Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how i can Order BY Group BY ?

By
Ahmed elbarbary
on 6/18/15, 7:31 AM 1,036 views

i want to group_by my projects with its state and the state is a selection field (initiation, implementation, execution, monitoring, testing, closure phase , closed, pending) but the problem is when i group_by the projects it grouped with alphabetical sort but i need it ordered by the same order in the selection field , could anyone help me ?

0
Jean-Charles Drubay
On 10/6/15, 5:09 AM

In version 8

You need to override the function read_group like this:

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
if 'state' in groupby:

orderby = 'state ASC' + (orderby and (',' + orderby) or '')

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


Note that in case you need to order on a field many2one, the default order by field of the model will be used. However, the ASC/DESC is ignored so you will need to use a similar way as above to force the ASC/DESC.

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
if 'state_id' in groupby:
orderby = 'state_id ASC' + (orderby and (',' + orderby) or '')
return super(trobz_crm_lead, self).read_group( domain, fields, groupby, offset=0, limit=limit, orderby=orderby, lazy=lazy)


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/18/15, 7:31 AM
Seen: 1036 times
Last updated: 10/6/15, 5:09 AM