跳至内容
菜单
此问题已终结
3 回复
5226 查看

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?

编写者 最佳答案

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.

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
10月 16
3605
1
9月 15
10026
0
7月 24
619
1
10月 19
2425
2
5月 19
20240