This question has been flagged

Hallo All.

I have an issue about How to send all attachment file from Module Recruitment to Module Employee.

When i press button (create employee) from module Recruitment, the attachment files that i added in the bottom of Recruitment form(hr.applicant) didn't show up in the bottom of Employee form(hr.employee).

I try this code as another one2many field used to be:

'message_ids': [(6,0,[message.id for message in applicant.message_ids])]

I don't know if fields message_ids are the correct fields that save the attachment files.

Any advice how to send the attachment file?

Avatar
Discard
Best Answer

Hi,

Override the 'Create Employee' Button: Modify the function that is triggered when the "Create Employee" button is pressed. This function should create the new employee record and copy the attachment files from the applicant to the employee.

from odoo import models, fields, api


class HrApplicant(models.Model):
_inherit = 'hr.applicant'

attachment_ids = fields.Many2many('ir.attachment', string='Attachments')


class HrEmployee(models.Model):
_inherit = 'hr.employee'

attachment_ids = fields.Many2many('ir.attachment', string='Attachments')


@api.model
def create_employee_from_applicant(self, applicant_id):
# Create a new employee record based on the applicant data
applicant = self.env['hr.applicant'].browse(applicant_id)
employee_data = {
'name': applicant.name,
# Add other relevant fields from applicant to employee
# ...
# Copy the attachments from applicant to employee
'attachment_ids': [(6, 0, applicant.attachment_ids.ids)],
}
new_employee = self.create(employee_data)
return new_employee.id

once you can use this override method, otherwise you can super the create_employee_from_applicant function, and update the employee_data dictionary

i.e. 

employee_data.update({" 'default_attachment_ids': [(6, 0, applicant.attachment_ids.ids)]})

Regards

Avatar
Discard