콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
33941 화면

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
10860
1
10월 23
98
1
8월 23
2193