-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#66887 [16.0][MIG] mail_template_fr_fields (#14)
Co-authored-by: majouda <[email protected]>
- Loading branch information
1 parent
ee4f078
commit d5c1ecb
Showing
11 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
======================= | ||
Mail Template FR Fields | ||
======================= | ||
|
||
.. contents:: Table of Contents | ||
|
||
Context | ||
------- | ||
Without this module, when exporting the values of an email template, | ||
you have to switch language between french and english and | ||
export the data in 2 steps. | ||
|
||
Overview | ||
-------- | ||
This module adds extra fields to email templates. | ||
|
||
* body_html_en | ||
* body_html_fr | ||
* subject_en | ||
* subject_fr | ||
|
||
Those fields allow export (and import) english and french values | ||
for the body and subject of an email template in a single css file. | ||
|
||
.. image:: static/description/email_template_list.png | ||
|
||
Contributors | ||
------------ | ||
* Numigi (tm) and all its contributors (https://bit.ly/numigiens) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Mail Templates FR Fields", | ||
"version": "16.0.1.0.0", | ||
"author": "Numigi", | ||
"maintainer": "Numigi", | ||
"license": "LGPL-3", | ||
"category": "Other", | ||
"summary": "Add FR fields to email templates", | ||
"depends": ["mail", "lang_fr_activated"], | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import mail_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class MailTemplate(models.Model): | ||
|
||
_inherit = "mail.template" | ||
|
||
body_html_fr = fields.Char( | ||
compute="_compute_body_html_fr", | ||
inverse=lambda self: None, | ||
) | ||
body_html_en = fields.Char( | ||
compute="_compute_body_html_en", | ||
inverse=lambda self: None, | ||
) | ||
subject_fr = fields.Char( | ||
compute="_compute_subject_fr", | ||
inverse=lambda self: None, | ||
) | ||
subject_en = fields.Char( | ||
compute="_compute_subject_en", | ||
inverse=lambda self: None, | ||
) | ||
|
||
def _compute_body_html_fr(self): | ||
for record in self: | ||
record.body_html_fr = record.with_fr().body_html | ||
|
||
def _compute_body_html_en(self): | ||
for record in self: | ||
record.body_html_en = record.with_en().body_html | ||
|
||
def _compute_subject_fr(self): | ||
for record in self: | ||
record.subject_fr = record.with_fr().subject | ||
|
||
def _compute_subject_en(self): | ||
for record in self: | ||
record.subject_en = record.with_en().subject | ||
|
||
@api.model | ||
def create(self, vals): | ||
vals_copy = vals.copy() | ||
template = super().create(vals) | ||
template._set_fr_field_values(vals_copy) | ||
template._set_en_field_values(vals_copy) | ||
return template | ||
|
||
def write(self, vals): | ||
vals_copy = vals.copy() | ||
super().write(vals) | ||
self._set_fr_field_values(vals_copy) | ||
self._set_en_field_values(vals_copy) | ||
return True | ||
|
||
def _set_fr_field_values(self, vals): | ||
fields = { | ||
"subject_fr": "subject", | ||
"body_html_fr": "body_html", | ||
} | ||
fr_vals = {fields[k]: v for k, v in vals.items() if k in fields} | ||
if fr_vals: | ||
self.with_fr().write(fr_vals) | ||
|
||
def _set_en_field_values(self, vals): | ||
fields = { | ||
"subject_en": "subject", | ||
"body_html_en": "body_html", | ||
} | ||
en_vals = {fields[k]: v for k, v in vals.items() if k in fields} | ||
if en_vals: | ||
self.with_en().write(en_vals) | ||
|
||
def with_en(self): | ||
return _with_lang(self, "en_US") | ||
|
||
def with_fr(self): | ||
return _with_lang(self, "fr_FR") | ||
|
||
|
||
def _with_lang(record, lang): | ||
return record.with_context(lang=lang) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from . import test_mail_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo.tests import common | ||
|
||
|
||
class TestMailTemplate(common.SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.body_html_fr = "Mon contenu en français" | ||
cls.body_html_en = "My content in english" | ||
cls.subject_fr = "Mon sujet en français" | ||
cls.subject_en = "My subject in english" | ||
cls.template = cls.env["mail.template"].create( | ||
{ | ||
"name": "My Email Template", | ||
"body_html_fr": cls.body_html_fr, | ||
"body_html_en": cls.body_html_en, | ||
"subject_fr": cls.subject_fr, | ||
"subject_en": cls.subject_en, | ||
} | ||
) | ||
|
||
def test_body_html_fr(self): | ||
assert self.template.with_fr().body_html == self.body_html_fr | ||
|
||
def test_body_html_en(self): | ||
assert self.template.with_en().body_html == self.body_html_en | ||
|
||
def test_subject_fr(self): | ||
assert self.template.with_fr().subject == self.subject_fr | ||
|
||
def test_subject_en(self): | ||
assert self.template.with_en().subject == self.subject_en | ||
|
||
def test_write_body_html(self): | ||
new_value_fr = "Nouvelle valeur du contenu" | ||
new_value_en = "New content value" | ||
self.template.write( | ||
{ | ||
"body_html_fr": new_value_fr, | ||
"body_html_en": new_value_en, | ||
} | ||
) | ||
assert self.template.body_html == new_value_en | ||
assert self.template.body_html_fr == new_value_fr | ||
assert self.template.body_html_en == new_value_en |