Skip to content

[19.0][OU-ADD] payment_redsys: Migration scripts - #5894

Merged
pedrobaeza merged 1 commit into
OCA:19.0from
Tecnativa:19.0-ou_add-payment_redsys
Aug 7, 2026
Merged

pedrobaeza merged 1 commit into
OCA:19.0from
Tecnativa:19.0-ou_add-payment_redsys

Conversation

@pedrobaeza

Copy link
Copy Markdown
Member

@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels Aug 6, 2026
@pedrobaeza

pedrobaeza commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

/ocabot migration payment_redsys

Depends on :

@OCA-git-bot OCA-git-bot added this to the 19.0 milestone Aug 6, 2026
@pedrobaeza
pedrobaeza force-pushed the 19.0-ou_add-payment_redsys branch from 84c6127 to 45aaae2 Compare August 6, 2026 16:30
@pedrobaeza
pedrobaeza merged commit cc5a1be into OCA:19.0 Aug 7, 2026
7 checks passed
@pedrobaeza
pedrobaeza deleted the 19.0-ou_add-payment_redsys branch August 7, 2026 06:55

PAY_METHOD_MAPPING = {
"T": "payment.payment_method_card",
"z": " payment.payment_method_bizum",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"z": " payment.payment_method_bizum",
"z": "payment.payment_method_bizum",

Comment on lines +29 to +32
provider = env["payment.provider"].browse(provider_id)
provider.payment_method_ids = [
Command.set(env.ref(PAY_METHOD_MAPPING[redsys_pay_method]).ids)
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provider = env["payment.provider"].browse(provider_id)
provider.payment_method_ids = [
Command.set(env.ref(PAY_METHOD_MAPPING[redsys_pay_method]).ids)
]
xml_id = PAY_METHOD_MAPPING.get(redsys_pay_method)
if not xml_id:
continue
method = env.ref(xml_id, raise_if_not_found=False)
if method:
env.cr.execute(
"""
INSERT INTO payment_method_payment_provider_rel
(payment_provider_id, payment_method_id)
VALUES (%s, %s)
ON CONFLICT DO NOTHING
""",
(provider_id, method.id),
)

I tested the migration against an existing v18 database and found a couple of issues:

  1. Stray whitespace in PAY_METHOD_MAPPING
    There is a leading tab character (\t) before payment.payment_method_bizum in the mapping ("z": "\tpayment.payment_method_bizum"). As a result, env.ref() cannot resolve the Bizum payment method.

  2. ORM constraint triggered during migration
    Updating provider.payment_method_ids through the ORM triggers _check_required_if_provider(). If the database contains legacy or test Redsys providers without redsys_merchant_code or redsys_secret_key configured, the write() call raises a ValidationError and the migration fails.

Using direct SQL to populate payment_method_payment_provider_rel avoids triggering ORM constraints while safely creating the required many2many records during the migration.

Comment on lines +10 to +17
env,
(
"payment.provider",
"payment_provider",
"redsys_terminal",
"redsys_merchant_terminal",
),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
env,
(
"payment.provider",
"payment_provider",
"redsys_terminal",
"redsys_merchant_terminal",
),
)
env,
[
(
"payment.provider",
"payment_provider",
"redsys_terminal",
"redsys_merchant_terminal",
),
],
)

@pedrobaeza

Copy link
Copy Markdown
Member Author

Thanks, @BhaveshHeliconia

I have made direct commit to fix the typos (I expected the CI to detect at least the syntax one, but it's not executed as the DB doesn't contain the OCA module). About the constraint, I expect to fail if the mapping doesn't return any value, as that cases are not covered. They shouldn't be selected anyway in real cases.

@BhaveshHeliconia

Copy link
Copy Markdown
Contributor

In a real production database, the merchant credentials should already be configured, so the ORM constraint shouldn't be an issue.

@pedrobaeza

Copy link
Copy Markdown
Member Author

Yes, because the OCA module already makes them mandatory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants