odoo18/addons_extensions/hr_recruitment_extended/models/recruitment_attachments.py

52 lines
2.5 KiB
Python

from odoo import models, fields, api
class RecruitmentAttachments(models.Model):
_name = 'recruitment.attachments'
_description = 'Recruitment Attachments'
name = fields.Char(string='Name', required=True)
attachment_type = fields.Selection([('personal','Personal Documents'),('education','Education Documents'),('previous_employer','Previous Employer'),('others','Others')],default="others",required=True)
is_default = fields.Boolean(string='Is Default')
employee_recruitment_attachments = fields.One2many('employee.recruitment.attachments','recruitment_attachment_id',string="Documents")
class EmployeeRecruitmentAttachments(models.Model):
_name = "employee.recruitment.attachments"
_rec_name = 'name'
name = fields.Char(string='Attachment Name', required=True)
employee_id = fields.Many2one('hr.employee')
applicant_id = fields.Many2one('hr.applicant')
candidate_id = fields.Many2one('hr.candidate')
recruitment_attachment_id = fields.Many2one('recruitment.attachments')
recruitment_attachment_type = fields.Selection([('personal','Personal Documents'),('education','Education Documents'),('previous_employer','Previous Employer'),('others','Others')],related='recruitment_attachment_id.attachment_type')
file = fields.Binary(string='File', required=True)
review_status = fields.Selection([('draft','Under Review'),('pass','PASS'),('fail','FAIL')], default='draft')
review_comments = fields.Char()
def action_preview_file(self):
""" Returns a URL to preview the attachment in a popup """
for record in self:
if record.file:
attachment = self.env.ref("hr_recruitment_extended.employee_recruitment_attachments_preview")
attachment.sudo().datas = record.file
return {
'name': "File Preview",
'type': 'ir.actions.act_url',
'url': f'/web/content/{attachment.id}?download=false',
'target': 'current', # Opens in a new tab
}
@api.model
def create(self, vals):
# Auto-link applicant_id if context is passed correctly
if self.env.context.get('default_applicant_id'):
vals['applicant_id'] = self.env.context['default_applicant_id']
return super().create(vals)
class Employee(models.Model):
_inherit='hr.employee'
employee_attachment_ids = fields.One2many('employee.recruitment.attachments','employee_id',string="Attachments")