Odoo Help


How to add a constraint based on the current logged-in user?

Martin King
on 2/23/15, 1:58 PM 628 views

New Odoo user here. I'm trying to add a custom view to the HR module where you can only see the remaining vacation days of the employee related to the logged-in user, but I don't know how to make a reference to the logged-in user as there's no field to reference it in the hr.employee model.  

Here's what I have so far:

        <record model="ir.ui.view" id="sq_employee_leave_view">
            <field name="name">sqemployeeleaves.form</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr_holidays.view_employee_form_leave_inherit"/>            
            <field name="arch" type="xml">
                <xpath expr="//field[@name='remaining_leaves']" position="replace">
                    <field name="remaining_leaves" attrs="{'invisible':[('user_id', '!=', uid)]}"/>

This gives me a 'uid is not defined' error.  Can anyone tell me how to go about referencing the current user?  I'm working in Odoo 8.  Thanks!

Hi Cyril, I don't have enough karma to comment on your post yet but the suggested fix didn't work. It didn't throw an error but uid is still not recognized as the current logged-in user so the constraint doesn't work. Thanks for the help, though!

Martin King
on 2/24/15, 1:45 PM

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.


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

1 follower(s)


Asked: 2/23/15, 1:58 PM
Seen: 628 times
Last updated: 3/16/15, 8:10 AM