Odoo Help

0

How to hide field based on condition?

By
Anirudh Lou
on 3/16/15, 9:27 PM 1,260 views

Hello to all, Does anyone knows how to solve this kind of situation? I have created security access on hr_contract. However, there are case where sometimes, the users cannot see some field. Here is the situation, on hr_employee i add field is_confidential and on hr_contract, if is_confidential (field on hr_employee) is checked, the user (let say HR I) cannot see employee's Wage and his Salary Structure but (HR II) can view this field including those confidential.


Any help is very much appreciated. Thank you.

1

Vasanth

--Vasanth--
Vasanth
3468
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
On 3/17/15, 3:33 AM

Hi Anirudh, try this :

In hr_employee:

'is_confidential': fields.boolean('Is Confidential')   (your field)

In hr_contract.py '

'is_confidential': fields.related('employee_id',is_confidential', type='boolean', relation='hr.employee', string="Is Confidential"),

In xml_view:
<field name="is_confidential" invisible="1" />
<field name="your field"  groups="user1_group" attrs="{'invisible': [(''is_confidential','!=','True')]}" />

In that case sir, both user1 and user2 cannot view the 'your_field' whenever 'is_confidential' is True. In my case, i want that only user1 can view employee's wage regardless if he or she is confidential but not on user2, beacuse if that employee is confidential then user2 cannot view it.

Anirudh Lou
on 3/17/15, 4:22 AM
0

zbik

--zbik--
6039
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 3/17/15, 3:33 PM

You use two fields: your_filed and your_field_related. XML in this case:

<field name="is_confidential" invisible="1" />

<field name="your_field" groups="user1_group" attrs="{'invisible': [(''is_confidential','!=','True')]}" />

<field name="your_field_related" groups="user2_group"/>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 3/16/15, 9:27 PM
Seen: 1260 times
Last updated: 2/19/16, 2:43 AM