Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions partner_communication/i18n/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -1750,3 +1750,10 @@ msgstr "Vorschau"
#: model:mail.template,subject:partner_communication.default_communication_template
msgid "{{object.subject or ' '}}"
msgstr ""

#. module: partner_communication
#. odoo-python
#: code:addons/partner_communication/wizards/email_template_preview_view.py:0
msgid ""
"No communication uses this template yet. Choose one in Record to preview it."
msgstr "Noch keine Kommunikation verwendet diese Vorlage. Wählen Sie eine unter Datensatz, um sie in der Vorschau anzuzeigen."
7 changes: 7 additions & 0 deletions partner_communication/i18n/fr_CH.po
Original file line number Diff line number Diff line change
Expand Up @@ -1729,3 +1729,10 @@ msgstr "aperçu"
#: model:mail.template,subject:partner_communication.default_communication_template
msgid "{{object.subject or ' '}}"
msgstr "\t{{object.subject or ' '}}"

#. module: partner_communication
#. odoo-python
#: code:addons/partner_communication/wizards/email_template_preview_view.py:0
msgid ""
"No communication uses this template yet. Choose one in Record to preview it."
msgstr "Aucune communication n'utilise encore ce modèle. Choisissez-en une dans Enregistrement pour le prévisualiser."
7 changes: 7 additions & 0 deletions partner_communication/i18n/it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -1725,3 +1725,10 @@ msgstr "anteprima"
#: model:mail.template,subject:partner_communication.default_communication_template
msgid "{{object.subject or ' '}}"
msgstr "{{oggetto.soggetto o ' '}}"

#. module: partner_communication
#. odoo-python
#: code:addons/partner_communication/wizards/email_template_preview_view.py:0
msgid ""
"No communication uses this template yet. Choose one in Record to preview it."
msgstr "Nessuna comunicazione utilizza ancora questo modello. Sceglierne una in Record per visualizzarne l'anteprima."
2 changes: 2 additions & 0 deletions partner_communication/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
# The licence is in the file __manifest__.py
#
##############################################################################

from . import test_template_preview
49 changes: 49 additions & 0 deletions partner_communication/tests/test_template_preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from odoo.tests.common import TransactionCase


class TestTemplatePreview(TransactionCase):
"""The preview of a communication template renders a communication of a
rule using it (T3523)."""

@classmethod
def setUpClass(cls):
super().setUpClass()
job_model = cls.env["ir.model"]._get("partner.communication.job")
cls.template = cls.env["mail.template"].create(
{
"name": "T3523 preview",
"model_id": job_model.id,
"body_html": "<p>Hello <t t-out='object.config_id.name'/></p>",
}
)
cls.config = cls.env.ref("partner_communication.default_communication").copy(
{"name": "T3523 preview rule", "email_template_id": cls.template.id}
)
cls.partner = cls.env["res.partner"].create({"name": "T3523 preview"})

def _preview(self):
return self.env["mail.template.preview"].create(
{"mail_template_id": self.template.id}
)

def test_preview_uses_a_communication_of_the_template(self):
job = self.env["partner.communication.job"].create(
{"partner_id": self.partner.id, "config_id": self.config.id}
)
# A newer communication of another rule
self.env["partner.communication.job"].create(
{
"partner_id": self.partner.id,
"config_id": self.env.ref(
"partner_communication.default_communication"
).id,
}
)
preview = self._preview()
self.assertEqual(preview.resource_ref, job)
self.assertFalse(preview.error_msg)

def test_preview_without_communication_says_so(self):
preview = self._preview()
self.assertFalse(preview.resource_ref)
self.assertTrue(preview.error_msg)
54 changes: 27 additions & 27 deletions partner_communication/wizards/email_template_preview_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@
#
##############################################################################

from odoo import api, fields, models
from odoo import _, api, models

JOB_MODEL = "partner.communication.job"


class TemplatePreview(models.TransientModel):
_inherit = "mail.template.preview"

res_id = fields.Reference(
selection=lambda s: s._reference_models(), default=lambda s: s._default_model()
)

@api.model
def _reference_models(self):
template = self.env["mail.template"].browse(self._context.get("active_id"))
domain = [("model", "=", template.model)]
models = self.env["ir.model"].search(domain)
result = [(model.model, model.name) for model in models]
return result
def _is_communication_template(self):
return self.mail_template_id.sudo().model == JOB_MODEL

@api.model
def _default_model(self):
recs = self._reference_models()
model = recs[0][0]
model_obj = self.env[model]
has_partner_field = hasattr(model_obj, "partner_id")
if has_partner_field:
domain = [("partner_id", "!=", False)]
else:
domain = []
result = model + "," + str(model_obj.search(domain, limit=1).id)
return result
@api.depends("mail_template_id")
def _compute_resource_ref(self):
"""A communication template reads the objects of its own rule (e.g. a
registration): preview it on a communication of a rule using it, not
on the latest communication of any rule."""
res = super()._compute_resource_ref()
for preview in self.filtered(lambda p: p._is_communication_template()):
job = self.env[JOB_MODEL].search(
[("config_id.email_template_id", "=", preview.mail_template_id.id)],
limit=1,
)
preview.resource_ref = f"{JOB_MODEL},{job.id}" if job else False
return res

@api.onchange("res_id")
def on_change_res_id(self):
return super().on_change_res_id()
@api.depends("lang", "resource_ref")
def _compute_mail_template_fields(self):
res = super()._compute_mail_template_fields()
if self._is_communication_template() and not self.resource_ref:
self.error_msg = _(
"No communication uses this template yet. Choose one in Record "
"to preview it."
)
return res
Loading