Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2836 Lượt xem

I am working with Odoo 18 and have inherited the state field from account.move. I added a new state (to_approve) to the selection using selection_add. However, in the status bar, the states are not displayed in the correct order (draft → to_approve → posted). Instead, they appear as draft → posted → to_approve.

Here’s my code:

/python file snippet-----------------------

state = fields.Selection(

    selection_add=[("to_approve", "To Approve")],

    ondelete={'to_approve': 'set default'}

)

/xml file snippet-----------------------

<field name="state" position="attributes">

    <attribute name="statusbar_visible">draft,to_approve,posted</attribute>

</field>


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

By default, new states added with selection_add are appended to the end of the existing selection list, which disrupts the desired order.

You can explicitly reorder the states by including existing ones in your selection_add.

state = fields.Selection(

    selection_add=[("to_approve", "To Approve"), ("posted",)],

    ondelete={'to_approve': 'set default'}

)

("posted",) is an existing option from the original state field. By including it in selection_add, you are effectively redefining its position in the list.


In your XML file, ensure the statusbar_visible attribute aligns with the desired order:

<field name="state" position="attributes">

    <attribute name="statusbar_visible">draft,to_approve,posted</attribute>

</field>


The status bar will now display the states in the desired order: Draft → To Approve → Posted.


Best Regards,

NIZAMUDHEEN MJ
Accurates

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 1 24
15940
0
thg 10 23
2369
4
thg 5 19
12322
1
thg 3 15
7225
2
thg 3 15
6338