Skip to content

Commit 8ff6a8d

Browse files
[FIX] payment: finish migration
1 parent 3687072 commit 8ff6a8d

File tree

4 files changed

+182
-27
lines changed

4 files changed

+182
-27
lines changed

openupgrade_scripts/scripts/payment/15.0.2.0/noupdate_changes.xml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,34 @@
2828
</record>
2929
<record id="payment_acquirer_authorize" model="payment.acquirer">
3030
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_maestro'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_discover'), ref('payment.payment_icon_cc_diners_club_intl'), ref('payment.payment_icon_cc_jcb'), ref('payment.payment_icon_cc_visa'), ])]"/>
31-
<field name="sequence"/>
31+
<!-- <field name="sequence"/>-->
3232
</record>
3333
<record id="payment_acquirer_buckaroo" model="payment.acquirer">
3434
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_bancontact'), ref('payment.payment_icon_cc_maestro'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_visa'), ref('payment.payment_icon_cc_american_express'), ])]"/>
3535
</record>
36+
<record id="payment_acquirer_ogone" model="payment.acquirer">
37+
<field name="description" type="html">
38+
<p>
39+
Ogone supports a wide range of payment methods: credit cards, debit cards, bank
40+
transfers, Bancontact, iDeal, Giropay.
41+
</p>
42+
<ul class="list-inline">
43+
<li class="list-inline-item"><i class="fa fa-check"/>Online Payment</li>
44+
<li class="list-inline-item"><i class="fa fa-check"/>Payment Status Tracking</li>
45+
<li class="list-inline-item"><i class="fa fa-check"/>Subscriptions</li>
46+
<li class="list-inline-item"><i class="fa fa-check"/>Save Cards</li>
47+
<li class="list-inline-item"><i class="fa fa-check"/>Embedded Credit Card Form</li>
48+
</ul>
49+
</field>
50+
<field name="display_as">Credit Card (powered by Ogone)</field>
51+
<field name="module_id" ref="base.module_payment_ogone"/>
52+
<field name="name">Ogone</field>
53+
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_ideal'), ref('payment.payment_icon_cc_bancontact'), ref('payment.payment_icon_cc_maestro'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_visa'), ])]"/>
54+
<!-- <field name="sequence"/>-->
55+
</record>
3656
<record id="payment_acquirer_paypal" model="payment.acquirer">
3757
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_maestro'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_discover'), ref('payment.payment_icon_cc_diners_club_intl'), ref('payment.payment_icon_cc_jcb'), ref('payment.payment_icon_cc_american_express'), ref('payment.payment_icon_cc_unionpay'), ref('payment.payment_icon_cc_visa'), ])]"/>
38-
<field name="sequence"/>
58+
<!-- <field name="sequence"/>-->
3959
</record>
4060
<record id="payment_acquirer_payulatam" model="payment.acquirer">
4161
<field name="description" type="html">
@@ -51,6 +71,18 @@
5171
</field>
5272
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_diners_club_intl'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_american_express'), ref('payment.payment_icon_cc_visa'), ref('payment.payment_icon_cc_codensa_easy_credit'), ])]"/>
5373
</record>
74+
<record id="payment_acquirer_payumoney" model="payment.acquirer">
75+
<field name="description" type="html">
76+
<p>
77+
PayUmoney is an online payments solutions company serving the Indian market.
78+
</p>
79+
<ul class="list-inline">
80+
<li class="list-inline-item"><i class="fa fa-check"/>Online Payment</li>
81+
<li class="list-inline-item"><i class="fa fa-check"/>Payment Status Tracking</li>
82+
</ul>
83+
</field>
84+
<field name="payment_icon_ids" eval="[(6, 0, [ ref('payment.payment_icon_cc_maestro'), ref('payment.payment_icon_cc_mastercard'), ref('payment.payment_icon_cc_american_express'), ref('payment.payment_icon_cc_visa'), ])]"/>
85+
</record>
5486
<record id="payment_acquirer_sepa_direct_debit" model="payment.acquirer">
5587
<field name="description" type="html">
5688
<p>
@@ -83,6 +115,9 @@
83115
<field name="pending_msg"/>
84116
<field name="sequence">30</field>
85117
</record>
118+
<record id="payment_token_billing_rule" model="ir.rule">
119+
<field name="name">Access every token</field>
120+
</record>
86121
<record id="payment_token_user_rule" model="ir.rule">
87122
<field name="name">Access only tokens belonging to commercial partner</field>
88123
</record>

