[MERGE] mail, various: update record when creating a customer from chatter suggestion
Currently using chatter it is possible to create customers directly when posting a message. Unknown email addresses are proposed to the user that can create customers directly in the posting process. However the record is not updated. Several models like lead, issue, ticket or event track have a customer (partner_id) field that is not updated even when a customer is created from the chatter. Users have to update records manually. This merge automates it by updating the record through a post process hook on message_post that is used in main customer-based addons. A small improvement is done in the chatter to reload the record once posting a message to a new customer.
This commit is contained in:
@@ -1113,6 +1113,19 @@ class Lead(models.Model):
|
||||
update_vals[key] = res.group(2).lower()
|
||||
return super(Lead, self).message_update(msg_dict, update_vals=update_vals)
|
||||
|
||||
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(Lead, self)._message_post_after_hook(message)
|
||||
|
||||
@api.multi
|
||||
def message_partner_info_from_emails(self, emails, link_mail=False):
|
||||
result = super(Lead, self).message_partner_info_from_emails(emails, link_mail=link_mail)
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers"/>
|
||||
<field name="message_ids" widget="mail_thread"/>
|
||||
<field name="message_ids" widget="mail_thread" options="{'post_refresh': 'recipients'}"/>
|
||||
</div>
|
||||
</form>
|
||||
</field>
|
||||
@@ -497,7 +497,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>
|
||||
|
||||
@@ -447,6 +447,20 @@ class EventRegistration(models.Model):
|
||||
pass
|
||||
return recipients
|
||||
|
||||
def _message_post_after_hook(self, message):
|
||||
if self.email 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)
|
||||
if new_partner:
|
||||
self.search([
|
||||
('partner_id', '=', False),
|
||||
('email', '=', new_partner.email),
|
||||
('state', 'not in', ['cancel']),
|
||||
]).write({'partner_id': new_partner.id})
|
||||
return super(EventRegistration, self)._message_post_after_hook(message)
|
||||
|
||||
@api.multi
|
||||
def action_send_badge_email(self):
|
||||
""" Open a window to compose an email, with the template - 'event_badge'
|
||||
|
||||
@@ -499,7 +499,7 @@
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers"/>
|
||||
<field name="message_ids" widget="mail_thread"/>
|
||||
<field name="message_ids" widget="mail_thread" options="{'post_refresh': 'recipients'}"/>
|
||||
</div>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1894,8 +1894,14 @@ class MailThread(models.AbstractModel):
|
||||
self.sudo().write({'message_last_post': fields.Datetime.now()})
|
||||
if new_message.author_id and model and self.ids and message_type != 'notification' and not self._context.get('mail_create_nosubscribe'):
|
||||
self.message_subscribe([new_message.author_id.id], force=False)
|
||||
|
||||
self._message_post_after_hook(new_message)
|
||||
|
||||
return new_message
|
||||
|
||||
def _message_post_after_hook(self, message):
|
||||
pass
|
||||
|
||||
@api.multi
|
||||
def message_post_with_view(self, views_or_xmlid, **kwargs):
|
||||
""" Helper method to send a mail / post a message using a view_id to
|
||||
|
||||
@@ -58,6 +58,7 @@ var Chatter = Widget.extend(chat_mixin, {
|
||||
this.fields.thread = new ThreadField(this, mailFields.mail_thread, record, options);
|
||||
var nodeOptions = this.record.fieldsInfo.form[mailFields.mail_thread].options;
|
||||
this.hasLogButton = nodeOptions.display_log_button;
|
||||
this.postRefresh = nodeOptions.post_refresh || 'never';
|
||||
}
|
||||
},
|
||||
start: function () {
|
||||
@@ -158,7 +159,12 @@ var Chatter = Widget.extend(chat_mixin, {
|
||||
self.composer.focus();
|
||||
}
|
||||
self.composer.on('post_message', self, function (message) {
|
||||
self.fields.thread.postMessage(message).then(self._closeComposer.bind(self, true));
|
||||
self.fields.thread.postMessage(message).then(function () {
|
||||
self._closeComposer(true);
|
||||
if (self.postRefresh === 'always' || (self.postRefresh === 'recipients' && message.partner_ids.length)) {
|
||||
self.trigger_up('reload');
|
||||
}
|
||||
});
|
||||
});
|
||||
self.composer.on('need_refresh', self, self.trigger_up.bind(self, 'reload'));
|
||||
self.composer.on('close_composer', null, self._closeComposer.bind(self, true));
|
||||
|
||||
@@ -173,7 +173,7 @@ var ChatterComposer = composer.BasicComposer.extend({
|
||||
var new_names_to_find = _.difference(names_to_find, names_to_remove);
|
||||
var def;
|
||||
if (new_names_to_find.length > 0) {
|
||||
self._rpc({
|
||||
def = self._rpc({
|
||||
model: self.model,
|
||||
method: 'message_partner_info_from_emails',
|
||||
args: [[self.context.default_res_id], new_names_to_find, true],
|
||||
|
||||
@@ -327,6 +327,19 @@ class ProjectIssue(models.Model):
|
||||
self.sudo().write({'date_action_last': fields.Datetime.now()})
|
||||
return mail_message
|
||||
|
||||
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(ProjectIssue, self)._message_post_after_hook(message)
|
||||
|
||||
@api.multi
|
||||
def message_get_email_values(self, notif_mail=None):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
|
||||
<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>
|
||||
|
||||
@@ -160,6 +160,20 @@ class Track(models.Model):
|
||||
track._message_add_suggested_recipient(recipients, email=track.partner_email, reason=_('Speaker Email'))
|
||||
return recipients
|
||||
|
||||
def _message_post_after_hook(self, message):
|
||||
if self.partner_email 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.partner_email)
|
||||
if new_partner:
|
||||
self.search([
|
||||
('partner_id', '=', False),
|
||||
('partner_email', '=', new_partner.email),
|
||||
('stage_id.is_cancel', '=', False),
|
||||
]).write({'partner_id': new_partner.id})
|
||||
return super(Track, self)._message_post_after_hook(message)
|
||||
|
||||
@api.multi
|
||||
def open_track_speakers_list(self):
|
||||
return {
|
||||
|
||||
@@ -154,7 +154,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>
|
||||
|
||||
Reference in New Issue
Block a user