Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Agu 24
1333
0
Okt 21
1783
0
Mar 25
1236
1
Mei 22
2921
1
Nov 21
3756