openupgrade_scripts/scripts/payment/15.0.2.0/post-migration.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
from openupgradelib import openupgrade
22

33

4-
def convert_payment_acquirer_provider(env):
4+
def fill_payment_adquirer_allow_tokenization(env):
55
openupgrade.logged_query(
66
env.cr,
77
"""
8+
UPDATE payment_acquirer pa
9+
SET allow_tokenization = TRUE
10+
WHERE save_token IN ('always', 'ask')""",
11+
)
12+
13+
14+
def fill_payment_transaction_tokenize(env):
15+
openupgrade.logged_query(
16+
env.cr,
17+
"""
18+
UPDATE payment_transaction pt
19+
SET tokenize = TRUE
20+
WHERE type = 'form_save'""",
21+
)
22+
23+
24+
def convert_payment_acquirer_provider(env):
25+
openupgrade.logged_query(
26+
env.cr,
27+
f"""
828
UPDATE payment_acquirer
929
SET provider = 'none'
10-
WHERE provider = 'manual'""",
30+
WHERE {openupgrade.get_legacy_name('provider')} = 'manual'""",
1131
)
1232

1333

@@ -34,23 +54,51 @@ def fill_payment_transaction_partner_state_id(env):
3454
)
3555

3656

57+
def create_account_payment_method_line(env):
58+
# Create account payment method lines from account payment methods
59+
openupgrade.logged_query(
60+
env.cr,
61+
"""
62+
INSERT INTO account_payment_method_line (name, sequence,
63+
payment_method_id, journal_id, create_uid, write_uid,
64+
create_date, write_date)
65+
SELECT DISTINCT ON (apm.id, aj.id) apm.name, 10, apm.id, aj.id,
66+
apm.create_uid, apm.write_uid, apm.create_date, apm.write_date
67+
FROM account_payment_method apm
68+
JOIN payment_acquirer pa ON pa.provider = apm.code
69+
JOIN account_journal aj ON aj.type = 'bank' AND aj.id = pa.journal_id
70+
WHERE apm.code NOT IN ('manual', 'check_printing')
71+
""",
72+
)
73+
74+
3775
@openupgrade.migrate()
3876
def migrate(env, version):
77+
fill_payment_adquirer_allow_tokenization(env)
78+
fill_payment_transaction_tokenize(env)
3979
convert_payment_acquirer_provider(env)
4080
fill_payment_transaction_partner_state_id(env)
4181
fill_payment_transaction_last_state_change(env)
82+
create_account_payment_method_line(env)
4283
openupgrade.load_data(env.cr, "payment", "15.0.2.0/noupdate_changes.xml")
4384
openupgrade.delete_record_translations(
4485
env.cr,
4586
"payment",
4687
[
4788
"payment_acquirer_adyen",
4889
"payment_acquirer_alipay",
90+
"payment_acquirer_ogone",
4991
"payment_acquirer_payulatam",
92+
"payment_acquirer_payumoney",
5093
"payment_acquirer_sepa_direct_debit",
5194
"payment_acquirer_stripe",
95+
"payment_token_billing_rule",
5296
"payment_token_user_rule",
5397
"payment_transaction_billing_rule",
5498
"payment_transaction_user_rule",
5599
],
56100
)
101+
openupgrade.delete_records_safely_by_xml_id(
102+
env,
103+
["payment.payment_acquirer_odoo_by_adyen", "payment.default_acquirer_button"],
104+
)

openupgrade_scripts/scripts/payment/15.0.2.0/pre-migration.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from openupgradelib import openupgrade
22

3+
_copied_columns = {
4+
"payment_acquirer": [
5+
("provider", None, None),
6+
],
7+
}
8+
39
_renamed_fields = [
410
(
511
"payment.token",
@@ -19,34 +25,76 @@
1925
"payment_token_id",
2026
"token_id",
2127
),
28+
(
29+
"payment.acquirer",
30+
"payment_acquirer",
31+
"registration_view_template_id",
32+
"inline_form_view_id",
33+
),
34+
]
35+
36+
_renamed_xmlids = [
37+
("payment.payment_token_salesman_rule", "payment.payment_token_billing_rule"),
38+
("payment.payment_acquirer_ingenico", "payment.payment_acquirer_ogone"),
39+
("payment.payment_acquirer_payu", "payment.payment_acquirer_payumoney"),
2240
]
2341

2442

25-
def fast_fill_payment_token_name(env):
43+
def fill_payment_token_name(env):
44+
# field it's required now
2645
openupgrade.logged_query(
2746
env.cr,
2847
"""
2948
UPDATE payment_token
30-
SET name = 'XXXXXXXXXX????'
49+
SET name = 'XXXXXXXXXXXX????'
3150
WHERE name IS NULL""",
3251
)
3352

3453

35-
def fast_fill_payment_transaction_partner_id(env):
54+
def fill_payment_transaction_partner_id(env):
55+
# field it's required now
3656
openupgrade.logged_query(
3757
env.cr,
3858
"""
3959
UPDATE payment_transaction pt
40-
SET partner_id = ap.partner_id
60+
SET partner_id = COALESCE(ap.partner_id, rc.partner_id)
4161
FROM account_payment ap
42-
WHERE ap.partner_id IS NOT NULL
43-
AND pt.partner_id IS NULL
44-
AND ap.payment_transaction_id = pt.id""",
62+
JOIN account_move am ON ap.move_id = am.id
63+
JOIN account_journal aj ON am.journal_id = aj.id
64+
JOIN res_company rc ON aj.company_id = rc.id
65+
WHERE pt.partner_id IS NULL
66+
AND ap.payment_token_id = pt.token_id
67+
AND (ap.payment_transaction_id = pt.id OR pt.payment_id = ap.id)""",
68+
)
69+
openupgrade.logged_query(
70+
env.cr,
71+
"""
72+
UPDATE payment_transaction pt
73+
SET partner_id = COALESCE(ap.partner_id, rc.partner_id)
74+
FROM account_payment ap
75+
JOIN account_move am ON ap.move_id = am.id
76+
JOIN account_journal aj ON am.journal_id = aj.id
77+
JOIN res_company rc ON aj.company_id = rc.id
78+
WHERE pt.partner_id IS NULL
79+
AND (ap.payment_transaction_id = pt.id OR pt.payment_id = ap.id)""",
80+
)
81+
82+
83+
def delete_payment_adquirer_inline_form_view_id(env):
84+
openupgrade.logged_query(
85+
env.cr,
86+
"""
87+
UPDATE payment_acquirer pa
88+
SET inline_form_view_id = NULL
89+
WHERE payment_flow = 'form'""",
4590
)
4691

