-
-
Notifications
You must be signed in to change notification settings - Fork 827
[19.0][OU-ADD] payment_redsys: Migration scripts #5894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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", | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I tested the migration against an existing v18 database and found a couple of issues:
Using direct SQL to populate |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.