Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
8 Vastaukset
31346 Näkymät

Hello Odooers.

I want to add one value To Approve in state field on invoice after Draft.

so sequence will be like. draft,to approve,open,paid.

i know about attribute selection_add but it add value at the end of selection list.

any idea to add value at specific location.?



Avatar
Hylkää
Tekijä Paras vastaus

Finally got solution. Thanks Yenthe, to bring it up.

selection = [('a', 'A'), ('b', 'B')] 

selection_add = [('c', 'C'), ('b',)] 

> result = [('a', 'A'), ('c', 'C'), ('b', 'B')] 


https://github.com/odoo/odoo/blob/65d709c9ab386d646f682c494cfb21cb06ec8034/odoo/fields.py#L2058-L2067

Avatar
Hylkää
Paras vastaus

Hi Alpesh,

Sadly there is no way to do this in Odoo right now, its a limitation of the current framework. You'll either need to use selection_add to add the element at the end of the selection:

 state = fields.Selection(selection_add=[('to_approve', 'To approve')])

or recreate the whole field definition from scratch so you can add the selection value at the place you'd like:

state = fields.Selection(selection=[
    ('draft', 'Draft'),
    ('to_approve', 'To approve'),
    ('posted', 'Posted'),
    ('cancel', 'Cancelled')
    ], string='Status', required=True, readonly=True, copy=False, tracking=True,default='draft')


Regards,
Yenthe

Avatar
Hylkää
Tekijä

Thanks Yenthe. but i prefer to use selection_add.

hope odoo give some positional attribute to add it on specific location in future version.

Tekijä

its shows me warring in log, to use 'add_selection' instead of overwrite whole field.

Yeah and I can understand why :-) I know Odoo has discussed position attributes somewhere in the past (e.g. by adding a sequence to every key of a selection field) but it has never been implemented/approved by Odoo S.A. sadly.

Its an informative warning from Odoo that has been added in V13 (or V12). You can ignore it but its a fact that in most cases a selection_add is the best solution.

Tekijä

Right.