Skip to content

Commit

Permalink
Merge pull request #4259 from Meisolsson/15.0-fix-payment-method-jour…
Browse files Browse the repository at this point in the history
…nal-acquirer

[15.0][FIX] payment: Wait for payment methods to be created
  • Loading branch information
pedrobaeza authored Dec 18, 2023
2 parents a5e43bf + d8e1f1c commit 5cb5e2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
32 changes: 32 additions & 0 deletions openupgrade_scripts/scripts/payment/15.0.2.0/end-migration.py
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 0 additions & 19 deletions openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5cb5e2e

Please sign in to comment.