I want to set all fields readonly in specific state in form view only. i inherit the model and try to make fields readonly using fields_view_get() method. i don't want to use attributes in xml view. in Odoo v12 it's working with use of setup_modifiers().
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
2
Replies
11189
Views
Hi,
You can try the following code
import json
from lxml import etree
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(YourClass, self).fields_view_get(view_id=view_id,
view_type=view_type,
toolbar=toolbar,
submenu=submenu)
if (your_condition):
doc = etree.XML(res['arch'])
for field in res['fields']:
for node in doc.xpath("//field[@name='%s']" % field):
node.set("readonly", "1")
modifiers = json.loads(node.get("modifiers"))
modifiers['readonly'] = True
node.set("modifiers", json.dumps(modifiers))
res['arch'] = etree.tostring(doc)
return res
Regards
I try this solution in V14 and not working
For that you can hide the edit button using below code
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AccountMove, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,submenu=submenu)
if (YOUR condition):
doc = etree.fromstring(res['arch'])
if view_type=='form':
node = doc.xpath("//form")[0]
node.set("edit", "0")
res['arch'] = etree.tostring(doc)
return res
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
Have a look into customization tips: https://goo.gl/8HgnCF