From 4b95fcf7f3010165f587998109b5bcac726ad093 Mon Sep 17 00:00:00 2001
From: Maksym Yankin
Date: Wed, 8 Jan 2025 16:16:16 +0200
Subject: [PATCH] [MIG] base_comment_template: Migration to 18.0
---
base_comment_template/README.rst | 10 +++----
base_comment_template/__manifest__.py | 2 +-
.../migrations/16.0.1.0.0/post-migration.py | 17 ------------
.../migrations/16.0.1.1.0/pre-migration.py | 27 -------------------
.../models/base_comment_template.py | 9 ++++---
.../models/comment_template.py | 4 +--
.../static/description/index.html | 6 ++---
.../tests/test_base_comment_template.py | 4 +--
.../views/base_comment_template_view.xml | 10 ++++---
.../views/res_partner_view.xml | 4 +--
10 files changed, 27 insertions(+), 66 deletions(-)
delete mode 100644 base_comment_template/migrations/16.0.1.0.0/post-migration.py
delete mode 100644 base_comment_template/migrations/16.0.1.1.0/pre-migration.py
diff --git a/base_comment_template/README.rst b/base_comment_template/README.rst
index be6ca1d5fb..68d67a6030 100644
--- a/base_comment_template/README.rst
+++ b/base_comment_template/README.rst
@@ -17,13 +17,13 @@ Base Comments Templates
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
- :target: https://github.com/OCA/reporting-engine/tree/17.0/base_comment_template
+ :target: https://github.com/OCA/reporting-engine/tree/18.0/base_comment_template
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/reporting-engine-17-0/reporting-engine-17-0-base_comment_template
+ :target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-base_comment_template
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=17.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -140,7 +140,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -199,6 +199,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-This module is part of the `OCA/reporting-engine `_ project on GitHub.
+This module is part of the `OCA/reporting-engine `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/base_comment_template/__manifest__.py b/base_comment_template/__manifest__.py
index 88b705f921..5b2a1f0a60 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": "17.0.1.0.0",
+ "version": "18.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/migrations/16.0.1.0.0/post-migration.py b/base_comment_template/migrations/16.0.1.0.0/post-migration.py
deleted file mode 100644
index fe9f2f703b..0000000000
--- a/base_comment_template/migrations/16.0.1.0.0/post-migration.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# 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/migrations/16.0.1.1.0/pre-migration.py b/base_comment_template/migrations/16.0.1.1.0/pre-migration.py
deleted file mode 100644
index 89d9cbce40..0000000000
--- a/base_comment_template/migrations/16.0.1.1.0/pre-migration.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright 2022 Tecnativa - Víctor Martínez
-# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-
-from openupgradelib import openupgrade
-
-from odoo.tools.sql import column_exists
-
-
-@openupgrade.migrate()
-def migrate(env, version):
- if not column_exists(env.cr, "base_comment_template", "models"):
- openupgrade.logged_query(
- env.cr,
- "ALTER TABLE base_comment_template ADD COLUMN IF NOT EXISTS models text",
- )
- openupgrade.logged_query(
- env.cr,
- """
- UPDATE base_comment_template template
- SET models = (
- SELECT string_agg(model.model, ',')
- FROM base_comment_template_ir_model_rel AS rel
- JOIN ir_model AS model ON rel.ir_model_id = model.id
- WHERE rel.base_comment_template_id = template.id
- )
- """,
- )
diff --git a/base_comment_template/models/base_comment_template.py b/base_comment_template/models/base_comment_template.py
index aa54cad497..7ea8bce0db 100644
--- a/base_comment_template/models/base_comment_template.py
+++ b/base_comment_template/models/base_comment_template.py
@@ -3,7 +3,7 @@
# Copyright 2020 NextERP Romania SRL
# Copyright 2021-2022 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from odoo import _, api, fields, models
+from odoo import Command, api, fields, models
from odoo.exceptions import ValidationError
@@ -48,7 +48,6 @@ class BaseCommentTemplate(models.Model):
column1="base_comment_template_id",
column2="res_partner_id",
string="Partner",
- readonly=True,
help="If set, the comment template will be available only for the selected "
"partner.",
)
@@ -104,7 +103,7 @@ def _compute_model_ids(self):
models = im_model.browse()
if item.models:
models = self._get_ir_model_items(item.models.split(","))
- item.model_ids = [(6, 0, models.ids)]
+ item.model_ids = [Command.set(models.ids)]
@api.constrains("models")
def check_models(self):
@@ -113,7 +112,9 @@ def check_models(self):
models = item.models.split(",")
res = self._get_ir_model_items(item.models.split(","))
if not res or len(res) != len(models):
- raise ValidationError(_("Some model (%s) not found") % item.models)
+ raise ValidationError(
+ self.env._(f"Some model ({item.models}) not found")
+ )
@api.depends("position", "model_ids")
def _compute_display_name(self):
diff --git a/base_comment_template/models/comment_template.py b/base_comment_template/models/comment_template.py
index 8858ac384f..f03c629497 100644
--- a/base_comment_template/models/comment_template.py
+++ b/base_comment_template/models/comment_template.py
@@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import markupsafe
-from odoo import api, fields, models
+from odoo import Command, api, fields, models
from odoo.osv import expression
from odoo.tools.safe_eval import safe_eval
@@ -49,7 +49,7 @@ def _compute_comment_template_ids(self):
for template in templates:
domain = safe_eval(template.domain)
if not domain or record.filtered_domain(domain):
- record.comment_template_ids = [(4, template.id)]
+ record.comment_template_ids = [Command.link(template.id)]
def render_comment(self, comment, engine=False, add_context=None, options=None):
self.ensure_one()
diff --git a/base_comment_template/static/description/index.html b/base_comment_template/static/description/index.html
index 876cf0898a..72b907e327 100644
--- a/base_comment_template/static/description/index.html
+++ b/base_comment_template/static/description/index.html
@@ -369,7 +369,7 @@ Base Comments Templates
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3b5eb88dbd79b1149e679ff90f3a24b61a1f07af046693635b7fc3b597479aba
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
Add a new mixin class to define templates of comments to print on
documents. The comment templates can be defined like make templates, so
you can use variables from linked models.
@@ -484,7 +484,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -540,7 +540,7 @@
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
-
This module is part of the OCA/reporting-engine project on GitHub.
+
This module is part of the OCA/reporting-engine project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/base_comment_template/tests/test_base_comment_template.py b/base_comment_template/tests/test_base_comment_template.py
index d13a521685..f25a434737 100644
--- a/base_comment_template/tests/test_base_comment_template.py
+++ b/base_comment_template/tests/test_base_comment_template.py
@@ -105,7 +105,7 @@ def test_partner_template_domain(self):
(4, self.before_template_id.id),
(4, self.after_template_id.id),
]
- self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
+ self.before_template_id.domain = f"[('id', 'in', {self.user.ids})]"
self.assertTrue(
self.before_template_id in self.partner2_id.base_comment_template_ids
)
@@ -114,7 +114,7 @@ def test_partner_template_domain(self):
)
def test_render_comment_text(self):
- expected_text = "Test comment render %s" % self.user.name
+ expected_text = f"Test comment render {self.user.name}"
self.before_template_id.text = "Test comment render {{object.name}}"
with self.with_user(self.user.login):
self.assertEqual(
diff --git a/base_comment_template/views/base_comment_template_view.xml b/base_comment_template/views/base_comment_template_view.xml
index 362947d0a5..3ecba80ed4 100644
--- a/base_comment_template/views/base_comment_template_view.xml
+++ b/base_comment_template/views/base_comment_template_view.xml
@@ -4,7 +4,7 @@
base.comment.template.search
base.comment.template
-
+
@@ -13,7 +13,7 @@
-
+