Skip to content

Commit

Permalink
TA#66807 [16.0][MIG] mail_template_default (#147)
Browse files Browse the repository at this point in the history
* [16.0][MIG] mail_template_default

---------

Co-authored-by: Majda EL MARIOULI <[email protected]>
  • Loading branch information
lanto-razafindrabe and majouda authored Jul 2, 2024
1 parent f83ba43 commit 4bd4e2f
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .docker_files/main/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# © 2024 Numigi
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3 changes: 2 additions & 1 deletion .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2024 Numigi
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
Expand All @@ -15,6 +15,7 @@
"mail",
"mail_bot_no_pong",
"mail_notification_no_action_button",
"mail_template_default",
],
"installable": True,
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ USER odoo

COPY mail_bot_no_pong /mnt/extra-addons/mail_bot_no_pong
COPY mail_notification_no_action_button /mnt/extra-addons/mail_notification_no_action_button
COPY mail_template_default /mnt/extra-addons/mail_template_default

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
22 changes: 22 additions & 0 deletions mail_template_default/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=====================
Mail Template Default
=====================
- This module adds the field Default Template to Mail Template which will add ability to automatically pre-define a template when send mail through mail compose in open chatter
- This field is unique per object

.. image:: static/description/mail_template_default_form_view.png
.. image:: static/description/mail_template_default_tree_view.png
.. image:: static/description/warning_check.png

Configuration
-------------
- Set default template for object in Settings > Technical > Email > Templates > Default Template

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
* Komit (https://komit-consulting.com)

More information
----------------
* Meet us at https://bit.ly/numigi-com
4 changes: 4 additions & 0 deletions mail_template_default/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
14 changes: 14 additions & 0 deletions mail_template_default/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mail Template Default",
"summary": "Add ability to pre-define default mail template by object",
"version": "16.0.1.0.0",
"website": "https://bit.ly/numigi-com",
"author": "Numigi",
"maintainer": "Numigi",
"license": "AGPL-3",
"depends": ["mail"],
"data": ["views/mail_template.xml"],
"installable": True,
}
41 changes: 41 additions & 0 deletions mail_template_default/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_template_default
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-25 10:47+0000\n"
"PO-Revision-Date: 2024-06-25 10:47+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mail_template_default
#: model:ir.model.fields,field_description:mail_template_default.field_email_template_preview__is_default_template
#: model:ir.model.fields,field_description:mail_template_default.field_mail_template__is_default_template
msgid "Default Template"
msgstr "Modèle par défaut"

#. module: mail_template_default
#: model:ir.model,name:mail_template_default.model_mail_template
msgid "Email Templates"
msgstr "Modèle de courriel"

#. module: mail_template_default
#: model:ir.model,name:mail_template_default.model_mail_compose_message
msgid "Email composition wizard"
msgstr "Assistant de composition de courriel"

#. module: mail_template_default
#: code:addons/mail_template_default/models/mail_template.py:16
#, python-format
msgid "This object already has a default template associated. \n"
"You cannot assign more than one default template by object."
msgstr "Un modèle de courriel par défaut est déjà sélectionné pour cet objet.\n"
"Un seul modèle de courriel par défaut peut être défini par objet."

5 changes: 5 additions & 0 deletions mail_template_default/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import mail_compose_message
from . import mail_template
22 changes: 22 additions & 0 deletions mail_template_default/models/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class MailComposeMessage(models.TransientModel):
_inherit = "mail.compose.message"

@api.model
def default_get(self, fields):
res = super().default_get(fields)
default_mail_template = self.env["mail.template"].search(
[
("model_id.model", "=", self._context.get("default_model")),
("is_default_template", "=", True),
],
limit=1,
)
if default_mail_template:
res["template_id"] = default_mail_template.id
return res
30 changes: 30 additions & 0 deletions mail_template_default/models/mail_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class MailTemplate(models.Model):
_inherit = "mail.template"

is_default_template = fields.Boolean("Default Template")

@api.constrains("is_default_template", "model_id")
def _check_unique_default_template(self):
for record in self:
if (
record.search_count(
[
("is_default_template", "=", True),
("model_id", "=", record.model_id.id),
]
)
> 1
):
raise ValidationError(
_(
"This object already has a default template associated. \n"
"You cannot assign more than one default template by object."
)
)
Binary file added mail_template_default/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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_default/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_mail_template_default
47 changes: 47 additions & 0 deletions mail_template_default/tests/test_mail_template_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase


class TestMailTemplateDefault(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.mail_1 = cls.env["mail.template"].create(
{
"name": "Mail to Partner 1",
"model_id": cls.env.ref("base.model_res_partner").id,
}
)
cls.mail_2 = cls.env["mail.template"].create(
{
"name": "Mail to Partner 2",
"model_id": cls.env.ref("base.model_res_partner").id,
}
)

def test_model_can_have_one_template(self):
self.mail_1.is_default_template = True

def test_model_cannot_have_many_template(self):
self.mail_1.is_default_template = True
with self.assertRaises(ValidationError):
self.mail_2.is_default_template = True

def test_get_default_template(self):
self.mail_1.is_default_template = True
self.assertEquals(
self.env["mail.compose.message"]
.with_context(default_model="res.partner")
.default_get(["template_id"])["template_id"],
self.mail_1.id,
)
self.mail_1.is_default_template = False
self.assertEquals(
self.env["mail.compose.message"]
.with_context(default_model="res.partner")
.default_get(["template_id"]),
{},
)
26 changes: 26 additions & 0 deletions mail_template_default/views/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="email_template_tree_with_is_default_template" model="ir.ui.view">
<field name="name">Mail Template Tree: Add field Default Template</field>
<field name="model">mail.template</field>
<field name="inherit_id" ref="mail.email_template_tree" />
<field name="arch" type="xml">
<field name="model_id" position="after">
<field name="is_default_template" />
</field>
</field>
</record>

<record id="email_template_form_with_is_default_template" model="ir.ui.view">
<field name="name">Mail Template Form: Add field Default Template</field>
<field name="model">mail.template</field>
<field name="inherit_id" ref="mail.email_template_form" />
<field name="arch" type="xml">
<field name="model_id" position="after">
<field name="is_default_template" />
</field>
</field>
</record>

</odoo>

0 comments on commit 4bd4e2f

Please sign in to comment.