From 610ba9853976f81d3ffe04c141f63ab61bb467ab Mon Sep 17 00:00:00 2001 From: Dharmraj Jhala Date: Thu, 6 Aug 2020 09:47:56 +0000 Subject: [PATCH] [FIX] mail, crm: do not display body in creation message when having a subtype Right now on few business objects (like leads, invoices, tasks, helpdesk tickets etc) creation message contains * subtype description; * generic creation message; This looks like multiple creation message on chatter after creation of the record as you generally have "Task Created - Task created" (subtype description then generic message). This happens when we provide custom subtype on creation by by overriding `_creation_subtype` method. This commit fixes the issue by only using provided creation subtype and removing default body. If creation subtype is not provided default creation message is posted as before. In this commit we also fix subtype for Lead/Opportunity creation and make it generic ('Lead/Opportunity created') to avoid inconsistent behavior. Finally some cleaning is made in method naming. Semi followup of 92e9e84b63a266b39d556c1db1d336373dc8b303 LINKS Task ID-2288458 PR odoo/odoo#56631 PR odoo/enterprise#12707 closes odoo/odoo#56688 X-original-commit: 2ebbeb4b5443c6405dd9a3b202a1eee9c5c67ebb Related: odoo/enterprise#12728 Signed-off-by: Thibault Delavallee (tde) --- addons/account/models/account_move.py | 4 ++-- addons/crm/data/mail_data.xml | 2 +- addons/hr/models/models.py | 2 +- addons/mail/models/mail_channel.py | 2 +- addons/mail/models/mail_thread.py | 10 ++++++---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 7bfff747fdd..13ca6ebd4b5 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1795,10 +1795,10 @@ class AccountMove(models.Model): return self.env.ref('account.mt_invoice_validated') return super(AccountMove, self)._track_subtype(init_values) - def _get_creation_message(self): + def _creation_message(self): # OVERRIDE if not self.is_invoice(include_receipts=True): - return super()._get_creation_message() + return super()._creation_message() return { 'out_invoice': _('Invoice Created'), 'out_refund': _('Credit Note Created'), diff --git a/addons/crm/data/mail_data.xml b/addons/crm/data/mail_data.xml index 28253e529b5..d6e6015e2a5 100644 --- a/addons/crm/data/mail_data.xml +++ b/addons/crm/data/mail_data.xml @@ -15,7 +15,7 @@ crm.lead - Opportunity created + Lead/Opportunity created Stage Changed diff --git a/addons/hr/models/models.py b/addons/hr/models/models.py index dd615798364..fcad66113ba 100644 --- a/addons/hr/models/models.py +++ b/addons/hr/models/models.py @@ -16,5 +16,5 @@ class BaseModel(models.AbstractModel): employee = self.env['hr.employee'].search([('user_id.email', 'ilike', email_address)], limit=1) if not employee: return _('restricted to employees') - return True + return False return super(BaseModel, self)._alias_get_error_message(message, message_dict, alias) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 70f0d9eb78c..c4c8b7fbb58 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -391,7 +391,7 @@ class Channel(models.Model): author = self.env['res.partner'].browse(message_dict.get('author_id', False)) if not author or author not in self.channel_partner_ids: return _('restricted to channel members') - return True + return False return super(Channel, self)._alias_get_error_message(message, message_dict, alias) def init(self): diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 9899c2a0692..24d85f79f70 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -284,14 +284,16 @@ class MailThread(models.AbstractModel): if not self._context.get('mail_create_nolog'): threads_no_subtype = self.env[self._name] for thread in threads: - body = thread._get_creation_message() subtype = thread._creation_subtype() if subtype: # if we have a subtype, post message to notify users from _message_auto_subscribe - thread.sudo().message_post(body=body, subtype_id=subtype.id, author_id=self.env.user.partner_id.id) + thread.sudo().message_post(subtype_id=subtype.id, author_id=self.env.user.partner_id.id) else: threads_no_subtype += thread if threads_no_subtype: - threads_no_subtype._message_log_batch(bodies={t.id: body for t in threads_no_subtype}) + bodies = dict( + (thread.id, thread._creation_message()) + for thread in threads_no_subtype) + threads_no_subtype._message_log_batch(bodies=bodies) # post track template if a tracked field changed threads._discard_tracking() @@ -414,7 +416,7 @@ class MailThread(models.AbstractModel): """ return self.env['mail.message.subtype'] - def _get_creation_message(self): + def _creation_message(self): """ Get the creation message to log into the chatter at the record's creation. :returns: The message's body to log. """