From aabdb35fbbd9076f5d8a163834bebe840dfe4d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 28 Jul 2024 16:16:03 +0200 Subject: [PATCH 1/2] [FIX] account: reversed_entry_id migration was reversed --- addons/account/migrations/13.0.1.1/post-migration.py | 7 +++---- addons/account/migrations/13.0.1.1/pre-migration.py | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/account/migrations/13.0.1.1/post-migration.py b/addons/account/migrations/13.0.1.1/post-migration.py index 38e1561e7eb..94bb2f69097 100644 --- a/addons/account/migrations/13.0.1.1/post-migration.py +++ b/addons/account/migrations/13.0.1.1/post-migration.py @@ -585,10 +585,9 @@ def fill_account_move_reversed_entry_id(env): env.cr, """ UPDATE account_move am SET reversed_entry_id = am2.id - FROM account_invoice ai - JOIN account_invoice ai2 ON ai.refund_invoice_id = ai2.id - JOIN account_move am2 ON am2.old_invoice_id = ai2.id - WHERE am.reversed_entry_id IS NULL AND am.old_invoice_id = ai.id""" + FROM account_move am2 + WHERE am.reversed_entry_id IS NULL AND am2.reverse_entry_id = am.id + """ ) diff --git a/addons/account/migrations/13.0.1.1/pre-migration.py b/addons/account/migrations/13.0.1.1/pre-migration.py index e57abf7cdd6..ab8c9766389 100644 --- a/addons/account/migrations/13.0.1.1/pre-migration.py +++ b/addons/account/migrations/13.0.1.1/pre-migration.py @@ -34,7 +34,6 @@ _field_renames = [ ('account.move', 'account_move', 'amount', 'amount_total'), - ('account.move', 'account_move', 'reverse_entry_id', 'reversed_entry_id'), ] _field_sale_renames = [ From 747ee5577bfc2453af2f4615528349b3973d8b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Tue, 30 Jul 2024 12:52:49 +0200 Subject: [PATCH 2/2] [IMP] account: preserve refund_invoice_id as reversed_entry_id --- addons/account/migrations/13.0.1.1/post-migration.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/account/migrations/13.0.1.1/post-migration.py b/addons/account/migrations/13.0.1.1/post-migration.py index 94bb2f69097..e277afbda05 100644 --- a/addons/account/migrations/13.0.1.1/post-migration.py +++ b/addons/account/migrations/13.0.1.1/post-migration.py @@ -581,6 +581,17 @@ def migration_voucher_moves(env): def fill_account_move_reversed_entry_id(env): + # copy refund_invoice_id to reverse_entry_id + openupgrade.logged_query( + env.cr, """ + UPDATE account_move am + SET reverse_entry_id = am2.id + FROM account_invoice ai + JOIN account_invoice ai2 ON ai.refund_invoice_id = ai2.id + JOIN account_move am2 ON am2.old_invoice_id = ai2.id + WHERE am.reverse_entry_id IS NULL AND am.old_invoice_id = ai.id""" + ) + # copy reverse_entry_id to reversed_entry_id (the relation is reversed in 13.0) openupgrade.logged_query( env.cr, """ UPDATE account_move am