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 2d66c16ff69..14abd4bcb23 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 7f4d126d71d..e742e224a4c 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 028049ff17c..25525ef4fb3 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