Skip to Content
Menu
This question has been flagged
1 Reply
3402 Views

i want to return true if logged in user valid ..

but still not working

def _hide_working_hours(self):
current_user = fields.Many2one('res.users', 'Current User', default=lambda self: self.env.user.id)
if current_user != id:
return False
else:
return True

working_hours_view = fields.Boolean(computed=_hide_working_hours)


Avatar
Discard
Best Answer

Hi,

What exactly you are trying to do ? Suppose if you are adding this boolean field in the hr.employee model and if you want to compare whether the logged in user is the user of a certain employee, then try this,

def _hide_working_hours(self):
for rec in self:
uid = self.env.user.id
if self.user_id.id == uid:
rec.working_hours_view = True
else:
rec.working_hours_view = False

working_hours_view = fields.Boolean(compute='_hide_working_hours')

Thanks

Avatar
Discard
Author

i want to hide working hours field (view only for employee itself) by attrs based on computed field

Author

<record id="hide_working_hours_for_employees" model="ir.ui.view">

<field name="name">Hide Working Hours Employees Form</field>

<field name="model">hr.employee</field>

<field name="inherit_id" ref="hr.view_employee_form"/>

<field name="arch" type="xml">

<xpath expr="//field[@name='resource_calendar_id']" position="before">

<field name="working_hours_view"/>

</xpath>

<xpath expr="//field[@name='resource_calendar_id']" position="attributes">

<attribute name="attrs">{'invisible': [('working_hours_view' ,'=', False)]}</attribute>

</xpath>

</field>

</record>

You can update the compute function as answered and implement logic in attrs in xml

Author

i can't get logged in user id and compare with form user id

Related Posts Replies Views Activity
1
Jan 20
2093
0
Jan 20
2221
1
May 24
2149
3
Jun 23
14225
1
Mar 22
11723