From e3abb35faf2b3b56bab1eb786267e9a07ce49e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20Alan=20Ramos=20Rodri=CC=81guez?= Date: Fri, 3 May 2024 10:01:36 -0600 Subject: [PATCH] [MIG] base_comment_template: Migration to 17.0 --- base_comment_template/__manifest__.py | 2 +- .../models/base_comment_template.py | 23 +++++++++++-------- .../models/comment_template.py | 6 ++--- .../security/ir.model.access.csv | 1 - .../tests/test_base_comment_template.py | 4 ++-- .../views/base_comment_template_view.xml | 2 +- .../wizard/base_comment_template_preview.py | 2 +- .../base_comment_template_preview_views.xml | 7 ++---- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/base_comment_template/__manifest__.py b/base_comment_template/__manifest__.py index 3fe483de79..88b705f921 100644 --- a/base_comment_template/__manifest__.py +++ b/base_comment_template/__manifest__.py @@ -5,7 +5,7 @@ "name": "Base Comments Templates", "summary": "Add conditional mako template to any report" "on models that inherits comment.template.", - "version": "16.0.2.2.2", + "version": "17.0.1.0.0", "category": "Reporting", "website": "https://github.com/OCA/reporting-engine", "author": "Camptocamp, Odoo Community Association (OCA)", diff --git a/base_comment_template/models/base_comment_template.py b/base_comment_template/models/base_comment_template.py index 37c0a5f54a..aa54cad497 100644 --- a/base_comment_template/models/base_comment_template.py +++ b/base_comment_template/models/base_comment_template.py @@ -80,7 +80,8 @@ class BaseCommentTemplate(models.Model): ], required=True, default="inline_template", - help="This field allows to select the engine to use for rendering the template.", + help="This field allows to select the engine to use for rendering the " + "template.", ) def _get_ir_model_items(self, models): @@ -114,17 +115,19 @@ def check_models(self): if not res or len(res) != len(models): raise ValidationError(_("Some model (%s) not found") % item.models) - def name_get(self): - """Redefine the name_get method to show the template name with the position.""" - res = [] - for item in self: - name = "{} ({})".format( - item.name, dict(self._fields["position"].selection).get(item.position) + @api.depends("position", "model_ids") + def _compute_display_name(self): + for rec in self: + name = "{name} ({position})".format( + name=rec.name, + position=dict(self._fields["position"].selection).get(rec.position), ) if self.env.context.get("comment_template_model_display"): - name += " (%s)" % ", ".join(item.model_ids.mapped("name")) - res.append((item.id, name)) - return res + name = "{name} ({models})".format( + name=name, + models=", ".join(rec.model_ids.mapped("name")), + ) + rec.display_name = name def _search_model_ids(self, operator, value): # We cannot use model_ids.model in search() method to avoid access errors diff --git a/base_comment_template/models/comment_template.py b/base_comment_template/models/comment_template.py index 0d000f197f..8858ac384f 100644 --- a/base_comment_template/models/comment_template.py +++ b/base_comment_template/models/comment_template.py @@ -51,9 +51,7 @@ def _compute_comment_template_ids(self): if not domain or record.filtered_domain(domain): record.comment_template_ids = [(4, template.id)] - def render_comment( - self, comment, engine=False, add_context=None, post_process=False - ): + def render_comment(self, comment, engine=False, add_context=None, options=None): self.ensure_one() comment_texts = self.env["mail.render.mixin"]._render_template( template_src=comment.text, @@ -61,6 +59,6 @@ def render_comment( res_ids=[self.id], engine=engine or comment.engine, add_context=add_context, - post_process=post_process, + options=options, ) return markupsafe.Markup(comment_texts[self.id]) or "" diff --git a/base_comment_template/security/ir.model.access.csv b/base_comment_template/security/ir.model.access.csv index af72e1c8f4..acfeb4685f 100644 --- a/base_comment_template/security/ir.model.access.csv +++ b/base_comment_template/security/ir.model.access.csv @@ -1,4 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_base_comment_template_user,access_base_comment_template_user,model_base_comment_template,,1,0,0,0 access_base_comment_template,access_base_comment_template no one,model_base_comment_template,base.group_no_one,1,1,1,1 access_base_comment_template_preview,access.base.comment.template.preview,model_base_comment_template_preview,base.group_user,1,1,1,0 diff --git a/base_comment_template/tests/test_base_comment_template.py b/base_comment_template/tests/test_base_comment_template.py index 7ad31cdc7b..d13a521685 100644 --- a/base_comment_template/tests/test_base_comment_template.py +++ b/base_comment_template/tests/test_base_comment_template.py @@ -47,7 +47,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): teardown_test_model(cls.env, ResUsers) - return super(TestCommentTemplate, cls).tearDownClass() + return super().tearDownClass() def test_template_model_ids(self): self.assertIn( @@ -70,7 +70,7 @@ def test_template_models_constrains(self): } ) - def test_template_name_get(self): + def test_template_display_name(self): self.assertEqual( self.before_template_id.display_name, "Top template (Top)", diff --git a/base_comment_template/views/base_comment_template_view.xml b/base_comment_template/views/base_comment_template_view.xml index 8fa5237377..362947d0a5 100644 --- a/base_comment_template/views/base_comment_template_view.xml +++ b/base_comment_template/views/base_comment_template_view.xml @@ -44,7 +44,7 @@ name="web_ribbon" title="Archived" bg_color="bg-danger" - attrs="{'invisible': [('active', '=', True)]}" + invisible="active" />