Search code examples
defaultstatusbarodooodoo-8

Odoo8 - how can I sort status bar and set default as new?


I have created a new module in Odoo for helpdesk and I have 2 problems that I can't seem to fix or find information on so need some help.

I created a status bar (code):

state = fields.Selection({('new','New'), ('open','In Progress'), ('closed','Closed')}, "Status")
_defaults = {
    'state': 'new'
}



<header>
<field name="state" widget="statusbar" statusbar_visible="new,open,closed" clickable="True"/>

Even thought I have stated "new, open, closed" it is showing in Odoo as open,new, closed.

I set the state default as new, even though I am not getting any errors, when I click on create it shows state as blank.

Any ideas on how to fix these issues?


Solution

  • When you declared your field you gave it a set of options instead of a list of options. Sets in Python doesn't keep the information about items order, but lists do. For your declared order to be respected you just need to replace the set literal by a list literal:

    state = fields.Selection(
        [('new','New'), ('open','In Progress'), ('closed','Closed')],
        "Status",
    )
    

    You can remove statusbar_visible from your view.


    As for your second problem (with the default value) Emipro Technologies is correct. You need to declare the default value as an argument on your field:

    state = fields.Selection(
        [('new','New'), ('open','In Progress'), ('closed','Closed')],
        default='new',
        string="Status",
    )