Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |del| payment_razorpay_oauth | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |new| payment_redsys | | |
| |new| payment_redsys |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| payment_stripe |Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2026 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

from odoo import Command

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",

}


def _adjust_payment_methods(env):
"""On the OCA module, done before the payment refactoring, the payment method of
Redsys was defined through a specific field, instead of using payment_method_ids
field.

We need to convert existing payment providers to this new way, as the Odoo module
handles it through it.
"""
if not openupgrade.column_exists(env.cr, "payment_provider", "redsys_pay_method"):
return # No previous OCA module installed
env.cr.execute(
"SELECT id, redsys_pay_method FROM payment_provider "
"WHERE code='redsys' AND redsys_pay_method IS NOT NULL"
)
for provider_id, redsys_pay_method in env.cr.fetchall():
provider = env["payment.provider"].browse(provider_id)
provider.payment_method_ids = [
Command.set(env.ref(PAY_METHOD_MAPPING[redsys_pay_method]).ids)
]
Comment on lines +29 to +32

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.



@openupgrade.migrate()
def migrate(env, version):
_adjust_payment_methods(env)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2026 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(
env,
(
"payment.provider",
"payment_provider",
"redsys_terminal",
"redsys_merchant_terminal",
),
)
Comment on lines +10 to +17

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",
),
],
)

openupgrade.rename_xmlids(
env.cr,
[
(
"payment_redsys.provider_form_redsys",
"payment_redsys.payment_provider_form",
),
("payment_redsys.redsys_form", "payment_redsys.redirect_form"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---Models in module 'payment_redsys'---
---Fields in module 'payment_redsys'---
payment_redsys / payment.provider / code (False) : NEW selection_keys: ['adyen', 'aps', 'asiapay', 'authorize', 'buckaroo', 'custom', 'demo', 'dpo', 'ecpay', 'flutterwave', 'iyzico', 'mercado_pago', 'mollie', 'none', 'nuvei', 'paymob', 'paypal', 'payu', 'razorpay', 'redsys'], mode: modify
# NOTHING TO DO: the value is the same for the OCA and this one

payment_redsys / payment.provider / redsys_merchant_code (char) : NEW
payment_redsys / payment.provider / redsys_secret_key (char) : NEW
# NOTHING TO DO: Same field name

payment_redsys / payment.provider / redsys_merchant_terminal (char): NEW
# DONE: pre-migration: Rename field

---XML records in module 'payment_redsys'---
NEW ir.ui.view: payment_redsys.payment_provider_form
NEW ir.ui.view: payment_redsys.redirect_form
# DONE: pre-migration: Rename OCA XML-IDs
Loading