Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
5471 Vistas

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
Descartar

did you try it?

Autor Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
oct 16
3829
1
sept 15
10410
0
jul 24
905
1
oct 19
2623
2
may 19
20702