4792

4893
@openupgrade.migrate()
4994
def migrate(env, version):
95+
openupgrade.copy_columns(env.cr, _copied_columns)
5096
openupgrade.rename_fields(env, _renamed_fields)
51-
fast_fill_payment_token_name(env)
52-
fast_fill_payment_transaction_partner_id(env)
97+
openupgrade.rename_xmlids(env.cr, _renamed_xmlids)
98+
fill_payment_token_name(env)
99+
fill_payment_transaction_partner_id(env)
100+
delete_payment_adquirer_inline_form_view_id(env)

openupgrade_scripts/scripts/payment/15.0.2.0/upgrade_analysis_work.txt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
---Models in module 'payment'---
22
new model payment.refund.wizard [transient]
3-
# NOTHING TO DO: new model
3+
# NOTHING TO DO: new model: https://github.com/odoo/odoo/commit/e0233a1010618450cf53b997c50964bed2bb1b1a
44

55
---Fields in module 'payment'---
66
payment / account.payment / source_payment_id (many2one) : NEW relation: account.payment, isrelated: related, stored
7-
# DONE: pre-migration: create source_payment_id column
7+
# NOTHING TO DO: it's related to source_transaction_id and the new refund feature
88

99
payment / account.payment.method.line / payment_acquirer_id (many2one): NEW relation: payment.acquirer, isfunction: function, stored
10-
# NOTHING TO DO
10+
payment / payment.acquirer / journal_id (many2one) : not stored anymore
11+
payment / payment.acquirer / journal_id (many2one) : now a function
12+
# DONE: post-migration: payment.method.line records are populated for each payment method.
1113

