[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.
This commit is contained in:
Thibault Delavallée
2017-05-04 14:15:34 +02:00
parent 4207b33b88
commit 7da0ea30fb
2 changed files with 14 additions and 2 deletions
+13 -1
View File
@@ -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 """
@@ -159,7 +159,7 @@
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
<field name="message_ids" widget="mail_thread" options="{'post_refresh': 'recipients'}"/>
</div>
</form>
</field>