[MIG] base_comment_template: Migration to 15.0

TT35696
pull/664/head
Víctor Martínez 2022-09-13 16:43:26 +02:00 committed by Achraf Mhadhbi
parent 36ae90bd37
commit dd174895f7
23 changed files with 106 additions and 330 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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ó"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 "位置"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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"

View File

@ -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

View File

@ -431,7 +431,7 @@ It has a priority field (smaller number = higher priority)</p>
</ol>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Change the report related to the model from configuration and add a statement like:</p>
<dl class="docutils">
<dt>&lt;t t-foreach=”o.comment_template_ids.filtered(lambda x: x.position == before_lines)” t-as=”comment_template_top”&gt;</dt>
@ -447,7 +447,7 @@ If you create a new template with the same configuration (Model, Domain, Positio
<p>If you want to use Qweb templates, or different context, you can specify it just like in
mail.render.mixin with parameters:</p>
<ul class="simple">
<li>engine: “jinja” or “qweb”,</li>
<li>engine: “inline_template”, “qweb” or “qweb_view”,</li>
<li>add_context: dict with your own context,</li>
<li>post_process: perform a post processing on rendered result</li>
</ul>

View File

@ -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"

View File

@ -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):

View File

@ -1,80 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<!-- SMS Template Preview -->
<record model="ir.ui.view" id="base_comment_template_preview_form">
<field name="name">base.comment.template.preview.form</field>
<field name="model">base.comment.template.preview</field>
<field name="arch" type="xml">
<form string="Base Comment Preview">
<h3>Preview of
<field
name="base_comment_template_id"
readonly="1"
nolabel="1"
class="oe_inline"
/>
</h3>
<field name="no_record" invisible="1" />
<field name="model_ids" />
<div class="o_row">
<span>Choose an example
<field
name="model_id"
domain="[('id', 'in', model_ids or False)]"
/>
record:
</span>
<div>
<field
name="resource_ref"
class="oe_inline"
options="{'hide_model': True, 'no_create': True, 'no_edit': True, 'no_open': True}"
attrs="{'invisible': [('no_record', '=', True)]}"
/>
<span
class="text-warning"
attrs="{'invisible': [('no_record', '=', False)]}"
>No records
</span>
</div>
</div>
<p>Choose a language:
<field name="lang" class="oe_inline ml8" />
</p>
<p>Choose an engine:
<field name="engine" class="oe_inline ml8" />
</p>
<label for="body" string="Base Comment content" />
<hr />
<record model="ir.ui.view" id="base_comment_template_preview_form">
<field name="name">base.comment.template.preview.form</field>
<field name="model">base.comment.template.preview</field>
<field name="arch" type="xml">
<form string="Base Comment Preview">
<h3>Preview of
<field
name="body"
name="base_comment_template_id"
readonly="1"
nolabel="1"
options='{"safe": True}'
class="oe_inline"
/>
<hr />
<footer>
<button
string="Discard"
class="btn-secondary"
special="cancel"
</h3>
<field name="no_record" invisible="1" />
<field name="model_ids" />
<div class="o_row">
<span>Choose an example
<field
name="model_id"
domain="[('id', 'in', model_ids or False)]"
/>
</footer>
</form>
</field>
</record>
record:
</span>
<div>
<field
name="resource_ref"
class="oe_inline"
options="{'hide_model': True, 'no_create': True, 'no_edit': True, 'no_open': True}"
attrs="{'invisible': [('no_record', '=', True)]}"
/>
<span
class="text-warning"
attrs="{'invisible': [('no_record', '=', False)]}"
>No records
</span>
</div>
</div>
<p>Choose a language:
<field name="lang" class="oe_inline ml8" />
</p>
<p>Choose an engine:
<field name="engine" class="oe_inline ml8" />
</p>
<label for="body" string="Base Comment content" />
<hr />
<field name="body" readonly="1" nolabel="1" options='{"safe": True}' />
<hr />
<footer>
<button string="Discard" class="btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="base_comment_template_preview_action" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">base.comment.template.preview</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="view_id" ref="base_comment_template_preview_form" />
<field name="target">new</field>
<field name="context">{'default_base_comment_template_id':active_id}</field>
</record>
</data>
<record id="base_comment_template_preview_action" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">base.comment.template.preview</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">form</field>
<field name="view_id" ref="base_comment_template_preview_form" />
<field name="target">new</field>
<field name="context">{'default_base_comment_template_id':active_id}</field>
</record>
</odoo>