Skip to content

Commit

Permalink
[IMP] mail: allow overriding invite message values
Browse files Browse the repository at this point in the history
Before this commit the creation of the message(s) was done within a for loop in a big function.
Due to this there is no easy nor clean way to override and modify values on the mail.message record(s).

By placing the preparation of message data in a subfunction it can be overwritten and modified as wanted.

closes odoo#102825

X-original-commit: 6d6d7c1
Signed-off-by: Thibault Delavallee (tde) <[email protected]>
  • Loading branch information
Yenthe666 committed Oct 10, 2022
1 parent 0053a9e commit 34b790f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions addons/mail/wizard/mail_wizard_invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,9 @@ def add_followers(self):
model_name = self.env['ir.model']._get(wizard.res_model).display_name
# send an email if option checked and if a message exists (do not send void emails)
if wizard.send_mail and wizard.message and not wizard.message == '<br>': # when deleting the message, cleditor keeps a <br>
message = self.env['mail.message'].create({
'subject': _('Invitation to follow %(document_model)s: %(document_name)s', document_model=model_name, document_name=document.display_name),
'body': wizard.message,
'record_name': document.display_name,
'email_from': email_from,
'reply_to': email_from,
'model': wizard.res_model,
'res_id': wizard.res_id,
'reply_to_force_new': True,
'email_add_signature': True,
})
message = self.env['mail.message'].create(
self._prepare_message_values(document, model_name, email_from)
)
email_partners_data = []
recipients_data = self.env['mail.followers']._get_recipient_data(document, 'comment', False, pids=new_partners.ids)[document.id]
for _pid, pdata in recipients_data.items():
Expand All @@ -85,3 +77,17 @@ def add_followers(self):
self.env['bus.bus']._sendone(self.env.user.partner_id, 'mail.message/delete', {'message_ids': message.ids})
message.unlink()
return {'type': 'ir.actions.act_window_close'}

def _prepare_message_values(self, document, model_name, email_from):
return {
'subject': _('Invitation to follow %(document_model)s: %(document_name)s', document_model=model_name,
document_name=document.display_name),
'body': self.message,
'record_name': document.display_name,
'email_from': email_from,
'reply_to': email_from,
'model': self.res_model,
'res_id': self.res_id,
'reply_to_force_new': True,
'email_add_signature': True,
}

0 comments on commit 34b790f

Please sign in to comment.