Skip to content

Commit

Permalink
[FIX] hr_recruitment: fix calendar_events
Browse files Browse the repository at this point in the history
When using the Add button on the calendar view introduced with
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#73621

X-original-commit: f23e07d
Signed-off-by: Yannick Tivisse (yti) <[email protected]>
Signed-off-by: William Braeckman (wbr) <[email protected]>
  • Loading branch information
Williambraecky committed Jul 13, 2021
1 parent eb5c4e9 commit 831fb8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions addons/hr_recruitment/models/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ 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']
)

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

Expand Down
1 change: 1 addition & 0 deletions addons/hr_recruitment/models/hr_recruitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def action_makeMeeting(self):
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,
Expand Down

0 comments on commit 831fb8f

Please sign in to comment.