跳至內容
選單
此問題已被標幟
4 回覆
33940 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 24
2684
1
6月 24
5147
1
10月 23
10859
1
10月 23
98
1
8月 23
2193