Skip to content

Commit

Permalink
[REF] mail: improve propagation and setup of render context when post…
Browse files Browse the repository at this point in the history
…ing messages

PURPOSE

Purpose of this commit is to cleanup flow of values going through message_post
and its sub methods until email generation for notifications.

SPECIFICATIONS

Ensure some values are given directly when creating message linked to post
methods to avoid browsing message when value is not known. Notably make
signature propagation (add_sign) more explicit in message_post and its sub
methods (notify, log, ...).

Prepare future language related improvements by allowing to force company and
lang values for rendering context. Also add ``is_html_empty`` tool method to
use it in notification templates. It will be used notably to check for empty
html blocks, e.g. user signature.

Rename some internal variables to better understand their purpose.

Finally update some outdated and/or badly indented docstrings.

Task-2726501 (Mail: Propagate message values in post methods)

Part-of: #82167
  • Loading branch information
tde-banana-odoo committed Jan 31, 2022
1 parent 517df26 commit 3eb9680
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 91 deletions.
13 changes: 12 additions & 1 deletion addons/mail/models/mail_template.py
Expand Up @@ -7,6 +7,7 @@

from odoo import _, api, fields, models, tools, Command
from odoo.exceptions import UserError
from odoo.tools import is_html_empty

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -301,10 +302,20 @@ def send_mail(self, res_id, force_send=False, raise_exception=False, email_value
model = model.with_context(lang=lang)

template_ctx = {
# message
'message': self.env['mail.message'].sudo().new(dict(body=values['body_html'], record_name=record.display_name)),
'subtype': self.env['mail.message.subtype'].sudo(),
# record
'model_description': model.display_name,
'company': 'company_id' in record and record['company_id'] or self.env.company,
'record': record,
'record_name': False,
# user / environment
'company': 'company_id' in record and record['company_id'] or self.env.company,
'email_add_signature': False,
'signature': '',
'website_url': '',
# tools
'is_html_empty': is_html_empty,
}
body = template._render(template_ctx, engine='ir.qweb', minimal_qcontext=True)
values['body_html'] = self.env['mail.render.mixin']._replace_local_links(body)
Expand Down

0 comments on commit 3eb9680

Please sign in to comment.