Skip to content

Commit e6e5bf1

Browse files
[4979][IMP] mail_layout_force: reflect oca changes (#14)
* [4979][IMP] mail_layout_force: reflect oca changes
1 parent 835c16c commit e6e5bf1

File tree

14 files changed

+310
-33
lines changed

14 files changed

+310
-33
lines changed

mail_layout_force/README.rst

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Mail Layout Force
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:c0697d9e6eb2247affb97748c2d6c1c811c3749953856ceda5393a0b406e1f6e
10+
!! source digest: sha256:bd6e51284d03e0193675b8c1b52c89371a10d014b6f9ea57a29bfd661ac9be33
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -16,11 +16,17 @@ Mail Layout Force
1616
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
19-
.. |badge3| image:: https://img.shields.io/badge/github-qrtl%2Fstx--oca-lightgray.png?logo=github
20-
:target: https://github.com/qrtl/stx-oca/tree/15.0/mail_layout_force
21-
:alt: qrtl/stx-oca
22-
23-
|badge1| |badge2| |badge3|
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
20+
:target: https://github.com/OCA/social/tree/15.0/mail_layout_force
21+
:alt: OCA/social
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-mail_layout_force
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2430

2531
Odoo will add a default email layout on most commercial communications.
2632

@@ -31,11 +37,14 @@ the company logo, and a small footer saying "Powered by Odoo".
3137
There are notably two main layouts used in Odoo, and the user can't control when
3238
they're used, as it's hardcoded into the different applications.
3339

40+
* ``mail.message_notification_email``
3441
* ``mail.mail_notification_light``
3542
* ``mail.mail_notification_paynow``
3643

3744
This module allows to force a specific layout for a given ``email.template``,
38-
effectively overwritting the one hardcoded by Odoo.
45+
effectively overwritting the one hardcoded by Odoo. Additionally, it enables
46+
forcing a custom layout for emails that do not use an existing ``email.template``
47+
record (e.g., when sending an email from the chatter).
3948

4049
This allows you to fully customize the way Odoo emails are rendered and sent
4150
to your customers.
@@ -48,9 +57,9 @@ to your customers.
4857
Configuration
4958
=============
5059

51-
# Go to Configuration > Technical > Emails > Templates
52-
# Open the desired ``email.template`` record.
53-
# In Advanced Parameters tab, find the Force Layout field.
60+
#. Go to Settings > Technical > Emails > Templates
61+
#. Open the desired ``email.template`` record.
62+
#. In Advanced Parameters tab, find the Force Layout field.
5463

5564
You can leave it empty to use the default email layout (chosen by Odoo).
5665
You can force a custom email layout of your own.
@@ -64,13 +73,23 @@ You can see how the existing layouts are defined for details or inspiration:
6473
* ``mail.mail_notification_paynow``
6574
* ``mail.mail_notification_borders``
6675

76+
To force a new custom layout for emails that do not use an existing ``email.template``
77+
record (e.g., emails sent from the chatter):
78+
79+
#. Go to Settings > Technical > User Interface > Views.
80+
#. Copy the current layout (e.g., mail.message_notification_email) to create a new one, and remove any parts you don’t need.
81+
#. Open the layout that you want to swap with a substitute. Then, under the Layout Mapping tab:
82+
* Set ``Substitute Layout`` to the new custom layout you created.
83+
* Set ``Models`` if you want to apply the replacement only to specific models. If left empty,
84+
the email layout will be replaced for all models.
85+
6786
Bug Tracker
6887
===========
6988

70-
Bugs are tracked on `GitHub Issues <https://github.com/qrtl/stx-oca/issues>`_.
89+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
7190
In case of trouble, please check there if your issue has already been reported.
7291
If you spotted it first, help us to smash it by providing a detailed and welcomed
73-
`feedback <https://github.com/qrtl/stx-oca/issues/new?body=module:%20mail_layout_force%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
92+
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_layout_force%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7493

7594
Do not contact contributors directly about support or help with technical issues.
7695

@@ -88,18 +107,32 @@ Contributors
88107
* `Camptocamp <https://www.camptocamp.com>`_
89108

90109
* Iván Todorovich <[email protected]>
110+
* `Quartile <https://www.quartile.co>`_
111+
112+
* Aung Ko Ko Lin
113+
* Yoshi Tashiro
91114

92115
Maintainers
93116
~~~~~~~~~~~
94117

118+
This module is maintained by the OCA.
119+
120+
.. image:: https://odoo-community.org/logo.png
121+
:alt: Odoo Community Association
122+
:target: https://odoo-community.org
123+
124+
OCA, or the Odoo Community Association, is a nonprofit organization whose
125+
mission is to support the collaborative development of Odoo features and
126+
promote its widespread use.
127+
95128
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
96129
:target: https://github.com/ivantodorovich
97130
:alt: ivantodorovich
98131

99-
Current maintainer:
132+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
100133

101134
|maintainer-ivantodorovich|
102135

103-
This module is part of the `qrtl/stx-oca <https://github.com/qrtl/stx-oca/tree/15.0/mail_layout_force>`_ project on GitHub.
136+
This module is part of the `OCA/social <https://github.com/OCA/social/tree/15.0/mail_layout_force>`_ project on GitHub.
104137

105-
You are welcome to contribute.
138+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

mail_layout_force/__manifest__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
{
66
"name": "Mail Layout Force",
77
"summary": "Force a mail layout on selected email templates",
8-
"version": "15.0.1.0.0",
8+
"version": "15.0.1.0.1",
99
"author": "Camptocamp, Odoo Community Association (OCA)",
1010
"maintainers": ["ivantodorovich"],
1111
"website": "https://github.com/OCA/social",
1212
"license": "AGPL-3",
1313
"category": "Marketing",
1414
"depends": ["mail"],
1515
"demo": ["demo/mail_layout.xml"],
16-
"data": ["data/mail_layout.xml", "views/mail_template.xml"],
16+
"data": [
17+
"security/ir.model.access.csv",
18+
"data/mail_layout.xml",
19+
"views/ir_ui_views.xml",
20+
"views/mail_template.xml",
21+
],
1722
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * mail_layout_force
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 15.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: mail_layout_force
17+
#: model:ir.model,name:mail_layout_force.model_mail_template
18+
msgid "Email Templates"
19+
msgstr ""
20+
21+
#. module: mail_layout_force
22+
#: model:ir.model,name:mail_layout_force.model_mail_thread
23+
msgid "Email Thread"
24+
msgstr ""
25+
26+
#. module: mail_layout_force
27+
#: model:ir.model,name:mail_layout_force.model_mail_compose_message
28+
msgid "Email composition wizard"
29+
msgstr ""
30+
31+
#. module: mail_layout_force
32+
#: model:ir.model.fields,field_description:mail_layout_force.field_mail_template__force_email_layout_id
33+
msgid "Force Layout"
34+
msgstr ""
35+
36+
#. module: mail_layout_force
37+
#: model:ir.model.fields,help:mail_layout_force.field_mail_template__force_email_layout_id
38+
msgid "Force a mail layout for this template."
39+
msgstr ""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
from . import email_layout_mapping
2+
from . import ir_ui_view
13
from . import mail_template
24
from . import mail_thread
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class EmailLayoutMapping(models.Model):
8+
_name = "email.layout.mapping"
9+
_description = "Email Layout Mapping"
10+
11+
layout_id = fields.Many2one("ir.ui.view", ondelete="cascade")
12+
substitute_layout_id = fields.Many2one(
13+
"ir.ui.view",
14+
domain=[("type", "=", "qweb")],
15+
required=True,
16+
help="Select a target layout.",
17+
)
18+
model_ids = fields.Many2many(
19+
"ir.model", string="Models", help="Select models that the swapping applies to."
20+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 Quartile (https://www.quartile.co)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class IrUiView(models.Model):
8+
_inherit = "ir.ui.view"
9+
10+
layout_mapping_line_ids = fields.One2many("email.layout.mapping", "layout_id")

mail_layout_force/models/mail_thread.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,50 @@ def message_post_with_template(
1818
return super().message_post_with_template(
1919
template_id, email_layout_xmlid=email_layout_xmlid, **kwargs
2020
)
21+
22+
def _notify_record_by_email(
23+
self,
24+
message,
25+
recipients_data,
26+
msg_vals=False,
27+
model_description=False,
28+
mail_auto_delete=True,
29+
check_existing=False,
30+
force_send=True,
31+
send_after_commit=True,
32+
**kwargs
33+
):
34+
msg_vals = msg_vals or {}
35+
layout_xmlid = (
36+
msg_vals.get("email_layout_xmlid")
37+
or message.email_layout_xmlid
38+
or "mail.message_notification_email"
39+
)
40+
layout = self.env.ref(layout_xmlid, raise_if_not_found=True)
41+
res_model = (
42+
self.env["ir.model"].sudo().search([("model", "=", self._name)], limit=1)
43+
)
44+
mapping = self.env["email.layout.mapping"].search(
45+
[("layout_id", "=", layout.id), ("model_ids", "in", res_model.ids)],
46+
limit=1,
47+
)
48+
if not mapping:
49+
mapping = self.env["email.layout.mapping"].search(
50+
[("layout_id", "=", layout.id), ("model_ids", "=", False)], limit=1
51+
)
52+
if mapping:
53+
substitute_layout = mapping.substitute_layout_id
54+
if not substitute_layout.xml_id:
55+
substitute_layout._export_rows([["id"]])
56+
msg_vals["email_layout_xmlid"] = mapping.substitute_layout_id.xml_id
57+
return super()._notify_record_by_email(
58+
message,
59+
recipients_data,
60+
msg_vals=msg_vals,
61+
model_description=model_description,
62+
mail_auto_delete=mail_auto_delete,
63+
check_existing=check_existing,
64+
force_send=force_send,
65+
send_after_commit=send_after_commit,
66+
**kwargs
67+
)

mail_layout_force/readme/CONFIGURE.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Go to Configuration > Technical > Emails > Templates
2-
# Open the desired ``email.template`` record.
3-
# In Advanced Parameters tab, find the Force Layout field.
1+
#. Go to Settings > Technical > Emails > Templates
2+
#. Open the desired ``email.template`` record.
3+
#. In Advanced Parameters tab, find the Force Layout field.
44

55
You can leave it empty to use the default email layout (chosen by Odoo).
66
You can force a custom email layout of your own.
@@ -13,3 +13,13 @@ You can see how the existing layouts are defined for details or inspiration:
1313
* ``mail.mail_notification_light``
1414
* ``mail.mail_notification_paynow``
1515
* ``mail.mail_notification_borders``
16+
17+
To force a new custom layout for emails that do not use an existing ``email.template``
18+
record (e.g., emails sent from the chatter):
19+
20+
#. Go to Settings > Technical > User Interface > Views.
21+
#. Copy the current layout (e.g., mail.message_notification_email) to create a new one, and remove any parts you don’t need.
22+
#. Open the layout that you want to swap with a substitute. Then, under the Layout Mapping tab:
23+
* Set ``Substitute Layout`` to the new custom layout you created.
24+
* Set ``Models`` if you want to apply the replacement only to specific models. If left empty,
25+
the email layout will be replaced for all models.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
* `Camptocamp <https://www.camptocamp.com>`_
22

33
* Iván Todorovich <[email protected]>
4+
* `Quartile <https://www.quartile.co>`_
5+
6+
* Aung Ko Ko Lin
7+
* Yoshi Tashiro

mail_layout_force/readme/DESCRIPTION.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ the company logo, and a small footer saying "Powered by Odoo".
77
There are notably two main layouts used in Odoo, and the user can't control when
88
they're used, as it's hardcoded into the different applications.
99

10+
* ``mail.message_notification_email``
1011
* ``mail.mail_notification_light``
1112
* ``mail.mail_notification_paynow``
1213

1314
This module allows to force a specific layout for a given ``email.template``,
14-
effectively overwritting the one hardcoded by Odoo.
15+
effectively overwritting the one hardcoded by Odoo. Additionally, it enables
16+
forcing a custom layout for emails that do not use an existing ``email.template``
17+
record (e.g., when sending an email from the chatter).
1518

1619
This allows you to fully customize the way Odoo emails are rendered and sent
1720
to your customers.

0 commit comments

Comments
 (0)