[16.0][MIG] mail_template_substitute: Migration to 16.0

pull/1314/head
Karthik, Sodexis 2023-04-03 13:14:31 +05:30 committed by Sakthivel
parent 48053a686e
commit 72da3e3411
10 changed files with 61 additions and 32 deletions

View File

@ -14,14 +14,14 @@ Mail Template Substitute
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/12.0/mail_template_substitute :target: https://github.com/OCA/social/tree/16.0/mail_template_substitute
:alt: OCA/social :alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_template_substitute :target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_template_substitute
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/12.0 :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&target_branch=16.0
:alt: Try me on Runbot :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -56,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_template_substitute%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_template_substitute%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -72,6 +72,7 @@ Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Bejaoui Souheil <souheil.bejaoui@acsone.eu> * Bejaoui Souheil <souheil.bejaoui@acsone.eu>
* Karthik <karthik@sodexis.com>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -86,6 +87,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/12.0/mail_template_substitute>`_ project on GitHub. This module is part of the `OCA/social <https://github.com/OCA/social/tree/16.0/mail_template_substitute>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,3 +1,2 @@
from . import models from . import models
from . import wizards from . import wizards
from . import tests

View File

@ -6,7 +6,7 @@
"summary": """ "summary": """
This module allows to create substitution rules for mail templates. This module allows to create substitution rules for mail templates.
""", """,
"version": "12.0.1.0.1", "version": "16.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)", "author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",

View File

@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"

View File

@ -1,13 +1,11 @@
# Copyright 2019 ACSONE SA/NV # Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models from odoo import fields, models
from odoo.tools import pycompat
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
class MailTemplate(models.Model): class MailTemplate(models.Model):
_inherit = "mail.template" _inherit = "mail.template"
mail_template_substitution_rule_ids = fields.One2many( mail_template_substitution_rule_ids = fields.One2many(
@ -16,12 +14,11 @@ class MailTemplate(models.Model):
string="Substitution Rules", string="Substitution Rules",
) )
@api.multi
def _get_substitution_template(self, model_id, active_ids): def _get_substitution_template(self, model_id, active_ids):
self.ensure_one() self.ensure_one()
if isinstance(active_ids, pycompat.integer_types): if isinstance(active_ids, int):
active_ids = [active_ids] active_ids = [active_ids]
model = self.env[model_id.model] model = self.env[model_id.sudo().model]
for substitution_template_rule in self.mail_template_substitution_rule_ids: for substitution_template_rule in self.mail_template_substitution_rule_ids:
domain = safe_eval(substitution_template_rule.domain) domain = safe_eval(substitution_template_rule.domain)
domain.append(("id", "in", active_ids)) domain.append(("id", "in", active_ids))
@ -29,9 +26,8 @@ class MailTemplate(models.Model):
return substitution_template_rule.substitution_mail_template_id return substitution_template_rule.substitution_mail_template_id
return False return False
@api.multi def _classify_per_lang(self, res_ids, engine="inline_template"):
def get_email_template(self, res_ids):
substitution_template = self._get_substitution_template(self.model_id, res_ids) substitution_template = self._get_substitution_template(self.model_id, res_ids)
if substitution_template: if substitution_template:
return substitution_template.get_email_template(res_ids) return substitution_template._classify_per_lang(res_ids, engine=engine)
return super().get_email_template(res_ids) return super()._classify_per_lang(res_ids, engine=engine)

View File

