跳至內容
選單
此問題已被標幟
8 回覆
31353 瀏覽次數

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.?



頭像
捨棄
作者 最佳答案

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

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

Thanks Yenthe. but i prefer to use selection_add.

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

作者

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.

作者

Right.