Skip to content

Commit

Permalink
TA#66887 [16.0][MIG] mail_template_fr_fields (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: majouda <[email protected]>
  • Loading branch information
lanto-razafindrabe and majouda authored Jul 16, 2024
1 parent ee4f078 commit d5c1ecb
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"konvergo_mail_notification",
"konvergo_web_logo",
"mail_color_konvergo",
"mail_template_fr_fields",
"ui_color_konvergo",
],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ COPY konvergo_login_page /mnt/extra-addons/konvergo_login_page
COPY konvergo_mail_notification /mnt/extra-addons/konvergo_mail_notification
COPY konvergo_web_logo /mnt/extra-addons/konvergo_web_logo
COPY mail_color_konvergo /mnt/extra-addons/mail_color_konvergo
COPY mail_template_fr_fields /mnt/extra-addons/mail_template_fr_fields
COPY ui_color_konvergo /mnt/extra-addons/ui_color_konvergo

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
5 changes: 5 additions & 0 deletions gitoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
branch: "16.0"
includes:
- muk_web_theme

- url: https://github.com/Numigi/odoo-base-addons
branch: "16.0"
includes:
- lang_fr_activated
29 changes: 29 additions & 0 deletions mail_template_fr_fields/README.rst
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)
4 changes: 4 additions & 0 deletions mail_template_fr_fields/__init__.py
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
14 changes: 14 additions & 0 deletions mail_template_fr_fields/__manifest__.py
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,
}
4 changes: 4 additions & 0 deletions mail_template_fr_fields/models/__init__.py
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
85 changes: 85 additions & 0 deletions mail_template_fr_fields/models/mail_template.py
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.
4 changes: 4 additions & 0 deletions mail_template_fr_fields/tests/__init__.py
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
48 changes: 48 additions & 0 deletions mail_template_fr_fields/tests/test_mail_template.py
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

0 comments on commit d5c1ecb

Please sign in to comment.