From 7da0ea30fb47ebeea409835d7b2dbfd274531af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 31 Mar 2017 12:07:54 +0200 Subject: [PATCH] [IMP] hr_recruitment: update applicant after creating a partner from chatter suggestion When a message is posted through the chatter and creates a new partner the applicant is now updated so that the partner field is correctly set to the newly-created partner. Chatter on applicant now uses the reload option so that the view is reloaded after posting a message. The user therefore sees that the record has been updated accordingly. --- addons/hr_recruitment/models/hr_recruitment.py | 14 +++++++++++++- .../hr_recruitment/views/hr_recruitment_views.xml | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index f5e164a4aff..9302b9a5ce5 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -305,7 +305,6 @@ class Applicant(models.Model): } return res - @api.multi def action_get_attachment_tree_view(self): attachment_action = self.env.ref('base.action_attachment') @@ -377,6 +376,19 @@ class Applicant(models.Model): defaults.update(custom_values) return super(Applicant, self).message_new(msg, custom_values=defaults) + def _message_post_after_hook(self, message): + if self.email_from and not self.partner_id: + # we consider that posting a message with a specified recipient (not a follower, a specific one) + # on a document without customer means that it was created through the chatter using + # suggested recipients. This heuristic allows to avoid ugly hacks in JS. + new_partner = message.partner_ids.filtered(lambda partner: partner.email == self.email_from) + if new_partner: + self.search([ + ('partner_id', '=', False), + ('email_from', '=', new_partner.email), + ('stage_id.fold', '=', False)]).write({'partner_id': new_partner.id}) + return super(Applicant, self)._message_post_after_hook(message) + @api.multi def create_employee_from_applicant(self): """ Create an hr.employee from the hr.applicants """ diff --git a/addons/hr_recruitment/views/hr_recruitment_views.xml b/addons/hr_recruitment/views/hr_recruitment_views.xml index f2269a9a991..27a3e33aab2 100644 --- a/addons/hr_recruitment/views/hr_recruitment_views.xml +++ b/addons/hr_recruitment/views/hr_recruitment_views.xml @@ -159,7 +159,7 @@
- +