forked from Viindoo/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] payment*: migration script (Viindoo#253)
Co-authored-by: Roy Le <[email protected]>
- Loading branch information
1 parent
e6c8f74
commit 4fb700e
Showing
29 changed files
with
581 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
openupgrade_scripts/scripts/account_check_printing/15.0.1.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
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, payment_method_id, journal_id) | ||
SELECT apm.name, apm.id, aj.id | ||
FROM account_payment_method apm | ||
JOIN account_journal aj ON aj.type = 'bank' | ||
WHERE apm.code = 'check_printing' | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_create_account_payment_method_line(env) |
58 changes: 58 additions & 0 deletions
58
openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def convert_payment_acquirer_provider(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE payment_acquirer | ||
SET provider = 'none' | ||
WHERE provider = 'manual'""", | ||
) | ||
|
||
|
||
def fill_payment_transaction_last_state_change(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE payment_transaction | ||
SET last_state_change = write_date | ||
WHERE last_state_change IS NULL | ||
""", | ||
) | ||
|
||
|
||
def fill_payment_transaction_partner_state_id(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE payment_transaction pt | ||
SET partner_state_id = rp.state_id | ||
FROM res_partner rp | ||
WHERE rp.id = pt.partner_id | ||
AND rp.state_id IS NOT NULL | ||
AND partner_state_id IS NULL | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.load_data(env.cr, "payment", "15.0.2.0/noupdate_changes.xml") | ||
openupgrade.delete_record_translations( | ||
env.cr, | ||
"payment", | ||
[ | ||
"payment_acquirer_adyen", | ||
"payment_acquirer_alipay", | ||
"payment_acquirer_payulatam", | ||
"payment_acquirer_sepa_direct_debit", | ||
"payment_acquirer_stripe", | ||
"payment_token_user_rule", | ||
"payment_transaction_billing_rule", | ||
"payment_transaction_user_rule", | ||
], | ||
) | ||
convert_payment_acquirer_provider(env) | ||
fill_payment_transaction_partner_state_id(env) | ||
fill_payment_transaction_last_state_change(env) |
54 changes: 54 additions & 0 deletions
54
openupgrade_scripts/scripts/payment/15.0.2.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def fast_fill_payment_token_name(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE payment_token | ||
SET name = 'XXXXXXXXXX????' | ||
WHERE name IS NULL""", | ||
) | ||
|
||
|
||
def fast_fill_payment_transaction_partner_id(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE payment_transaction pt | ||
SET partner_id = ap.partner_id | ||
FROM account_payment ap | ||
WHERE ap.partner_id IS NOT NULL | ||
AND pt.partner_id IS NULL | ||
AND ap.payment_transaction_id = pt.id | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
fast_fill_payment_token_name(env) | ||
openupgrade.rename_fields( | ||
env, | ||
[ | ||
( | ||
"payment.token", | ||
"payment_token", | ||
"payment_ids", | ||
"transaction_ids", | ||
), | ||
( | ||
"payment.transaction", | ||
"payment_transaction", | ||
"is_processed", | ||
"is_post_processed", | ||
), | ||
( | ||
"payment.transaction", | ||
"payment_transaction", | ||
"payment_token_id", | ||
"token_id", | ||
), | ||
], | ||
) | ||
fast_fill_payment_transaction_partner_id(env) |
Oops, something went wrong.