Odoo Help

0

odoo 8 sort tree view according to workflow states

By
Atakem
on 5/4/16, 11:57 AM 753 views

Hello,

I'm an odoo and python beginner and I'm building a small module for odoo, i have a model with a state attribute and i want to sort my tree view using the state field but i don't want the order to be done alphabetically.

here is my state field definition

state = fields.Selection(

[

('creation', "En création"),

('blocage', "Création"),

('listage', "A lister"),

('gel', "A geler + Analyse"),

('reponse', "A répondre"),

('avis', "Attente réponse client"),

('traitement', "En cours de traitement"),

('clos', "Clos"),

]

)

And i want the list view to be sorted according to the state so that records in 'creation' state will be the first one.

Thanks for helping.

did you try it?

Mohamed Essakali
on 5/5/16, 8:41 PM
0
Atakem
On 5/9/16, 6:43 AM

Hello, sorry for the delay.

Thanks for your answer.


We just updated our selection fields definition to use integer indexes and display string labels for users ...

state = fields.Selection(

[

('0', "En création"),

('1', "Création"),

('2', "A lister"),

('3', "A geler + Analyse"),

('4', "A répondre"),

('5', "Attente réponse client"),

('6', "En cours de traitement"),

('7', "Clos"),

]

)

It is actually working fine.

0
Mohamed Essakali
On 5/4/16, 3:06 PM

I suggest you to add a computed field and order by it like this:

......

    _order = "state_order asc"

......

@api.one

@api.depends('state')

def _get_state_order(self):

    state_list = [('creation', 1),('blocage', 2),('listage', 3),('gel', 4),('reponse', 5),('avis', 6),('traitement', 7),('clos', 8)]

    self.state_order = filter(lambda x: x[0] == self.state, state_list)[0][1]

...

    state_order = fields.Integer(string='State Order',  store=True, readonly=True, compute='_get_state_order')


Haven't time to check this code let you do it :)

Hope it will do the trick.

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/4/16, 11:57 AM
Seen: 753 times
Last updated: 5/9/16, 12:45 PM