From d8e1f1c653ca5a9c44afe8647cf791c355ae5392 Mon Sep 17 00:00:00 2001 From: Henrik Olsson Date: Mon, 18 Dec 2023 07:11:13 +0100 Subject: [PATCH] [FIX] payment: Delay payment method line migration Since other modules create account.payment.method in this migration we need to wait for them before finding all payment methods and and connecting them to the journal and acquirer. --- .../scripts/payment/15.0.2.0/end-migration.py | 32 +++++++++++++++++++ .../payment/15.0.2.0/post-migration.py | 19 ----------- 2 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 openupgrade_scripts/scripts/payment/15.0.2.0/end-migration.py diff --git a/openupgrade_scripts/scripts/payment/15.0.2.0/end-migration.py b/openupgrade_scripts/scripts/payment/15.0.2.0/end-migration.py new file mode 100644 index 000000000000..bd2899d4bc6c --- /dev/null +++ b/openupgrade_scripts/scripts/payment/15.0.2.0/end-migration.py @@ -0,0 +1,32 @@ +from openupgradelib import openupgrade + + +def create_account_payment_method_line(env): + """ + Create account payment method lines from account payment methods + + This is placed in 'end-' instead of 'post-' because we need to wait for + other modules to update. For instance payment_adyen creates its + 'account.payment.method' object in XML and that is execute after this + module has been migrated. But running this at 'end-' means that we will + have that updated data. + """ + openupgrade.logged_query( + env.cr, + """ + INSERT INTO account_payment_method_line (name, sequence, + payment_method_id, journal_id, create_uid, write_uid, + create_date, write_date) + SELECT DISTINCT ON (apm.id, aj.id) apm.name, 10, apm.id, aj.id, + apm.create_uid, apm.write_uid, apm.create_date, apm.write_date + FROM account_payment_method apm + JOIN payment_acquirer pa ON pa.provider = apm.code + JOIN account_journal aj ON aj.type = 'bank' AND aj.id = pa.journal_id + WHERE apm.code NOT IN ('manual', 'check_printing') + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + create_account_payment_method_line(env) diff --git a/openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py b/openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py index 9c09cd57bd16..e516955f27e6 100644 --- a/openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py +++ b/openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py @@ -44,31 +44,12 @@ def fill_payment_transaction_partner_state_id(env): ) -def create_account_payment_method_line(env): - # Create account payment method lines from account payment methods - openupgrade.logged_query( - env.cr, - """ - INSERT INTO account_payment_method_line (name, sequence, - payment_method_id, journal_id, create_uid, write_uid, - create_date, write_date) - SELECT DISTINCT ON (apm.id, aj.id) apm.name, 10, apm.id, aj.id, - apm.create_uid, apm.write_uid, apm.create_date, apm.write_date - FROM account_payment_method apm - JOIN payment_acquirer pa ON pa.provider = apm.code - JOIN account_journal aj ON aj.type = 'bank' AND aj.id = pa.journal_id - WHERE apm.code NOT IN ('manual', 'check_printing') - """, - ) - - @openupgrade.migrate() def migrate(env, version): fill_payment_adquirer_allow_tokenization(env) fill_payment_transaction_tokenize(env) fill_payment_transaction_partner_state_id(env) fill_payment_transaction_last_state_change(env) - create_account_payment_method_line(env) openupgrade.load_data(env.cr, "payment", "15.0.2.0/noupdate_changes.xml") openupgrade.delete_record_translations( env.cr,