Reputation: 3613
I know to make a field readonly with the "readonly" attribute. Is it possible to make the entire record readonly. That means that all field in a form should be readonly on a condition.
One insignificant way i found is to make this attrs="{'readonly':[('state','=','close')]}" in all the fileds present in the form.
<field name="responsible_id" class="oe_inline" attrs="{'readonly':
<field name="type" attrs="{ 'readonly':[('state','=','close')]}" class="oe_inline"/>
<field name="send_response" attrs="{'readonly':[('state','=','close')]}"/>[('state','=','close')]}"/>
However i don't think this be the right one. I expect some way to put readonly attribut common for the form. Kindly suggest.
In my example, People can view all the records and edit only their own records.
Thank You.
Upvotes: 0
Views: 1521
Reputation: 2766
Put this in your Python imports:
from lxml import etree
from openerp.osv.orm import setup_modifiers
And modify the fields in the fields_view_get
method like this:
def fields_view_get(self, cr, uid, view_id=None, view_type=None, context=None, toolbar=False, submenu=False):
res = super(MyClass, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type,
context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
# Set all fields read only when state is close.
doc = etree.XML(res['arch'])
for node in doc.xpath("//field"):
node.set('attrs', "{'readonly': [('state', '=', 'close')]}")
node_name = node.get('name')
setup_modifiers(node, res['fields'][node_name])
res['arch'] = etree.tostring(doc)
return res
This will modify every field on the form to include the attrs="{'readonly':[('state','=','close')]}"
attribute.
Upvotes: 2