How To View Or Hide Field By Attrs Based On Function (automatically)?
I want to view 'working_hours' field only for employee, his manager and 'hr.group_hr_user' group. how to hide this field automatically without edit form or trigger a button class
Solution 1:
Try below code for display working hours field only hr.group_hr_user
group users.
XML:
<recordid="hide_working_hours_for_employees"model="ir.ui.view"><fieldname="name">Hide Working Hours Employees Form</field><fieldname="model">hr.employee</field><fieldname="inherit_id"ref="hr.view_employee_form"/><fieldname="arch"type="xml"><xpathexpr="//field[@name='resource_calendar_id']"position="before"><fieldname="working_hours_view"invisible="1"/></xpath><xpathexpr="//field[@name='resource_calendar_id']"position="attributes"><attributename="groups">hr.group_hr_user</attribute></xpath></field></record>
You can add multiple attributes in the XML file like above code.
Solution 2:
i added the field before the function and it works now automatically
classInheritHrEmployee(models.Model):
_inherit = 'hr.employee'
inv = fields.Boolean(string="Invisible", compute="c_inv", store=False)
@api.onedefc_inv(self):
if self.env.uid == self.user_id.idor self.env.uid == self.parent_id.user_id.idor self.env.user.has_group(
'hr.group_hr_user'):
self.inv = Falseelse:
self.inv = True
.. like this example make fields visible to user and invisible to other
Post a Comment for "How To View Or Hide Field By Attrs Based On Function (automatically)?"