تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
15649 أدوات العرض

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.

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

Hi Mohammed,

Thanks. It works correctly.