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

I have a two fields on employee.registration model in Odoo 10.

The fields are 

        require = fields.Boolean(string="Require")
state = fields.Selection([('draft','Draft'),('approval_pending','Sent for Approval'),('approved','Approved'),('approved_finally', 'Approved Finally'),('cancel','Cancel')], default='draft')


I have different states like draft, approval_pending,approved,approved_finally,cancel.  If require field equal to true, then cancel option button should be visible in approval_pending and approved state. If require field equal to false, then cancel option button should be visible in approval_pending only.


I tried to invisible the cancel button based on require and state field using attrs,

<button name="cancel_action" type="object" string="Cancel"  attrs="{'invisible': ['|', (('require', '=', True), ('state','in', ['draft','approved_finally','refused'])), (('require', '=', False), ('state','in', ['draft','approved','approved_finally','refused']))]}"/>

But its not working. Uncaught Error shown on attrs when I open the record.

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

hello,

Inside your attrs you are giving two values for same field.

Try making two cancel buttons and make one visible when required

<button name="cancel_action" type="object" string="Cancel"  attrs="{'invisible': ['|', ('require', '=', True), ('state','in', ['draft','approved_finally','refused'])]}"/>
<button name="cancel_action" type="object" string="Cancel"  attrs="{'invisible': ['|', ('require', '=', False), ('state','in', ['draft','approved','approved_finally','refused'])]}"/>
Also check when both are visible and make only one visible

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi Mohammed,

Thanks. It works correctly.