mirror of https://github.com/OCA/social.git
[16.0][MIG] mail_template_substitute: Migration to 16.0
parent
10b60f22f8
commit
527be5113a
|
@ -14,14 +14,14 @@ Mail Template Substitute
|
|||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |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
|
||||
.. |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
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/205/12.0
|
||||
:alt: Try me on Runbot
|
||||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
|
||||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/social&target_branch=16.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
|
@ -56,7 +56,7 @@ Bug Tracker
|
|||
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.
|
||||
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.
|
||||
|
||||
|
@ -72,6 +72,7 @@ Contributors
|
|||
~~~~~~~~~~~~
|
||||
|
||||
* Bejaoui Souheil <souheil.bejaoui@acsone.eu>
|
||||
* Karthik <karthik@sodexis.com>
|
||||
|
||||
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
|
||||
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.
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
from . import models
|
||||
from . import wizards
|
||||
from . import tests
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"summary": """
|
||||
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",
|
||||
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/social",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 12.0\n"
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools import pycompat
|
||||
from odoo import fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class MailTemplate(models.Model):
|
||||
|
||||
_inherit = "mail.template"
|
||||
|
||||
mail_template_substitution_rule_ids = fields.One2many(
|
||||
|
@ -16,12 +14,11 @@ class MailTemplate(models.Model):
|
|||
string="Substitution Rules",
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _get_substitution_template(self, model_id, active_ids):
|
||||
self.ensure_one()
|
||||
if isinstance(active_ids, pycompat.integer_types):
|
||||
if isinstance(active_ids, int):
|
||||
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:
|
||||
domain = safe_eval(substitution_template_rule.domain)
|
||||
domain.append(("id", "in", active_ids))
|
||||
|
@ -29,9 +26,8 @@ class MailTemplate(models.Model):
|
|||
return substitution_template_rule.substitution_mail_template_id
|
||||
return False
|
||||
|
||||
@api.multi
|
||||
def get_email_template(self, res_ids):
|
||||
def _classify_per_lang(self, res_ids, engine="inline_template"):
|
||||
substitution_template = self._get_substitution_template(self.model_id, res_ids)
|
||||
if substitution_template:
|
||||
return substitution_template.get_email_template(res_ids)
|
||||
return super().get_email_template(res_ids)
|
||||
return substitution_template._classify_per_lang(res_ids, engine=engine)
|
||||
return super()._classify_per_lang(res_ids, engine=engine)
|
||||
|
|
|
@ -15,7 +15,7 @@ class MailTemplateSubstitutionRule(models.Model):
|
|||
comodel_name="mail.template", required=True, ondelete="cascade"
|
||||
)
|
||||
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(
|
||||
comodel_name="mail.template",
|
||||
required=True,
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
* Bejaoui Souheil <souheil.bejaoui@acsone.eu>
|
||||
* Karthik <karthik@sodexis.com>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<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>
|
||||
<style type="text/css">
|
||||
|
||||
|
@ -367,7 +367,7 @@ ul.auto-toc {
|
|||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! 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&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.
|
||||
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
|
||||
|
@ -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>.
|
||||
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
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
<ul class="simple">
|
||||
<li>Bejaoui Souheil <<a class="reference external" href="mailto:souheil.bejaoui@acsone.eu">souheil.bejaoui@acsone.eu</a>></li>
|
||||
<li>Karthik <<a class="reference external" href="mailto:karthik@sodexis.com">karthik@sodexis.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<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
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2019 ACSONE SA/NV
|
||||
# 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):
|
||||
|
@ -42,16 +42,35 @@ class TestMailTemplateSubstitute(TransactionCase):
|
|||
{"template_id": self.mt.id, "composition_mode": "mass_mail"}
|
||||
)
|
||||
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.mt._get_substitution_template(
|
||||
self.env.ref("base.model_res_partner"), self.partners.ids
|
||||
),
|
||||
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.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,
|
||||
)
|
||||
|
||||
|
@ -70,3 +89,15 @@ class TestMailTemplateSubstitute(TransactionCase):
|
|||
active_ids=self.partners.ids
|
||||
).onchange_template_id_wrapper()
|
||||
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)
|
||||
|
|
|
@ -13,9 +13,10 @@ class MailComposeMessage(models.TransientModel):
|
|||
if template:
|
||||
if composition_mode == "mass_mail" and self.env.context.get("active_ids"):
|
||||
res_ids = self.env.context.get("active_ids")
|
||||
res_ids_to_templates = template.get_email_template(res_ids)
|
||||
if res_ids_to_templates:
|
||||
return list(res_ids_to_templates.values())[0]
|
||||
res_ids_to_templates = template._classify_per_lang(res_ids)
|
||||
if len(res_ids_to_templates):
|
||||
_lang, (template, _res_ids) = list(res_ids_to_templates.items())[0]
|
||||
return template
|
||||
return False
|
||||
|
||||
@api.model
|
||||
|
@ -30,7 +31,6 @@ class MailComposeMessage(models.TransientModel):
|
|||
result["template_id"] = substitution_template.id
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
@api.onchange("template_id")
|
||||
def onchange_template_id_wrapper(self):
|
||||
substitution_template = self._get_substitution_template(
|
||||
|
|
Loading…
Reference in New Issue