コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
3873 ビュー

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

関連投稿 返信 ビュー 活動
1
1月 20
2564
0
1月 20
2683
1
5月 24
2686
3
6月 23
15197
1
3月 22
12659