@ -15,7 +15,7 @@ class MailTemplateSubstitutionRule(models.Model):
comodel_name="mail.template", required=True, ondelete="cascade" comodel_name="mail.template", required=True, ondelete="cascade"
) )
model = fields.Char(related="mail_template_id.model_id.model", store=True) model = fields.Char(related="mail_template_id.model_id.model", store=True)
domain = fields.Char(string="Domain", required=True, default="[]") domain = fields.Char(required=True, default="[]")
substitution_mail_template_id = fields.Many2one( substitution_mail_template_id = fields.Many2one(
comodel_name="mail.template", comodel_name="mail.template",
required=True, required=True,

View File

@ -1 +1,2 @@
* Bejaoui Souheil <souheil.bejaoui@acsone.eu> * Bejaoui Souheil <souheil.bejaoui@acsone.eu>
* Karthik <karthik@sodexis.com>

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Mail Template Substitute</title> <title>Mail Template Substitute</title>
<style type="text/css"> <style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mail_template_substitute"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_template_substitute"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/16.0/mail_template_substitute"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_template_substitute"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to create substitution rules for mail templates. <p>This module allows you to create substitution rules for mail templates.
A typical use case is to replace a standard template by alternative templates A typical use case is to replace a standard template by alternative templates
when some conditions are met. For instance, it allows to configure alternate when some conditions are met. For instance, it allows to configure alternate
@ -401,7 +401,7 @@ templates for different companies.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_template_substitute%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_template_substitute%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -416,6 +416,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id5">Contributors</a></h2> <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Bejaoui Souheil &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li> <li>Bejaoui Souheil &lt;<a class="reference external" href="mailto:souheil.bejaoui&#64;acsone.eu">souheil.bejaoui&#64;acsone.eu</a>&gt;</li>
<li>Karthik &lt;<a class="reference external" href="mailto:karthik&#64;sodexis.com">karthik&#64;sodexis.com</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -425,7 +426,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mail_template_substitute">OCA/social</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/16.0/mail_template_substitute">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
# Copyright 2019 ACSONE SA/NV # Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase from odoo.tests.common import Form, TransactionCase
class TestMailTemplateSubstitute(TransactionCase): class TestMailTemplateSubstitute(TransactionCase):
@ -42,16 +42,35 @@ class TestMailTemplateSubstitute(TransactionCase):
{"template_id": self.mt.id, "composition_mode": "mass_mail"} {"template_id": self.mt.id, "composition_mode": "mass_mail"}
) )
self.partners = self.env["res.partner"].search([]) self.partners = self.env["res.partner"].search([])
self.partner = self.env["res.partner"].search([], limit=1)
def test_get_email_template(self): def test_get_email_template_partners(self):
self.assertEqual( self.assertEqual(
self.mt._get_substitution_template( self.mt._get_substitution_template(
self.env.ref("base.model_res_partner"), self.partners.ids self.env.ref("base.model_res_partner"), self.partners.ids
), ),
self.smt1, self.smt1,
) )
res_ids_to_templates = self.mt._classify_per_lang(self.partners.ids)
self.assertTrue(len(res_ids_to_templates))
_lang, (template, _res_ids) = list(res_ids_to_templates.items())[0]
self.assertEqual( self.assertEqual(
self.mt.get_email_template(self.partners.ids).get(self.partners.ids[0]), template,
self.smt1,
)
def test_get_email_template_partner(self):
self.assertEqual(
self.mt._get_substitution_template(
self.env.ref("base.model_res_partner"), self.partner.id
),
self.smt1,
)
res_ids_to_templates = self.mt._classify_per_lang(self.partner.ids)
self.assertTrue(len(res_ids_to_templates))
_lang, (template, _res_ids) = list(res_ids_to_templates.items())[0]
self.assertEqual(
template,
self.smt1, self.smt1,
) )
@ -70,3 +89,15 @@ class TestMailTemplateSubstitute(TransactionCase):
active_ids=self.partners.ids active_ids=self.partners.ids
).onchange_template_id_wrapper() ).onchange_template_id_wrapper()
self.assertEqual(self.mail_compose.template_id, self.smt2) self.assertEqual(self.mail_compose.template_id, self.smt2)
def test_default_get(self):
mail_compose_form = Form(
self.env["mail.compose.message"].with_context(
**{
"default_template_id": self.mt.id,
"default_model": self.partner._name,
"default_res_id": self.partner.id,
}
)
)
self.assertEqual(mail_compose_form.template_id, self.smt1)

View File

@ -13,9 +13,10 @@ class MailComposeMessage(models.TransientModel):
if template: if template:
if composition_mode == "mass_mail" and self.env.context.get("active_ids"): if composition_mode == "mass_mail" and self.env.context.get("active_ids"):
res_ids = self.env.context.get("active_ids") res_ids = self.env.context.get("active_ids")
res_ids_to_templates = template.get_email_template(res_ids) res_ids_to_templates = template._classify_per_lang(res_ids)
if res_ids_to_templates: if len(res_ids_to_templates):
return list(res_ids_to_templates.values())[0] _lang, (template, _res_ids) = list(res_ids_to_templates.items())[0]
return template
return False return False
@api.model @api.model
@ -30,7 +31,6 @@ class MailComposeMessage(models.TransientModel):
result["template_id"] = substitution_template.id result["template_id"] = substitution_template.id
return result return result
@api.multi
@api.onchange("template_id") @api.onchange("template_id")
def onchange_template_id_wrapper(self): def onchange_template_id_wrapper(self):
substitution_template = self._get_substitution_template( substitution_template = self._get_substitution_template(