From 75ffd70cda9de4f14c16509d80f21df797b76a95 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 15 May 2021 15:45:19 +0200 Subject: [PATCH] [OU-FIX] base_comment_template: Do on post + avoid conflicts --- .../migrations/13.0.1.0.0/post-migration.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 base_comment_template/migrations/13.0.1.0.0/post-migration.py diff --git a/base_comment_template/migrations/13.0.1.0.0/post-migration.py b/base_comment_template/migrations/13.0.1.0.0/post-migration.py new file mode 100644 index 000000000..e1dce39d6 --- /dev/null +++ b/base_comment_template/migrations/13.0.1.0.0/post-migration.py @@ -0,0 +1,24 @@ +# Copyright 2020 NextERP Romania SRL +# Copyright 2021 Tecnativa - Víctor Martínez +# Copyright 2021 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + 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' + AND ip.res_id IS NOT NULL + ON CONFLICT DO NOTHING + """, + )