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
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
2
Antwoorden
11728
Weergaven
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden
Have a look into customization tips: https://goo.gl/8HgnCF