mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[IMP] base_comment_template: Refactor code and convert to Many2Many
This commit is contained in:
22
base_comment_template/migrations/13.0.1.0.0/pre-migration.py
Normal file
22
base_comment_template/migrations/13.0.1.0.0/pre-migration.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2020 NextERP Romania SRL
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
# Not tested
|
||||
openupgrade.logged_query(
|
||||
env.cr,
|
||||
"""
|
||||
INSERT INTO base_comment_template_res_partner_rel
|
||||
(res_partner_id, base_comment_template_id)
|
||||
SELECT SPLIT_PART(ip.res_id, ',', 2)::int AS res_partner_id,
|
||||
SPLIT_PART(ip.value_reference, ',', 2)::int AS base_comment_template_id
|
||||
FROM ir_property ip
|
||||
JOIN ir_model_fields imf ON ip.fields_id = imf.id
|
||||
WHERE imf.name = 'property_comment_template_id'
|
||||
AND imf.model = 'res.partner'
|
||||
""",
|
||||
)
|
||||
12
base_comment_template/migrations/13.0.2.0.0/pre-migration.py
Normal file
12
base_comment_template/migrations/13.0.2.0.0/pre-migration.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from openupgradelib import openupgrade # pylint: disable=W7936
|
||||
|
||||
field_renames = [
|
||||
("base.comment.template", "base_comment_template", "priority", "sequence"),
|
||||
]
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
openupgrade.rename_fields(env, field_renames)
|
||||
@@ -1,26 +0,0 @@
|
||||
# Copyright 2020 NextERP Romania SRL
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
# Not tested
|
||||
properties = env["ir.property"].search(
|
||||
[
|
||||
(
|
||||
"fields_id",
|
||||
"=",
|
||||
env.ref("base.field_res_partner_property_comment_template_id").id,
|
||||
)
|
||||
]
|
||||
)
|
||||
if properties:
|
||||
for template in properties.mapped("value_reference"):
|
||||
template_id = template.value_reference.split(",")[-1]
|
||||
if template_id:
|
||||
template = env["base.comment.template"].browse(template_id)
|
||||
part_prop = properties.filtered(lambda p: p.value_reference == template)
|
||||
template.partner_ids = [
|
||||
(prop["res_id"] or "").split(",")[-1] for prop in part_prop
|
||||
]
|
||||
Reference in New Issue
Block a user