Make form fields readonly based on a condition - Odoo 10
Hello everybody, I would like to make my form fields readonly in my model based on a condition, I'm trying it with fields_view_get for not add "attrs readonly" in each field in my xml file, I have the following code:
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
doc = etree.XML(res['arch'])
for field in res['fields']:
for node in doc.xpath("//field[@name='%s']" % field):
res['arch'] = etree.tostring(doc)
But it doesn't work, what could be my problem? Thank you so much!