Skip to content

Commit

Permalink
mail_unique_layout: refactor code so we can use specific layout for s…
Browse files Browse the repository at this point in the history
…ome record
  • Loading branch information
sebastienbeau committed Feb 25, 2024
1 parent 2fb9ea3 commit fb2b064
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions mail_unique_layout/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import mail_thread
from . import mail_template
from . import base
14 changes: 14 additions & 0 deletions mail_unique_layout/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


from odoo import api, models


class Base(models.AbstractModel):
_inherit = "base"

@api.model
def _get_mail_layout(self):
return "mail_unique_layout.general_mail_layout"
Empty file.
3 changes: 2 additions & 1 deletion mail_unique_layout/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ def send_mail(
email_values=None,
notif_layout=False,
):
record = self.env[self.model].browse(res_id)
return super().send_mail(
res_id,
force_send=force_send,
raise_exception=raise_exception,
email_values=email_values,
notif_layout=self.env["mail.thread"]._get_unique_layout_ref(),
notif_layout=record._get_mail_layout(),
)
13 changes: 1 addition & 12 deletions mail_unique_layout/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@
class MailThread(models.AbstractModel):
_inherit = "mail.thread"

@api.model
def _get_default_unique_layout_ref(self):
return "mail_unique_layout.general_mail_layout"

@api.model
def _get_unique_layout_ref(self):
if self._context.get("force_mail_uniq_layout_id"):
return self._context["force_mail_uniq_layout_id"]
else:
return self._get_default_unique_layout_ref()

@api.returns("mail.message", lambda value: value.id)
def message_post(self, *kw, **kwargs):
kwargs["email_layout_xmlid"] = self._get_unique_layout_ref()
kwargs["email_layout_xmlid"] = self._get_mail_layout()
return super().message_post(*kw, **kwargs)

0 comments on commit fb2b064

Please sign in to comment.