Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4 Antworten
33960 Ansichten

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

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
Verwerfen
Beste Antwort

Hello,

try this,

('user_id','=',uid)


Thanks

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Juli 24
2686
1
Juni 24
5148
1
Okt. 23
10866
1
Okt. 23
98
1
Aug. 23
2193