Skip to content

Commit

Permalink
Merge pull request OCA#2455 from ForgeFlow/13.0-fix-utm-avoid-foreign…
Browse files Browse the repository at this point in the history
…_key-error

[13.0][FIX] utm: avoid foreign_key error in utm_tag_rel table
  • Loading branch information
pedrobaeza committed Nov 30, 2020
2 parents b2bb2d8 + 6819841 commit d9cdbf1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 19 additions & 0 deletions addons/utm/migrations/13.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


def update_utm_tag_rel(env):
openupgrade.logged_query(
env.cr, """
INSERT INTO utm_tag_rel (tag_id, campaign_id)
SELECT rel.tag_id, mmc.campaign_id
FROM mail_mass_mailing_tag_rel rel
JOIN mail_mass_mailing_campaign mmc ON mmc.id = rel.campaign_id"""
)


@openupgrade.migrate()
def migrate(env, version):
if openupgrade.table_exists(env.cr, 'mail_mass_mailing_stage'):
update_utm_tag_rel(env)
9 changes: 1 addition & 8 deletions addons/utm/migrations/13.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
_table_renames = [
('mail_mass_mailing_stage', 'utm_stage'),
('mail_mass_mailing_tag', 'utm_tag'),
('mail_mass_mailing_tag_rel', 'utm_tag_rel'),
]

_xmlid_renames = [
Expand All @@ -21,6 +20,7 @@
'utm.campaign_stage_2'),
('mass_mailing.campaign_stage_3',
'utm.campaign_stage_3'),
('mass_mailing.mass_mail_tag_1', 'utm.utm_tag_1'),
]


Expand All @@ -37,13 +37,6 @@ def move_mailing_campaign_to_utm_campaign(env):
FROM mail_mass_mailing_campaign mmc
WHERE mmc.campaign_id = uc.id"""
)
openupgrade.logged_query(
env.cr, """
UPDATE utm_tag_rel utr
SET campaign_id = mmc.campaign_id
FROM mail_mass_mailing_campaign mmc
WHERE mmc.id = utr.campaign_id"""
)


def add_utm_stage_fields(env):
Expand Down
2 changes: 2 additions & 0 deletions odoo/addons/base/migrations/13.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
"account_voucher",
"account_voucher_line",
"lunch_order_line",
"mail_mass_mailing_campaign"
"slide_category",
"survey_page",
"account_analytic_tag_account_invoice_line_rel",
Expand All @@ -567,6 +568,7 @@
"sale_order_line_invoice_rel",
"summary_dept_rel",
"project_task_assign_so_line_rel",
"mail_mass_mailing_tag_rel",
)


Expand Down

0 comments on commit d9cdbf1

Please sign in to comment.