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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
2
Trả lời
11914
Lượt xem
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký
Have a look into customization tips: https://goo.gl/8HgnCF