Odoo Help

1

How to hide form Edit button depends on field value?

By
Dariusz Kubiak
on 10/30/13, 10:06 AM 9,093 views

I have project issue form for portal customer which they can edit only on state 'new'. Customer can change some of the issue state pressing buttons. I can make fields read only depends on the state, but the Edit button is visible on every state which confuses the user. To hide the button completely I can use <form edit=”false”>...</form>, but it's not the point.

The question is: How to hide Edit button in other states except 'new'? The lines below don't work.

<form attrs="{'edit': [('state','=','new')]}">
   <field name="state">
</form>

Why? Because the form attribute depends on the field which is on the form? Or the syntax is wrong?

which are the other state of your form ??

Bhavesh
on 10/31/13, 6:57 AM
3
deep
On 7/28/14, 3:35 AM

Hi...

One cannot hide/show ORM buttons like EDIT/SAVE/DELETE etc based on form data...

Because according to OPENERP framework, view(XML) is loaded first, then data will be retrived from database... hence one cannot change the view based on data...

So feasible option to control your data from editing is through locking the fields using States....

 

 

 

0
Maximiliano
On 7/26/14, 7:42 PM

can you find a solution?

0
shashank verma
On 7/28/14, 10:39 AM

Hello Darek,

This is very much possible by using fields_view_get() ORM method:

 

Following code:

    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=True, toolbar=False, submenu=False):
        
      
        result = super(my_model, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
        if view_type=='form':
            current_id=context.get('active_id', False)
            my_state=self.browse(cr,uid,current_id).state
            if my_state=='new':
                modify_edit_str='edit="false"'
                result['arch']='<form string="My configuration "  %s version="7.0">\n...................... so onnnnn'%(modify_edit_str)
            else:
                pass
                
            return result

This code going to work smooth.The only problem i faced at the moment is to get active id .If you somehow get active id of your model this model then edit button can be visible/invisible according to your state.

 

0
le_dilem
On 10/30/13, 12:40 PM

Hi the syntax is wrong

 <button name="button_name"  attrs="{'invisible':[('state','=','draft')]}"/>

Thank you for answer, but the question was about the default form Edit button, which doesn't have a specific name. That's why I gave the example <form edit=”false”>...</form>

Darek
on 10/30/13, 12:56 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 10/30/13, 10:06 AM
Seen: 9093 times
Last updated: 8/25/15, 2:31 PM