İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
33939 Görünümler

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 ?

Avatar
Vazgeç
En İyi Yanıt

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
Avatar
Vazgeç
En İyi Yanıt

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

Avatar
Vazgeç
En İyi Yanıt

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.

Avatar
Vazgeç
En İyi Yanıt

Hello,

try this,

('user_id','=',uid)


Thanks

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Tem 24
2684
1
Haz 24
5147
1
Eki 23
10859
1
Eki 23
98
1
Ağu 23
2193