[MIG] mail_layout_preview: Migration to 14.0

pull/1144/head
Tran Thanh Phuc 2021-05-26 14:19:09 +07:00 committed by sonhd91
parent 5fe9c02807
commit 073393c686
10 changed files with 66 additions and 28 deletions

View File

@ -14,13 +14,13 @@ Mail Preview
: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/13.0/mail_layout_preview :target: https://github.com/OCA/social/tree/14.0/mail_layout_preview
: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-13-0/social-13-0-mail_layout_preview :target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_layout_preview
: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/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/13.0 :target: https://runbot.odoo-community.org/runbot/205/14.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -57,7 +57,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_layout_preview%0Aversion:%2013.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_layout_preview%0Aversion:%2014.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.
@ -73,6 +73,14 @@ Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Simone Orsi <simahawk@gmail.com> * Simone Orsi <simahawk@gmail.com>
* Phuc Tran Thanh <phuc@trobz.com>
Other credits
~~~~~~~~~~~~~
The development of this module has been financially supported by:
* Camptocamp
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -87,6 +95,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/13.0/mail_layout_preview>`_ project on GitHub. This module is part of the `OCA/social <https://github.com/OCA/social/tree/14.0/mail_layout_preview>`_ 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

@ -5,7 +5,7 @@
"name": "Mail Preview", "name": "Mail Preview",
"summary": """ "summary": """
Preview email templates in the browser""", Preview email templates in the browser""",
"version": "13.0.1.0.0", "version": "14.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "Camptocamp SA,Odoo Community Association (OCA)", "author": "Camptocamp SA,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",

View File

@ -43,5 +43,5 @@ class Preview(http.Controller):
else: else:
# got a XID # got a XID
template = env.ref(templ_id.strip()) template = env.ref(templ_id.strip())
result = template.generate_email(record.id) result = template.generate_email(record.id, ["body_html"])
return request.make_response(result["body_html"]) return request.make_response(result["body_html"])

View File

@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 13.0\n" "Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -34,7 +34,12 @@ msgid "Copy the link"
msgstr "" msgstr ""
#. module: mail_layout_preview #. module: mail_layout_preview
#: model:ir.model,name:mail_layout_preview.model_email_template_preview #: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__display_name
msgid "Display Name"
msgstr ""
#. module: mail_layout_preview
#: model:ir.model,name:mail_layout_preview.model_mail_template_preview
msgid "Email Template Preview" msgid "Email Template Preview"
msgstr "" msgstr ""
@ -49,7 +54,7 @@ msgid "Find your template"
msgstr "" msgstr ""
#. module: mail_layout_preview #. module: mail_layout_preview
#: model:ir.model.fields,field_description:mail_layout_preview.field_email_template_preview__layout_preview_url #: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__layout_preview_url
msgid "Full layout preview" msgid "Full layout preview"
msgstr "" msgstr ""
@ -58,6 +63,16 @@ msgstr ""
msgid "Here you find all the template for the given model." msgid "Here you find all the template for the given model."
msgstr "" msgstr ""
#. module: mail_layout_preview
#: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview__id
msgid "ID"
msgstr ""
#. module: mail_layout_preview
#: model:ir.model.fields,field_description:mail_layout_preview.field_mail_template_preview____last_update
msgid "Last Modified on"
msgstr ""
#. module: mail_layout_preview #. module: mail_layout_preview
#: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list #: model_terms:ir.ui.view,arch_db:mail_layout_preview.email_templates_list
msgid "Load it" msgid "Load it"

View File

@ -1 +1,2 @@
* Simone Orsi <simahawk@gmail.com> * Simone Orsi <simahawk@gmail.com>
* Phuc Tran Thanh <phuc@trobz.com>

View File

@ -0,0 +1,3 @@
The development of this module has been financially supported by:
* Camptocamp

View File

