[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 <smetl@users.noreply.github.com>
This commit is contained in:
Laurent Smet
2019-09-27 08:08:04 +00:00
parent 237e0b42dc
commit 006e15569b
2 changed files with 29 additions and 4 deletions
+20 -2
View File
@@ -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
# -------------------------------------------------------------------------
+9 -2
View File
@@ -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.