Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4162 Представления

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)


Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор

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

Автор

<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

Автор

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

Related Posts Ответы Просмотры Активность
1
янв. 20
2947
0
янв. 20
3170
1
мая 24
3023
3
июн. 23
15942
1
мар. 22
13385