Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
5557 Tampilan

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
Buang

did you try it?

Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Okt 16
3941
1
Sep 15
10530
0
Jul 24
1037
1
Okt 19
2741
2
Mei 19
20902