1214
payment / payment.acquirer / _order : _order is now 'module_state, state desc, sequence, name' ('module_state, state, sequence, name')
13-
payment / payment.acquirer / allow_tokenization (boolean) : NEW
1415
payment / payment.acquirer / check_validity (boolean) : DEL
15-
payment / payment.acquirer / inline_form_view_id (many2one): NEW relation: ir.ui.view
16-
payment / payment.acquirer / journal_id (many2one) : not stored anymore
17-
payment / payment.acquirer / journal_id (many2one) : now a function
18-
payment / payment.acquirer / payment_flow (selection) : DEL required, selection_keys: ['form', 's2s'], req_default: function
1916
# NOTHING TO DO
2017

18+
payment / payment.acquirer / save_token (selection) : DEL selection_keys: ['always', 'ask', 'none']
19+
payment / payment.acquirer / allow_tokenization (boolean) : NEW
20+
DONE: post-migration: marked as true if 'always' or 'ask'
21+
22+
payment / payment.acquirer / payment_flow (selection) : DEL required, selection_keys: ['form', 's2s'], req_default: function
23+
# DONE: pre-migration: when payment_flow = form, inline_form_view_id is null
24+
25+
payment / payment.acquirer / registration_view_template_id (many2one): DEL relation: ir.ui.view
26+
payment / payment.acquirer / inline_form_view_id (many2one): NEW relation: ir.ui.view
27+
# DONE: pre-migration: renamed field.
28+
2129
payment / payment.acquirer / provider (selection) : selection_keys is now '['none']' ('['manual']')
2230
# DONE: post-migration: converted value of provider (manual -> none)
2331

2432
payment / payment.acquirer / qr_code (boolean) : module is now 'payment_transfer' ('payment')
2533
payment / payment.acquirer / redirect_form_view_id (many2one): NEW relation: ir.ui.view
26-
payment / payment.acquirer / registration_view_template_id (many2one): DEL relation: ir.ui.view
27-
payment / payment.acquirer / save_token (selection) : DEL selection_keys: ['always', 'ask', 'none']
2834
payment / payment.acquirer / support_authorization (boolean): NEW
2935
payment / payment.acquirer / support_fees_computation (boolean): NEW
3036
payment / payment.acquirer / support_refund (selection) : NEW selection_keys: ['full_only', 'partial']
@@ -49,7 +55,11 @@ payment / payment.token / provider (selection) : previo
4955

5056
payment / payment.transaction / callback_is_done (boolean) : NEW
5157
payment / payment.transaction / company_id (many2one) : NEW relation: res.company, isrelated: related, stored
58+
# NOTHING TO DO
59+
5260
payment / payment.transaction / date (datetime) : DEL
61+
# NOTHING TO DO: This date will be in the best case the same as write_date, and in the worst, the create_date, so nothing relevant.
62+
5363
payment / payment.transaction / html_3ds (char) : DEL
5464
# NOTHING TO DO
5565

