Retrieve rows conditionally


In different modules I need to display only the lines which concerns the logged in user.

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.

Hope it helps!

It helps me yes, I found examples in the code but it’s still a bit fuzzy. I may ask you for help again soon.

thank you :slight_smile:

To create the registration rules I looked at the company module.

I think I need to adapt this:

<record model="" id="rule_group_sequence_companies">
    <field name="name">User in companies</field>
    <field name="model" search="[('model', '=', 'ir.sequence')]"/>
    <field name="global_p" eval="True"/>
<record model="ir.rule" id="rule_sequence_companies1">
    <field name="domain"
        eval="[('company', 'in', Eval('companies', []))]"
    <field name="rule_group" ref="rule_group_sequence_companies"/>
<record model="ir.rule" id="rule_sequence_comapnies2">
    <field name="domain" eval="[('company', '=', None)]" pyson="1"/>
    <field name="rule_group" ref="rule_group_sequence_companies"/>

but I don’t know what to put in the “domain” fields.
I also don’t know what to put in my python script.

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.