[FIX] hr_recruitment: fix calendar_events
When using the Add button on the calendar view introduced with odoo/odoo#64948 the event would not be linked with the applicant. After further investigation the method used to get the applicant id in default_get was not flexible enough, the one from crm calendar has been 'copied' Task ID: 2578165 closes odoo/odoo#73635 X-original-commit: f23e07dcb0606dbc4bf835b8266323d5a515662d Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com> Signed-off-by: William Braeckman (wbr) <Williambraecky@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ class CalendarEvent(models.Model):
|
||||
def default_get(self, fields):
|
||||
if self.env.context.get('default_applicant_id'):
|
||||
self = self.with_context(
|
||||
default_res_model='hr.applicant', #res_model seems to be lost without this
|
||||
default_res_model_id=self.env.ref('hr_recruitment.model_hr_applicant').id,
|
||||
default_res_id=self.env.context['default_applicant_id']
|
||||
)
|
||||
@@ -19,9 +20,11 @@ class CalendarEvent(models.Model):
|
||||
defaults = super(CalendarEvent, self).default_get(fields)
|
||||
|
||||
# sync res_model / res_id to opportunity id (aka creating meeting from lead chatter)
|
||||
if 'applicant_id' not in defaults and defaults.get('res_id') and (defaults.get('res_model') or defaults.get('res_model_id')):
|
||||
if (defaults.get('res_model') and defaults['res_model'] == 'hr.applicant') or (defaults.get('res_model_id') and self.env['ir.model'].sudo().browse(defaults['res_model_id']).model == 'hr.applicant'):
|
||||
defaults['applicant_id'] = defaults['res_id']
|
||||
if 'applicant_id' not in defaults:
|
||||
res_model = defaults.get('res_model', False) or self.env.context.get('default_res_model')
|
||||
res_model_id = defaults.get('res_model_id', False) or self.env.context.get('default_res_model_id')
|
||||
if (res_model and res_model == 'hr.applicant') or (res_model_id and self.env['ir.model'].sudo().browse(res_model_id).model == 'hr.applicant'):
|
||||
defaults['applicant_id'] = defaults.get('res_id', False) or self.env.context.get('default_res_id', False)
|
||||
|
||||
return defaults
|
||||
|
||||
|
||||
@@ -354,6 +354,7 @@ class Applicant(models.Model):
|
||||
category = self.env.ref('hr_recruitment.categ_meet_interview')
|
||||
res = self.env['ir.actions.act_window']._for_xml_id('calendar.action_calendar_event')
|
||||
res['context'] = {
|
||||
'default_applicant_id': self.id,
|
||||
'default_partner_ids': partners.ids,
|
||||
'default_user_id': self.env.uid,
|
||||
'default_name': self.name,
|
||||
|
||||
Reference in New Issue
Block a user