Skip to content

Commit 9dae225

Browse files
sbidoulMiquelRForgeFlow
authored andcommitted
[FIX] account: reversed_entry_id migration was reversed
1 parent fb040b4 commit 9dae225

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

addons/account/migrations/13.0.1.1/openupgrade_analysis_work.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ account / account.move / matched_percentage (float) : DEL
331331
account / account.move / reverse_entry_id (many2one) : DEL relation: account.move
332332
account / account.move / reversed_entry_id (many2one) : NEW relation: account.move
333333
account / account.invoice / refund_invoice_id (many2one) : DEL relation: account.invoice
334-
# DONE: pre-migration: renamed fields
335-
# DONE: post-migration: used refund_invoice_id to fill reversed_entry_id in case is empty
334+
# DONE: pre-migration: lift FK constraint in reverse_entry_id
335+
# DONE: post-migration: used refund_invoice_id to fill reverse_entry_id in case is empty (for invoices transformed to moves)
336+
# DONE: post-migration: used reverse_entry_id to fill reversed_entry_id in case is empty
336337

337338
account / account.move / tax_type_domain (char) : DEL
338339
# NOTHING TO DO: renamed to invoice_filter_type_domain, but still is non stored

addons/account/migrations/13.0.1.1/post-migration.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,24 @@ def migration_voucher_moves(env):
581581

582582

583583
def fill_account_move_reversed_entry_id(env):
584+
# copy refund_invoice_id to reverse_entry_id
584585
openupgrade.logged_query(
585586
env.cr, """
586587
UPDATE account_move am
587-
SET reversed_entry_id = am2.id
588+
SET reverse_entry_id = am2.id
588589
FROM account_invoice ai
589590
JOIN account_invoice ai2 ON ai.refund_invoice_id = ai2.id
590591
JOIN account_move am2 ON am2.old_invoice_id = ai2.id
591-
WHERE am.reversed_entry_id IS NULL AND am.old_invoice_id = ai.id"""
592+
WHERE am.reverse_entry_id IS NULL AND am.old_invoice_id = ai.id"""
593+
)
594+
# copy reverse_entry_id to reversed_entry_id (the relation is reversed in 13.0)
595+
openupgrade.logged_query(
596+
env.cr, """
597+
UPDATE account_move am
598+
SET reversed_entry_id = am2.id
599+
FROM account_move am2
600+
WHERE am.reversed_entry_id IS NULL AND am2.reverse_entry_id = am.id
601+
"""
592602
)
593603

594604

addons/account/migrations/13.0.1.1/pre-migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
_field_renames = [
3636
('account.move', 'account_move', 'amount', 'amount_total'),
37-
('account.move', 'account_move', 'reverse_entry_id', 'reversed_entry_id'),
3837
]
3938

4039
_field_sale_renames = [
@@ -340,6 +339,7 @@ def migrate(env, version):
340339
fill_account_move_line(env)
341340
create_res_partner_ranks(env)
342341
delete_fk_constraints(env)
342+
openupgrade.lift_constraints(env.cr, "account_move", "reverse_entry_id")
343343
fill_account_move_commercial_partner_id(env)
344344
set_account_move_currency_id_required(env)
345345
add_helper_invoice_move_rel(env)

0 commit comments

Comments
 (0)