From 006e15569b87fc24b448b7e6a7887aa3b676cebc Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 27 Sep 2019 06:32:00 +0000 Subject: [PATCH] [FIX] account,mail: Fix creation message in chatter for invoices Add a hook inside mail_thread to be able to get a custom message at the record creation. Override this hook in account.move to get a custom creation message dependent of the move's type. closes odoo/odoo#37474 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 22 ++++++++++++++++++++-- addons/mail/models/mail_thread.py | 11 +++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 605cbf6ea76..b8e285c8dbf 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1570,6 +1570,13 @@ class AccountMove(models.Model): result.append((move.id, name)) return result + def _creation_subtype(self): + # OVERRIDE + if self.type in ('out_invoice', 'out_refund', 'out_receipt'): + return self.env.ref('account.mt_invoice_created') + else: + return super(AccountMove, self)._creation_subtype() + def _track_subtype(self, init_values): # OVERRIDE to add custom subtype depending of the state. self.ensure_one() @@ -1581,10 +1588,21 @@ class AccountMove(models.Model): return self.env.ref('account.mt_invoice_paid') elif 'state' in init_values and self.state == 'posted' and self.is_sale_document(include_receipts=True): return self.env.ref('account.mt_invoice_validated') - elif 'state' in init_values and self.state == 'draft' and self.is_sale_document(include_receipts=True): - return self.env.ref('account.mt_invoice_created') return super(AccountMove, self)._track_subtype(init_values) + def _get_creation_message(self): + # OVERRIDE + if not self.is_invoice(include_receipts=True): + return super()._get_creation_message() + return { + 'out_invoice': _('Invoice Created'), + 'out_refund': _('Refund Created'), + 'in_invoice': _('Vendor Bill Created'), + 'in_refund': _('Credit Note Created'), + 'out_receipt': _('Sales Receipt Created'), + 'in_receipt': _('Purchase Receipt Created'), + }[self.type] + # ------------------------------------------------------------------------- # BUSINESS METHODS # ------------------------------------------------------------------------- diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 101766fe9e2..91ebdb094b4 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -280,10 +280,9 @@ class MailThread(models.AbstractModel): # automatic logging unless asked not to (mainly for various testing purpose) if not self._context.get('mail_create_nolog'): - doc_name = self.env['ir.model']._get(self._name).name - body = _('%s created') % doc_name 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) @@ -562,6 +561,14 @@ class MailThread(models.AbstractModel): """ return self.env['mail.message.subtype'] + def _get_creation_message(self): + """ Get the creation message to log into the chatter at the record's creation. + :returns: The message's body to log. + """ + self.ensure_one() + doc_name = self.env['ir.model']._get(self._name).name + return _('%s created') % doc_name + def _track_subtype(self, init_values): """ Give the subtypes triggered by the changes on the record according to values that have been updated.