From b447e92666d97703dfb69e2af6f5614583f7b6b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?=
Date: Tue, 13 Sep 2022 16:43:26 +0200
Subject: [PATCH] [MIG] base_comment_template: Migration to 15.0
TT35696
---
base_comment_template/README.rst | 4 +-
base_comment_template/__init__.py | 3 +-
base_comment_template/i18n/de.po | 23 ----
base_comment_template/i18n/es.po | 29 ----
base_comment_template/i18n/fr.po | 19 ---
base_comment_template/i18n/gl.po | 19 ---
base_comment_template/i18n/hr.po | 18 ---
base_comment_template/i18n/it.po | 3 -
base_comment_template/i18n/ja.po | 19 ---
base_comment_template/i18n/pt.po | 21 ---
base_comment_template/i18n/pt_BR.po | 21 ---
base_comment_template/i18n/pt_PT.po | 21 ---
base_comment_template/i18n/sk.po | 21 ---
base_comment_template/i18n/sl.po | 19 ---
.../migrations/15.0.1.0.0/post-migration.py | 17 +++
base_comment_template/models/__init__.py | 5 +-
.../models/comment_template.py | 8 +-
base_comment_template/models/ir_model.py | 4 +-
base_comment_template/readme/USAGE.rst | 4 +-
.../static/description/index.html | 4 +-
.../tests/test_base_comment_template.py | 4 +-
.../wizard/base_comment_template_preview.py | 22 +--
.../base_comment_template_preview_views.xml | 128 ++++++++----------
23 files changed, 106 insertions(+), 330 deletions(-)
create mode 100644 base_comment_template/migrations/15.0.1.0.0/post-migration.py
diff --git a/base_comment_template/README.rst b/base_comment_template/README.rst
index e2016370d..a6dd4f38d 100644
--- a/base_comment_template/README.rst
+++ b/base_comment_template/README.rst
@@ -83,7 +83,7 @@ Usage
You should have at least one template with Default field set, if you choose a Partner the template is deselected as a Default one.
If you create a new template with the same configuration (Model, Domain, Position) and set it as Default, the previous one will be deselected as a default one.
-The template is a html field which will be rendered just like a mail template, so you can use variables like ${object}, ${user}, ${ctx} to add dynamic content.
+The template is a html field which will be rendered just like a mail template, so you can use variables like {{object}}, {{user}}, {{ctx}} to add dynamic content.
Change the report related to the model from configuration and add a statement like:
@@ -103,7 +103,7 @@ You should always use t-if since the method returns False if no template is foun
If you want to use Qweb templates, or different context, you can specify it just like in
mail.render.mixin with parameters:
-- engine: "jinja" or "qweb",
+- engine: "inline_template", "qweb" or "qweb_view",
- add_context: dict with your own context,
- post_process: perform a post processing on rendered result
diff --git a/base_comment_template/__init__.py b/base_comment_template/__init__.py
index ba0a966ff..f987065d3 100644
--- a/base_comment_template/__init__.py
+++ b/base_comment_template/__init__.py
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from . import models, wizard
+from . import models
+from . import wizard
diff --git a/base_comment_template/i18n/de.po b/base_comment_template/i18n/de.po
index a04d6d4d0..be50e563c 100644
--- a/base_comment_template/i18n/de.po
+++ b/base_comment_template/i18n/de.po
@@ -344,26 +344,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Suffix"
-
-#~ msgid "Base comment template"
-#~ msgstr "Textbausteinvorlage"
-
-#~ msgid "Before lines"
-#~ msgstr "Präfix"
-
-#~ msgid "Comment summary"
-#~ msgstr "Textbaustein-Zusammenfassung"
-
-#~ msgid "Conditions template"
-#~ msgstr "Textbausteinvorlage"
-
-#~ msgid "If set, it'll only be available for this company"
-#~ msgstr ""
-#~ "Wenn der Haken gesetzt ist, ist die Vorlage nur das gesetzte Unternehmen "
-#~ "verfügbar."
-
-#~ msgid "Position"
-#~ msgstr "Position"
diff --git a/base_comment_template/i18n/es.po b/base_comment_template/i18n/es.po
index 7530437e1..29714bbf8 100644
--- a/base_comment_template/i18n/es.po
+++ b/base_comment_template/i18n/es.po
@@ -355,32 +355,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Después de las líneas"
-
-#~ msgid "Before lines"
-#~ msgstr "Antes de las líneas"
-
-#~ msgid "Priority"
-#~ msgstr "Prioridad"
-
-#~ msgid ""
-#~ "There are other records with same models, priority, domain and position."
-#~ msgstr ""
-#~ "Hay otros registros con los mismos datos en modelo, prioridad, dominio y "
-#~ "posición."
-
-#~ msgid "the highest priority = the smallest number"
-#~ msgstr "Mayor prioridad = número menor"
-
-#~ msgid "Comment summary"
-#~ msgstr "Índice de comentarios"
-
-#, fuzzy
-#~| msgid "Comment Templates"
-#~ msgid "Conditions template"
-#~ msgstr "Plantillas de comentarios"
-
-#~ msgid "Position"
-#~ msgstr "Posició"
diff --git a/base_comment_template/i18n/fr.po b/base_comment_template/i18n/fr.po
index 9df9dc3a2..6ebe1436c 100644
--- a/base_comment_template/i18n/fr.po
+++ b/base_comment_template/i18n/fr.po
@@ -342,22 +342,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Après les lignes"
-
-#~ msgid "Base comment template"
-#~ msgstr "Modèle de textes de commentaires"
-
-#~ msgid "Before lines"
-#~ msgstr "Avant les lignes"
-
-#~ msgid "Comment summary"
-#~ msgstr "Nom"
-
-#, fuzzy
-#~ msgid "Conditions template"
-#~ msgstr "Modèles de commentaires"
-
-#~ msgid "Position"
-#~ msgstr "Position"
diff --git a/base_comment_template/i18n/gl.po b/base_comment_template/i18n/gl.po
index d6624cd5e..584bdd05b 100644
--- a/base_comment_template/i18n/gl.po
+++ b/base_comment_template/i18n/gl.po
@@ -343,22 +343,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Despois das liñas"
-
-#~ msgid "Base comment template"
-#~ msgstr "Modelo do comentario base"
-
-#~ msgid "Before lines"
-#~ msgstr "Antes das liñas"
-
-#~ msgid "Comment summary"
-#~ msgstr "Índice de comentarios"
-
-#, fuzzy
-#~ msgid "Conditions template"
-#~ msgstr "Modelos de comentarios"
-
-#~ msgid "Position"
-#~ msgstr "Posición"
diff --git a/base_comment_template/i18n/hr.po b/base_comment_template/i18n/hr.po
index f14f2416b..6d52b7f24 100644
--- a/base_comment_template/i18n/hr.po
+++ b/base_comment_template/i18n/hr.po
@@ -345,21 +345,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Iza linija"
-
-#~ msgid "Base comment template"
-#~ msgstr "Osnovni Predložak komentara"
-
-#~ msgid "Before lines"
-#~ msgstr "Ispred linija"
-
-#~ msgid "Comment summary"
-#~ msgstr "Sažetak komentara"
-
-#~ msgid "Conditions template"
-#~ msgstr "Predložak uvjeta"
-
-#~ msgid "Position"
-#~ msgstr "Pozicija"
diff --git a/base_comment_template/i18n/it.po b/base_comment_template/i18n/it.po
index e2b0844ef..6accf86a6 100644
--- a/base_comment_template/i18n/it.po
+++ b/base_comment_template/i18n/it.po
@@ -358,6 +358,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "Position"
-#~ msgstr "Posizione"
diff --git a/base_comment_template/i18n/ja.po b/base_comment_template/i18n/ja.po
index cbe0cdcbe..51ff73eaa 100644
--- a/base_comment_template/i18n/ja.po
+++ b/base_comment_template/i18n/ja.po
@@ -343,22 +343,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "明細行後"
-
-#~ msgid "Base comment template"
-#~ msgstr "Base comment template"
-
-#~ msgid "Before lines"
-#~ msgstr "明細行前"
-
-#~ msgid "Comment summary"
-#~ msgstr "コメントサマリ"
-
-#, fuzzy
-#~ msgid "Conditions template"
-#~ msgstr "コメントテンプレート"
-
-#~ msgid "Position"
-#~ msgstr "位置"
diff --git a/base_comment_template/i18n/pt.po b/base_comment_template/i18n/pt.po
index c5b2bd7e9..f836e2287 100644
--- a/base_comment_template/i18n/pt.po
+++ b/base_comment_template/i18n/pt.po
@@ -356,24 +356,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Após as linhas"
-
-#~ msgid "Base comment template"
-#~ msgstr "Modelo de Comentários Base"
-
-#~ msgid "Before lines"
-#~ msgstr "Antes das Linhas"
-
-#~ msgid "Comment summary"
-#~ msgstr "Resumo de comentário"
-
-#~ msgid "Conditions template"
-#~ msgstr "Modelos de condições"
-
-#~ msgid "If set, it'll only be available for this company"
-#~ msgstr "Se assinalado, só estará disponível para esta empresa"
-
-#~ msgid "Position"
-#~ msgstr "Posição"
diff --git a/base_comment_template/i18n/pt_BR.po b/base_comment_template/i18n/pt_BR.po
index dc9fbe4a8..9cd2858df 100644
--- a/base_comment_template/i18n/pt_BR.po
+++ b/base_comment_template/i18n/pt_BR.po
@@ -344,24 +344,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Depois das linhas"
-
-#~ msgid "Base comment template"
-#~ msgstr "Modelo de comentário Base"
-
-#~ msgid "Before lines"
-#~ msgstr "Antes das linhas"
-
-#~ msgid "Comment summary"
-#~ msgstr "Índice de comentários"
-
-#~ msgid "Conditions template"
-#~ msgstr "Modelos de condições"
-
-#~ msgid "If set, it'll only be available for this company"
-#~ msgstr "Se definido, ele estará disponível apenas para esta empresa"
-
-#~ msgid "Position"
-#~ msgstr "Posição"
diff --git a/base_comment_template/i18n/pt_PT.po b/base_comment_template/i18n/pt_PT.po
index 56b3f1fce..27f5d1f70 100644
--- a/base_comment_template/i18n/pt_PT.po
+++ b/base_comment_template/i18n/pt_PT.po
@@ -344,24 +344,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Após as linhas"
-
-#~ msgid "Base comment template"
-#~ msgstr "Modelo de comentários base"
-
-#~ msgid "Before lines"
-#~ msgstr "Antes das linhas"
-
-#~ msgid "Comment summary"
-#~ msgstr "Resumo de comentários"
-
-#~ msgid "Conditions template"
-#~ msgstr "Modelo de condições"
-
-#~ msgid "If set, it'll only be available for this company"
-#~ msgstr "Se assinalado, será apenas visível para esta empresa"
-
-#~ msgid "Position"
-#~ msgstr "Posição"
diff --git a/base_comment_template/i18n/sk.po b/base_comment_template/i18n/sk.po
index bc3a81d17..8b856fd64 100644
--- a/base_comment_template/i18n/sk.po
+++ b/base_comment_template/i18n/sk.po
@@ -343,24 +343,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Za položkami"
-
-#~ msgid "Base comment template"
-#~ msgstr "Základná šablóna komentárov"
-
-#~ msgid "Before lines"
-#~ msgstr "Pred položkami"
-
-#~ msgid "Comment summary"
-#~ msgstr "Názov"
-
-#~ msgid "Conditions template"
-#~ msgstr "Predvolená šablóna"
-
-#~ msgid "If set, it'll only be available for this company"
-#~ msgstr "Ak je nastavená, bude k dispozícii iba pre túto spoločnosť"
-
-#~ msgid "Position"
-#~ msgstr "Pozícia"
diff --git a/base_comment_template/i18n/sl.po b/base_comment_template/i18n/sl.po
index 6065b1f2d..e0dc6c52f 100644
--- a/base_comment_template/i18n/sl.po
+++ b/base_comment_template/i18n/sl.po
@@ -344,22 +344,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:base_comment_template.base_comment_template_preview_form
msgid "record:"
msgstr ""
-
-#~ msgid "After lines"
-#~ msgstr "Po postavkah"
-
-#~ msgid "Base comment template"
-#~ msgstr "Osnovna predloga za komentarje"
-
-#~ msgid "Before lines"
-#~ msgstr "Pred postavkami"
-
-#~ msgid "Comment summary"
-#~ msgstr "Povzetek komentarjev"
-
-#, fuzzy
-#~ msgid "Conditions template"
-#~ msgstr "Predloge komentarjev"
-
-#~ msgid "Position"
-#~ msgstr "Položaj"
diff --git a/base_comment_template/migrations/15.0.1.0.0/post-migration.py b/base_comment_template/migrations/15.0.1.0.0/post-migration.py
new file mode 100644
index 000000000..fe9f2f703
--- /dev/null
+++ b/base_comment_template/migrations/15.0.1.0.0/post-migration.py
@@ -0,0 +1,17 @@
+# Copyright 2022 Tecnativa - Víctor Martínez
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+import re
+
+from openupgradelib import openupgrade
+
+
+@openupgrade.migrate()
+def migrate(env, version):
+ """In v15 mail engine is inline_template, we try to replace the following:
+ - ${object} > {{object}}
+ - ${user} > {{user}}
+ - ${ctx} > {{ctx}}
+ """
+ for item in env["base.comment.template"].search([("text", "ilike", "${")]):
+ item.text = re.sub(r"\${(.+)}", r"{{\1}}", item.text)
diff --git a/base_comment_template/models/__init__.py b/base_comment_template/models/__init__.py
index 9ac817697..385ad1d18 100644
--- a/base_comment_template/models/__init__.py
+++ b/base_comment_template/models/__init__.py
@@ -1 +1,4 @@
-from . import base_comment_template, comment_template, ir_model, res_partner
+from . import base_comment_template
+from . import comment_template
+from . import ir_model
+from . import res_partner
diff --git a/base_comment_template/models/comment_template.py b/base_comment_template/models/comment_template.py
index befd11cd0..b421eadc1 100644
--- a/base_comment_template/models/comment_template.py
+++ b/base_comment_template/models/comment_template.py
@@ -44,13 +44,13 @@ class CommentTemplate(models.AbstractModel):
record.comment_template_ids = [(4, template.id)]
def render_comment(
- self, comment, engine="jinja", add_context=None, post_process=False
+ self, comment, engine="inline_template", add_context=None, post_process=False
):
self.ensure_one()
comment_texts = self.env["mail.render.mixin"]._render_template(
- comment.text,
- self._name,
- [self.id],
+ template_src=comment.text,
+ model=self._name,
+ res_ids=[self.id],
engine=engine,
add_context=add_context,
post_process=post_process,
diff --git a/base_comment_template/models/ir_model.py b/base_comment_template/models/ir_model.py
index b799732b0..85a35343b 100644
--- a/base_comment_template/models/ir_model.py
+++ b/base_comment_template/models/ir_model.py
@@ -14,7 +14,7 @@ class IrModel(models.Model):
)
def _reflect_model_params(self, model):
- vals = super(IrModel, self)._reflect_model_params(model)
+ vals = super()._reflect_model_params(model)
vals["is_comment_template"] = issubclass(
type(model), self.pool["comment.template"]
)
@@ -22,7 +22,7 @@ class IrModel(models.Model):
@api.model
def _instanciate(self, model_data):
- model_class = super(IrModel, self)._instanciate(model_data)
+ model_class = super()._instanciate(model_data)
if (
model_data.get("is_comment_template")
and model_class._name != "comment.template"
diff --git a/base_comment_template/readme/USAGE.rst b/base_comment_template/readme/USAGE.rst
index 5c7d46bc8..8800f0741 100644
--- a/base_comment_template/readme/USAGE.rst
+++ b/base_comment_template/readme/USAGE.rst
@@ -12,7 +12,7 @@
You should have at least one template with Default field set, if you choose a Partner the template is deselected as a Default one.
If you create a new template with the same configuration (Model, Domain, Position) and set it as Default, the previous one will be deselected as a default one.
-The template is a html field which will be rendered just like a mail template, so you can use variables like ${object}, ${user}, ${ctx} to add dynamic content.
+The template is a html field which will be rendered just like a mail template, so you can use variables like {{object}}, {{user}}, {{ctx}} to add dynamic content.
Change the report related to the model from configuration and add a statement like:
@@ -32,7 +32,7 @@ You should always use t-if since the method returns False if no template is foun
If you want to use Qweb templates, or different context, you can specify it just like in
mail.render.mixin with parameters:
-- engine: "jinja" or "qweb",
+- engine: "inline_template", "qweb" or "qweb_view",
- add_context: dict with your own context,
- post_process: perform a post processing on rendered result
diff --git a/base_comment_template/static/description/index.html b/base_comment_template/static/description/index.html
index cf5471d59..ec7ec6185 100644
--- a/base_comment_template/static/description/index.html
+++ b/base_comment_template/static/description/index.html
@@ -431,7 +431,7 @@ It has a priority field (smaller number = higher priority)
You should have at least one template with Default field set, if you choose a Partner the template is deselected as a Default one.
If you create a new template with the same configuration (Model, Domain, Position) and set it as Default, the previous one will be deselected as a default one.
-The template is a html field which will be rendered just like a mail template, so you can use variables like ${object}, ${user}, ${ctx} to add dynamic content.
+The template is a html field which will be rendered just like a mail template, so you can use variables like {{object}}, {{user}}, {{ctx}} to add dynamic content.
Change the report related to the model from configuration and add a statement like:
- <t t-foreach=”o.comment_template_ids.filtered(lambda x: x.position == ‘before_lines’)” t-as=”comment_template_top”>
@@ -447,7 +447,7 @@ If you create a new template with the same configuration (Model, Domain, Positio
If you want to use Qweb templates, or different context, you can specify it just like in
mail.render.mixin with parameters:
-- engine: “jinja” or “qweb”,
+- engine: “inline_template”, “qweb” or “qweb_view”,
- add_context: dict with your own context,
- post_process: perform a post processing on rendered result
diff --git a/base_comment_template/tests/test_base_comment_template.py b/base_comment_template/tests/test_base_comment_template.py
index 8aaa2b8d3..d8fc35620 100644
--- a/base_comment_template/tests/test_base_comment_template.py
+++ b/base_comment_template/tests/test_base_comment_template.py
@@ -92,7 +92,7 @@ class TestCommentTemplate(common.TransactionCase):
def test_render_comment_text(self):
expected_text = "Test comment render %s" % self.user.name
- self.before_template_id.text = "Test comment render ${object.name}"
+ self.before_template_id.text = "Test comment render {{object.name}}"
with self.with_user(self.user.login):
self.assertEqual(
self.user.render_comment(self.before_template_id), expected_text
@@ -114,7 +114,7 @@ class TestCommentTemplate(common.TransactionCase):
{"name": "Ambasador", "shortcut": "Amb."}
)
self.user.partner_id.title = partner_title
- self.before_template_id.text = "Test comment render ${object.title.name}"
+ self.before_template_id.text = "Test comment render {{object.title.name}}"
expected_en_text = "Test comment render Ambassador"
expected_ro_text = "Test comment render Ambasador"
diff --git a/base_comment_template/wizard/base_comment_template_preview.py b/base_comment_template/wizard/base_comment_template_preview.py
index 86e6c1ba7..bd9ff9c99 100644
--- a/base_comment_template/wizard/base_comment_template_preview.py
+++ b/base_comment_template/wizard/base_comment_template_preview.py
@@ -1,6 +1,8 @@
from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval
+from odoo.addons.base.models.res_partner import _lang_get
+
class BaseCommentTemplatePreview(models.TransientModel):
_name = "base.comment.template.preview"
@@ -11,13 +13,9 @@ class BaseCommentTemplatePreview(models.TransientModel):
models = self.env["ir.model"].search([("is_comment_template", "=", True)])
return [(model.model, model.name) for model in models]
- @api.model
- def _selection_languages(self):
- return self.env["res.lang"].get_installed()
-
@api.model
def default_get(self, fields):
- result = super(BaseCommentTemplatePreview, self).default_get(fields)
+ result = super().default_get(fields)
base_comment_template_id = self.env.context.get(
"default_base_comment_template_id"
)
@@ -41,21 +39,25 @@ class BaseCommentTemplatePreview(models.TransientModel):
base_comment_template_id = fields.Many2one(
"base.comment.template", required=True, ondelete="cascade"
)
- lang = fields.Selection(_selection_languages, string="Template Preview Language")
+ lang = fields.Selection(_lang_get, string="Template Preview Language")
engine = fields.Selection(
- [("jinja", "Jinja"), ("qweb", "QWeb")],
+ [
+ ("inline_template", "Inline template"),
+ ("qweb", "QWeb"),
+ ("qweb_view", "QWeb view"),
+ ],
string="Template Preview Engine",
- default="jinja",
+ default="inline_template",
)
model_ids = fields.Many2many(
"ir.model", related="base_comment_template_id.model_ids"
)
model_id = fields.Many2one("ir.model")
- body = fields.Char("Body", compute="_compute_base_comment_template_fields")
+ body = fields.Char(compute="_compute_base_comment_template_fields")
resource_ref = fields.Reference(
string="Record reference", selection="_selection_target_model"
)
- no_record = fields.Boolean("No Record", compute="_compute_no_record")
+ no_record = fields.Boolean(compute="_compute_no_record")
@api.depends("model_id")
def _compute_no_record(self):
diff --git a/base_comment_template/wizard/base_comment_template_preview_views.xml b/base_comment_template/wizard/base_comment_template_preview_views.xml
index 513bab63d..a6de5766b 100644
--- a/base_comment_template/wizard/base_comment_template_preview_views.xml
+++ b/base_comment_template/wizard/base_comment_template_preview_views.xml
@@ -1,80 +1,66 @@
-
-
-
+