In different modules I need to display only the lines which concerns the logged in user.
example:
A view returns all registered leave requests.
User “A” logs in and opens this view. I want him to only have access to leave requests that concern him.
How can I do this?
I tried to do this directly in the “setup” function of a module but I can’t find how to filter my request or how to retrieve the “employee” context variable.
“Transaction().context.get(‘employee’)” returns “None”
You need to add some Record Rules to restrict which records the user is allowed to see. Once you’ve defined the rule the trytond server will filter out the records that the user is not allowed to see.
You need to include the domain that limites the records that the user is allowed to see.
In your example, the user is just allowed to see the records that the company is in the list of companies the user is allowed to access.
so in the python class which defines the model hr.employee.spending you need to handle employee and employees. So maybe employees is always empty or filled with wrong values?
If it is working with '2' as value, it means that the employee field is not a Many2One but a Char.
So the Eval('employees', []) is filled by the company with a list of ids not char.
No employees is filled by the company module because rule evaluation is done with ir.rule context.