-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#66807 [16.0][MIG] mail_template_default (#147)
* [16.0][MIG] mail_template_default --------- Co-authored-by: Majda EL MARIOULI <[email protected]>
- Loading branch information
1 parent
f83ba43
commit 4bd4e2f
Showing
17 changed files
with
219 additions
and
2 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
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). |
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,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 |
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-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 |
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-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, | ||
} |
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,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." | ||
|
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,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 |
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,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 |
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,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." | ||
) | ||
) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+98.1 KB
mail_template_default/static/description/mail_template_default_form_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+79 KB
mail_template_default/static/description/mail_template_default_tree_view.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.
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-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 |
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,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"]), | ||
{}, | ||
) |
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,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> |