Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

python - How to sort position stages using default_group_by field selection of kanban view in Odoo 12

I define stages of kanban view by selection field, like this:

state = fields.Selection([
    ('draft', 'Draft'),
    ('open', 'Open'),
    ('pending', 'Pending'),
    ('cancel', 'Cancelled'),
    ('done', 'Done')],
    'State',
    default='draft'
)

So I use default_group_by in xml to show this stages:

<kanban string="Kanban Sprint" default_group_by="state">
            <field name="name"/>
            <field name="state"/>

I want it sorts Draft>Open>Pending>Cancelled>Done.

But it sorts by alphabet: Cancelled>Done>Draft>Open>Pending. Image here

So is there a way to sort them?

question from:https://stackoverflow.com/questions/65894919/how-to-sort-position-stages-using-default-group-by-field-selection-of-kanban-vie

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can use group_expand method to set the order:

state = fields.Selection([
    ('draft', 'Draft'),
    ('open', 'Open'),
    ('pending', 'Pending'),
    ('cancel', 'Cancelled'),
    ('done', 'Done')],
    'State',
    group_expand='_expand_groups',
    default='draft'
)

@api.model
def _expand_groups(self, states, domain, order):
    return ['draft', 'open', 'pending', 'cancel', 'done']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...