@@ -82,7 +92,7 @@ payment / payment.transaction / token_id (many2one) : NEW re
8292

8393
payment / payment.transaction / tokenize (boolean) : NEW
8494
payment / payment.transaction / type (selection) : DEL required, selection_keys: ['form', 'form_save', 'server2server', 'validation'], req_default: function
85-
# NOTHING TO DO
95+
# DONE: post-migration: marked as true if 'form_save'
8696

8797
---XML records in module 'payment'---
8898
DEL account.payment.method: payment.account_payment_method_electronic_in
@@ -106,10 +116,14 @@ DEL ir.model.access: payment.payment_method_portal
106116
DEL ir.model.access: payment.payment_method_system
107117
DEL ir.model.access: payment.payment_method_user
108118
NEW ir.rule: payment.payment_acquirer_company_rule (noupdate)
109-
NEW ir.rule: payment.payment_token_billing_rule (noupdate)
110119
NEW ir.rule: payment.payment_token_company_rule (noupdate)
111120
NEW ir.rule: payment.transaction_company_rule (noupdate)
121+
# NOTHING TO DO
122+
123+
NEW ir.rule: payment.payment_token_billing_rule (noupdate)
112124
DEL ir.rule: payment.payment_token_salesman_rule (noupdate)
125+
# DONE: pre-migration: renamed xmlid
126+
113127
NEW ir.ui.view: payment.checkout
114128
NEW ir.ui.view: payment.footer
115129
NEW ir.ui.view: payment.icon_list
@@ -141,7 +155,11 @@ DEL ir.ui.view: payment.acquirer_list
141155
DEL ir.ui.view: payment.acquirer_search
142156
DEL ir.ui.view: payment.assets_backend
143157
DEL ir.ui.view: payment.assets_frontend
158+
# NOTHING TO DO
159+
144160
DEL ir.ui.view: payment.default_acquirer_button (noupdate)
161+
# DONE: safely deleted xmlid
162+
145163
DEL ir.ui.view: payment.pay_methods
146164
DEL ir.ui.view: payment.payment_confirmation_status
147165
DEL ir.ui.view: payment.payment_icon_form_view
@@ -156,12 +174,18 @@ DEL ir.ui.view: payment.transaction_list
156174
DEL ir.ui.view: payment.transaction_view_kanban
157175
DEL ir.ui.view: payment_fix_register_token.view_account_payment_register_form_inherit_payment
158176
NEW payment.acquirer: payment.payment_acquirer_mollie (noupdate)
177+
NEW payment.acquirer: payment.payment_acquirer_test [renamed from payment_test module] (noupdate)
178+
# NOTHING TO DO
179+
180+
DEL payment.acquirer: payment.payment_acquirer_odoo_by_adyen (noupdate)
181+
# DONE: post-migration: safely deleted xmlid
182+
159183
NEW payment.acquirer: payment.payment_acquirer_ogone (noupdate)
160184
NEW payment.acquirer: payment.payment_acquirer_payumoney (noupdate)
161-
NEW payment.acquirer: payment.payment_acquirer_test [renamed from payment_test module] (noupdate)
162185
DEL payment.acquirer: payment.payment_acquirer_ingenico (noupdate)
163-
DEL payment.acquirer: payment.payment_acquirer_odoo_by_adyen (noupdate)
164186
DEL payment.acquirer: payment.payment_acquirer_payu (noupdate)
187+
# DONE: pre-migration: renamed xmlids
188+
165189
NEW payment.icon: payment.payment_icon_apple_pay
166190
NEW payment.icon: payment.payment_icon_kbc
167191
NEW payment.icon: payment.payment_icon_paypal

0 commit comments

Comments
 (0)