Hi T Ketaki Debadarshini,
You can achieve this by using following code
In Python
from lxml import etree
@api.model
def fields_view_get(self, view_id='you_form_view_id', view_type='form', toolbar=False, submenu=False):
res = super(ClassName, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu=submenu)
doc = etree.XML(res['arch'])
if self.env.user.has_group('group1'):
for node in doc.xpath("//field[@name='field1']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
elif self.env.user.has_group('group2'):
for node in doc.xpath("//field[@name='field2']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='field3']"):
node.set('modifiers', '{"readonly": true}')
res['arch'] = etree.tostring(doc)
return res