Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.0 refactor mail layout #293

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
5 changes: 2 additions & 3 deletions mail_unique_layout/wizards/mail_compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class MailComposeMessage(models.TransientModel):
_inherit = "mail.compose.message"

def send_mail(self, auto_commit=False):
self = self.with_context(
custom_layout=self.env["mail.thread"]._get_unique_layout_ref()
)
record = self.env[self.model].browse(self.res_id)
self = self.with_context(custom_layout=record._get_mail_layout())
return super().send_mail(auto_commit=auto_commit)
Loading