Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
33956 มุมมอง

Hello,

I'm working on Employee Directory module in odoo11 and I want to set a notebook page invisible to the current user (Logged user) if he is different to the related user.

I tried to use user.id in XML but it does not work.

Here is my code :

<page name="hr_settings" string="HR Settings" attrs="{'invisible': [('user_id', '!=', user.id)]}">
<group>
<group string='Status' name="active_group">
<field name="company_id"/>
<field name="user_id" string="Related User"/>
</group>
</group>
</page>

The error message :

<class 'NameError'>: "name 'user' is not defined" while evaluating

"{'invisible': [('user_id', '!=', user.id)]}"

None" while parsing /opt/odoo/odoo/my_addons/hr_dz/views/employee_views.xml:5, near

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

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

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

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

<form string="Employee">

<sheet>

<div class="oe_button_box" name="button_box">

<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">

<field name="active" widget="boolean_button" options="{&quot;terminology&quot;: &quot;archive&quot;}"/>

</button>

</div>

<div id="o_employee_container">

<div id="o_employee_main">

<field name="image" widget="image" class="oe_avatar" options="{&quot;preview_image&quot;:&quot;image_medium&quot;}"/>

<div class="oe_title">

<label for="name" class="oe_edit_only"/>

<h1>

<field name="name" placeholder="Employee's Name" required="True"/>

</h1>

</div>

Any idea about that, please ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You should override fields_view_get() method.

See this answer for the solution

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Create a  Boolean field in the model and compute value to that field based on the checking it is related user or not. Then Based on the value in this field, hide the page using attrs.

Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try this :

<page name="hr_settings" string="HR Settings" invisible="context.get('uid') not in YourListOfIds">
this <page> wont be visible if the current id not in YourListOfIds.

for example if you want to this page visible only for the admin user then : YourListOfIds = [1]
  To create a custom list of ids :
  1. enable developer mode.

  2. retreive the id of the users in settings/users/users.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

try this,

('user_id','=',uid)


Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 24
2686
1
มิ.ย. 24
5148
1
ต.ค. 23
10866
1
ต.ค. 23
98
413 Request Entity Too Large แก้ไขแล้ว
1
ส.ค. 23
2193