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

1.9k views Asked by At

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?

2

There are 2 answers

1
Ludwik Trammer On BEST ANSWER

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",
)
0
Emipro Technologies Pvt. Ltd. On

Your fields declaration seems that it's Odoo-8 code, in V8 _defaults is not there you need to write as below,

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

And there is no more logic to set sequence in status bar but then also try this,

<form string="String" version="7.0">
    <header>
        <field name="state" widget="statusbar" statusbar_visible="new,open,closed" clickable="True"/>
    </header>
</form>