Skip to Content
Menu
This question has been flagged
2 Replies
16257 Views

HI All,

I have spent most of the day on this issue and would be great to get some help.

Basically I am wanting to filter the records for a new module based on the person being in a particular group.


First Attempt: Tried to filter on users who belong to a particular group and was unable to find online any logic that would do this.  I am basically trying to use a DOMAIN that does something like the following:

<field name="domain">[('employee_recruitment.group_hr_manager','in',context.get('uid').groups)]</field> 


Full record shown below:

        <record model="ir.actions.act_window" id="recruitment_request_act">

            <field name="name">Recruitment Request</field>

            <field name="res_model">recruitment.request</field>

            <field name="view_type">form</field>

            <field name="view_mode">tree,form</field> 

   <field name="domain">[('employee_recruitment.group_hr_manager','in',context.get('uid').groups)]</field> 

            <field name="help" type="html">

                <p class="oe_view_nocontent_create">

                    Click to create a recruitment request.

                </p>

            </field>

        </record>


Method Two:

Created a dynamic variable to calculate whether the current user has approver rights or not and then reference that field within the domain as follows:

Add following Variable:

is_approver = fields.Boolean('Is Approver', compute='_get_is_approver', track_visibility='onchange')

Add function:

@api.one

def _get_is_approver(self):

approver_group = self.env.ref('employee_recruitment.group_hr_manager') 

users = approver_group.users

for user in users:

if user.id == self._uid:

self.is_approver = True

return

self.is_approver = False 

Add domain to record:

<field name="domain">[("is_approver_store","=",True)]</field>

Neither method works and assume that calculated fields do not work within the domain?


Any thoughts on how I might be able to achieve this?

Thanks,
Damien

Avatar
Discard
Best Answer

have you tried applying record rule? Or record rule isn't a solution for what you want to achieve?

What I understand by description is, you want to filter records based on groups assigned to user, which is possible by record rule.

If you want to send recruitment.request to hr_manager for approval, you will need to set state on recruitment.request, so that whenever request is in waiting for approval state, that request will only be visible to hr_manager.

<record id="recruitment_request_rule" model="ir.rule">
<field name="name">Recruitment Request</field>
<field ref="model_recruitment_request" name="model_id"/>
<field name="domain_force">[('state', '=', 'waiting_approval')]</field>
<field name="groups" eval="[(4, ref('employee_recruitment.group_hr_manager'))]"/>
</record>

above record rule will make records visible only to hr manager,

For other users to allow create request, you will need to create another record rule.

i.e.

<record id="recruitment_request_base_user_rule" model="ir.rule">
<field name="name">Recruitment Request Users</field>
<field ref="model_recruitment_request" name="model_id"/>
<field name="domain_force">[('user_id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record
Avatar
Discard