@ -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/13.0/mail_layout_preview"><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-13-0/social-13-0-mail_layout_preview"><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/13.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/14.0/mail_layout_preview"><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-14-0/social-14-0-mail_layout_preview"><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/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>The purpose of this module is to help development of email templates <p>The purpose of this module is to help development of email templates
allowing to render the full layout preview of each of them.</p> allowing to render the full layout preview of each of them.</p>
<p>Odoo already allows you do preview emails but they are wrapped into Odoo backend theme.</p> <p>Odoo already allows you do preview emails but they are wrapped into Odoo backend theme.</p>
@ -380,7 +380,8 @@ allowing to render the full layout preview of each of them.</p>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul> <li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li> <li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li> <li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li> <li><a class="reference internal" href="#other-credits" id="id6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -403,7 +404,7 @@ Follow the instructions there on how to use the links.</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_layout_preview%0Aversion:%2013.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_layout_preview%0Aversion:%2014.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">
@ -418,16 +419,24 @@ 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>Simone Orsi &lt;<a class="reference external" href="mailto:simahawk&#64;gmail.com">simahawk&#64;gmail.com</a>&gt;</li> <li>Simone Orsi &lt;<a class="reference external" href="mailto:simahawk&#64;gmail.com">simahawk&#64;gmail.com</a>&gt;</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#id6">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p>
<ul class="simple">
<li>Camptocamp</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2> <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<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/13.0/mail_layout_preview">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/14.0/mail_layout_preview">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

@ -16,7 +16,6 @@ class TestLayoutMixin(object):
"subject": "Preview ${object.name}", "subject": "Preview ${object.name}",
"body_html": "<p>Hello ${object.name}</p>", "body_html": "<p>Hello ${object.name}</p>",
"model_id": env["ir.model"]._get(model).id, "model_id": env["ir.model"]._get(model).id,
"user_signature": False,
} }
vals.update(kw) vals.update(kw)
return env["mail.template"].create(vals) return env["mail.template"].create(vals)
@ -28,14 +27,17 @@ class TestLayoutPreview(SavepointCase, TestLayoutMixin):
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.wiz_model = cls.env["email_template.preview"] cls.wiz_model = cls.env["mail.template.preview"]
cls.partner = cls.env.ref("base.res_partner_4") cls.partner = cls.env.ref("base.res_partner_4")
cls.tmpl = cls._create_template(cls.env, cls.partner._name) cls.tmpl = cls._create_template(cls.env, cls.partner._name)
def test_wizard_preview_url(self): def test_wizard_preview_url(self):
wiz = self.wiz_model.with_context( wiz = self.wiz_model.create(
template_id=self.tmpl.id, default_res_id=self.partner.id {
).create({}) "mail_template_id": self.tmpl.id,
"resource_ref": "{},{}".format(self.partner._name, self.partner.id),
}
)
self.assertEqual( self.assertEqual(
wiz.layout_preview_url, wiz.layout_preview_url,
"/email-preview/res.partner/{}/{}/".format(self.tmpl.id, self.partner.id), "/email-preview/res.partner/{}/{}/".format(self.tmpl.id, self.partner.id),

View File

@ -4,8 +4,8 @@
from odoo import api, fields, models from odoo import api, fields, models
class TemplatePreview(models.TransientModel): class MailTemplatePreview(models.TransientModel):
_inherit = "email_template.preview" _inherit = "mail.template.preview"
_url_pattern = "/email-preview/{model}/{templ_id}/{rec_id}/" _url_pattern = "/email-preview/{model}/{templ_id}/{rec_id}/"
@ -13,14 +13,14 @@ class TemplatePreview(models.TransientModel):
string="Full layout preview", compute="_compute_layout_preview_url" string="Full layout preview", compute="_compute_layout_preview_url"
) )
@api.depends("res_id") @api.depends("resource_ref", "model_id", "mail_template_id")
def _compute_layout_preview_url(self): def _compute_layout_preview_url(self):
for rec in self: for rec in self:
if self.env.context.get("template_id"): if rec.mail_template_id:
rec.layout_preview_url = self._url_pattern.format( rec.layout_preview_url = self._url_pattern.format(
model=rec.model_id.model, model=rec.model_id.model,
templ_id=self.env.context["template_id"], templ_id=rec.mail_template_id.id,
rec_id=rec.res_id, rec_id=rec.resource_ref.id,
) )
else: else:
rec.layout_preview_url = "" rec.layout_preview_url = ""

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record model="ir.ui.view" id="email_template_preview_form"> <record model="ir.ui.view" id="email_template_preview_form">
<field name="model">email_template.preview</field> <field name="model">mail.template.preview</field>
<field name="inherit_id" ref="mail.email_template_preview_form" /> <field name="inherit_id" ref="mail.mail_template_preview_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<footer position="before"> <footer position="before">
<hr /> <hr />