콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
8 답글
31422 화면

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.