HI,
I have 3 field in my view
<field name="name" />
<field name="date" />
<field name="nbc" />
I want set name and date field read only for hr_manager. how can i ?
Any help ??
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
HI,
I have 3 field in my view
<field name="name" />
<field name="date" />
<field name="nbc" />
I want set name and date field read only for hr_manager. how can i ?
Any help ??
Create function field that returns a value based on the user's group and then use attrs attributes on fields to control.
Reference :https://answers.launchpad.net/openobject-server/+question/178779
Thanks
Hi, you can use this as example...
'name': fields.char('Name', size=128, read=['base.group_userA'], write=['base.group_userB'] )
Read will allow the user group to view and Write will allow the user group to edit the field..
I have try this but its not working
*EDITED*
One solution is to combine a function field with the attrs tag:
.py:
def _get_uid_is_manager(self, cr, uid, ids, field_name, arg, context=None):
res = {};
manager_group_id = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'group_hr_manager').id
manager_ids = self.pool.get('res.user').search('groups_id', '=', manager_group_id);
for obj in self.browse(cr, uid, ids, context=context):
res[obj.id] = uid in manager_ids;
return res;
'uid_is_manager': fields_function(_get_uid_is_manager, type='boolean', method=True, string='Current User is Manager?'
.xml:
<field name="name" attrs="{'readonly': [('uid_is_manager' ,'=', True)]}"/>
<field name="date" attrs="{'readonly': [('uid_is_manager' ,'=', True)]}"/>
Regards.
@René Schuster: Thanks for the answer, I want make read only dont want hide.By using this code its hide for other user.
Sorry, got you wrong. I've edited my answer (but was slower than prakash ^^).
Use fields_get to achieve this:
Eg.
@api.model
def fields_view_get(self, view_id='OdooModule.test_form_view', view_type='form', toolbar=False, submenu=False):
res = super(Test, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,
submenu = submenu)
doc = etree.XML(res['arch'])
if not self.env.user.has_group('group_admin') or self.env.user.has_group('group_ad_doctor'):
for node in doc.xpath("//field[@name='laboratory']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='test_type_id']"):
node.set('modifiers', '{"readonly": true}')
for node in doc.xpath("//field[@name='patient_id']"):
node.set('modifiers', '{"readonly": true}')
res['arch'] = etree.tostring(doc)
return res
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
oct 24
|
1391 | ||
Make field readonly based on group
Resuelto
|
|
9
jul 21
|
62599 | |
|
3
ago 24
|
15679 | ||
|
0
may 23
|
1597 | ||
|
1
mar 23
|
2145 |