From ff2ee1c13c9b2e7bde1261f03de8a7b1e7a8ed2e Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Thu, 18 Jul 2024 11:23:18 +0200 Subject: [PATCH] [OU-FIX] sale_loyalty: Remove script that removes constraint This script is not necessary since both the table and the constraint are new in v16, it is only necessary to apply this restriction to the data dump in the new table by adding a condition that contemplates it. --- .../sale_loyalty/16.0.1.0/post-migration.py | 22 +++++++++++-------- .../sale_loyalty/16.0.1.0/pre-migration.py | 8 ------- .../16.0.1.0/upgrade_analysis_work.txt | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/post-migration.py b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/post-migration.py index 2d66c16ff69f..14abd4bcb235 100644 --- a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/post-migration.py @@ -80,15 +80,19 @@ def _generate_sale_order_coupon_points(env): coupon_id, order_id, points, create_uid, write_uid, create_date, write_date ) SELECT - id AS coupon_id, - order_id, - points, - create_uid, - write_uid, - create_date, - write_date - FROM loyalty_card - WHERE order_id IS NOT NULL; + lc.id AS coupon_id, + lc.order_id, + lc.points, + lc.create_uid, + lc.write_uid, + lc.create_date, + lc.write_date + FROM loyalty_card lc + LEFT JOIN sale_order_coupon_points socp + ON lc.order_id = socp.order_id + AND lc.id = socp.coupon_id + WHERE lc.order_id IS NOT NULL + AND socp.id IS NULL """, ) diff --git a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/pre-migration.py index 7f4d126d71dd..e742e224a4c3 100644 --- a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/pre-migration.py +++ b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/pre-migration.py @@ -138,13 +138,6 @@ def update_sale_order_line_data(env): ) -def delete_sql_constraints(env): - # Delete constraints to recreate it - openupgrade.delete_sql_constraint_safely( - env, "sale_loyalty", "sale_order_coupon_points", "order_coupon_unique" - ) - - def update_template_keys(env): """Update template keys of the merged sale_gift_card module in loyalty_sale""" openupgrade.logged_query( @@ -178,5 +171,4 @@ def migrate(env, version): openupgrade.rename_xmlids(env.cr, _xmlids_renames) update_loyalty_program_data(env) update_sale_order_line_data(env) - delete_sql_constraints(env) update_template_keys(env) diff --git a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/upgrade_analysis_work.txt index 028049ff17cf..25525ef4fb30 100644 --- a/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/sale_loyalty/16.0.1.0/upgrade_analysis_work.txt @@ -91,7 +91,7 @@ DEL ir.model.access: sale_gift_card.access_gift_card_sales # NOTHING TO DO NEW ir.model.constraint: sale_loyalty.constraint_sale_order_coupon_points_order_coupon_unique -# DONE pre-migration: safely delete constraint to recreate it +# NOTHING TO DO DEL ir.rule: sale_coupon.sale_coupon_apply_code_rule (noupdate) # DONE: post-migration: safely deleted xmlid