Home > Blockchain >  A record rule to restrict employees from publishing jobs, odoo 14
A record rule to restrict employees from publishing jobs, odoo 14

Time:11-19

I want to create one level record rule that restricts employees from publishing the job and sending it to the manager for approval. Like if they want it published and click on the publishing button, it should send the request to the manager to publish the job, and let them know. Here's my code:

<record id="group_manager_hr_job" model="res.groups">
            <field name="name">Hr_Job / Manager</field>
        </record>


<record id="group_only_manager_responsible_can_modify" model="ir.rule">
            <field name="name">Only Manager can publish jobs</field>
            <field name="model_id" ref="model_hr_job"/>
            <field name="groups" eval="[(4, ref('hr_job.group_manager_hr_job'))]"/>
            <field name="perm_read" eval="1"/>
            <field name="perm_write" eval="1"/>
            <field name="perm_create" eval="1"/>
            <field name="perm_unlink" eval="1"/>
            <field name="domain_force">
                ['|','|',('employee_id.user_id','=',manager.user.id),
                ('employee_id.parent_id.user_id','=',manager.user.id),
                ('default_job_id.is_published','=',is_published)]
            </field>
        </record>

CodePudding user response:

You can use python method to change state to "Waiting Approval" then send message to manager.

def button_request_publish(self):
    #method message post here
    partners = []
    user_obj = self.env['res.users'].sudo().search(use domain to find manager related to document)
    for x in user_obj:
        partners.append(x.partner_id.id)

    msg = "Your message to manager"
    self.sudo().message_post(body=msg, message_type="notification", partner_ids=partners)

    self.write({'state': 'waiting_approval'})

def approve_manager_publish(self):
    # write your code to publish here

    self.write({'state': 'approve'})

Button "Send Publish Request" have group user, then Button "Approve Publish" have group Manager.

  • Related