Skip to Content
Menu
This question has been flagged
3 Replies
4675 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.

Avatar
Discard

did you try it?

Author Best Answer

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.

Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 16
2991
1
Sep 15
9324
0
Jul 24
137
1
Oct 19
1960
2
May 19
18859