mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #320 from hbrunn/9.0-account_payment_mode-migrate_in_init_hook
[ADD] account_payment_mode: Migrate from 8.0 if possible in init_hook
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
from .hooks import pre_init_hook
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
'views/account_journal.xml',
|
||||
],
|
||||
'demo': ['demo/payment_demo.xml'],
|
||||
'pre_init_hook': 'pre_init_hook',
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
26
account_payment_mode/hooks.py
Normal file
26
account_payment_mode/hooks.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Therp BV <http://therp.nl>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
def pre_init_hook(cr):
|
||||
migrate_from_8(cr)
|
||||
|
||||
|
||||
def migrate_from_8(cr):
|
||||
"""If we're installed on a database which has the payment_mode table
|
||||
from 8.0, move its table so that we use the already existing modes"""
|
||||
cr.execute("SELECT 1 FROM pg_class WHERE relname = 'payment_mode'")
|
||||
if not cr.fetchone():
|
||||
return
|
||||
try:
|
||||
from openupgradelib.openupgrade import rename_models
|
||||
rename_models(cr, [('payment.mode', 'account.payment.mode')])
|
||||
except ImportError:
|
||||
cr.execute('ALTER TABLE payment_mode RENAME TO account_payment_mode')
|
||||
cr.execute('ALTER SEQUENCE payment_mode_id_seq '
|
||||
'RENAME TO account_payment_mode_id_seq')
|
||||
cr.execute(
|
||||
'ALTER TABLE account_payment_mode '
|
||||
'RENAME COLUMN journal TO fixed_journal_id'
|
||||
)
|
||||
Reference in New Issue
Block a user