Search code examples
odooodoo-8

Getting the Employee id of the Log User in Odoo - 8


Good Day I have a problem in filtering of Odoo 8 Field I just want to Select only the Employee id of the Log User i just add this in my XML

<field name="employee_id" style = "width:500px" domain = "[('id', '=', user.id.employee_id.id)]" options="{'no_create': True}"/>

But I have an Error it says

Uncaught Error: NameError: name 'user' is not defined.

Is there a right way to get the Employee Id of a Log User here in Odoo 8 ?


Solution

  • To obtain the employee of the logged user I do this way:

    resource = self.env['resource.resource'].search([('user_id','=',self.env.user.id)])
    employee = self.env['hr.employee'].search([('resource_id','=',resource.id)])
    

    Of course it is not easy to put it inside a domain, thus maybe you can use a stored computed field to save the user_id of the employee inside your table, then you can write the domain this way:

    [('user_id', '=', uid)]