Odoo Help


This community 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.


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

Martin King
on 2/23/15, 1:58 PM 344 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

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


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