[19.0][OU-ADD] payment_redsys: Migration scripts - #5894
Conversation
|
/ocabot migration payment_redsys Depends on :
|
84c6127 to
45aaae2
Compare
|
|
||
| PAY_METHOD_MAPPING = { | ||
| "T": "payment.payment_method_card", | ||
| "z": " payment.payment_method_bizum", |
There was a problem hiding this comment.
| "z": " payment.payment_method_bizum", | |
| "z": "payment.payment_method_bizum", |
| provider = env["payment.provider"].browse(provider_id) | ||
| provider.payment_method_ids = [ | ||
| Command.set(env.ref(PAY_METHOD_MAPPING[redsys_pay_method]).ids) | ||
| ] |
There was a problem hiding this comment.
| 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:
-
Stray whitespace in
PAY_METHOD_MAPPING
There is a leading tab character (\t) beforepayment.payment_method_bizumin the mapping ("z": "\tpayment.payment_method_bizum"). As a result,env.ref()cannot resolve the Bizum payment method. -
ORM constraint triggered during migration
Updatingprovider.payment_method_idsthrough the ORM triggers_check_required_if_provider(). If the database contains legacy or test Redsys providers withoutredsys_merchant_codeorredsys_secret_keyconfigured, thewrite()call raises aValidationErrorand 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.
| env, | ||
| ( | ||
| "payment.provider", | ||
| "payment_provider", | ||
| "redsys_terminal", | ||
| "redsys_merchant_terminal", | ||
| ), | ||
| ) |
There was a problem hiding this comment.
| env, | |
| ( | |
| "payment.provider", | |
| "payment_provider", | |
| "redsys_terminal", | |
| "redsys_merchant_terminal", | |
| ), | |
| ) | |
| env, | |
| [ | |
| ( | |
| "payment.provider", | |
| "payment_provider", | |
| "redsys_terminal", | |
| "redsys_merchant_terminal", | |
| ), | |
| ], | |
| ) |
|
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. |
|
In a real production database, the merchant credentials should already be configured, so the ORM constraint shouldn't be an issue. |
|
Yes, because the OCA module already makes them mandatory. |
@Tecnativa