Merge lp:~therp-nl/banking-addons/6.0-support_v5_migration into lp:banking-addons/6.0

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 79
Proposed branch: lp:~therp-nl/banking-addons/6.0-support_v5_migration
Merge into: lp:banking-addons/6.0
Diff against target: 113 lines (+95/-1)
2 files modified
account_banking/__terp__.py (+1/-1)
account_banking/migrations/0.1.78/pre-move_payment_type.py (+94/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/6.0-support_v5_migration
Reviewer Review Type Date Requested Status
Banking Addons Core Editors Pending
Review via email: mp+111743@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_banking/__terp__.py'
--- account_banking/__terp__.py 2011-07-21 11:30:59 +0000
+++ account_banking/__terp__.py 2012-06-24 14:42:18 +0000
@@ -25,7 +25,7 @@
25##############################################################################25##############################################################################
26{26{
27 'name': 'Account Banking',27 'name': 'Account Banking',
28 'version': '0.1.62',28 'version': '0.1.78',
29 'license': 'GPL-3',29 'license': 'GPL-3',
30 'author': 'EduSense BV',30 'author': 'EduSense BV',
31 'website': 'http://www.edusense.nl',31 'website': 'http://www.edusense.nl',
3232
=== added directory 'account_banking/migrations'
=== added directory 'account_banking/migrations/0.1.78'
=== added file 'account_banking/migrations/0.1.78/pre-move_payment_type.py'
--- account_banking/migrations/0.1.78/pre-move_payment_type.py 1970-01-01 00:00:00 +0000
+++ account_banking/migrations/0.1.78/pre-move_payment_type.py 2012-06-24 14:42:18 +0000
@@ -0,0 +1,94 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2011-2012 Therp BV (<http://therp.nl>)
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import logging
23logger = logging.getLogger('Migration: account_banking')
24
25# methods from openupgrade. Need a proper python library
26def table_exists(cr, table):
27 """ Check whether a certain table or view exists """
28 cr.execute(
29 'SELECT count(relname) FROM pg_class WHERE relname = %s',
30 (table,))
31 return cr.fetchone()[0] == 1
32
33def rename_models(cr, model_spec):
34 """
35 Rename models. Typically called in the pre script.
36 :param model_spec: a list of tuples (old model name, new model name).
37
38 Use case: if a model changes name, but still implements equivalent
39 functionality you will want to update references in for instance
40 relation fields.
41
42 """
43 for (old, new) in model_spec:
44 logger.info("model %s: renaming to %s",
45 old, new)
46 cr.execute('UPDATE ir_model_fields SET relation = %s '
47 'WHERE relation = %s', (new, old,))
48 cr.execute('UPDATE ir_model_data SET model = %s '
49 'WHERE model = %s', (new, old,))
50
51def rename_tables(cr, table_spec):
52 """
53 Rename tables. Typically called in the pre script.
54 This function also renames the id sequence if it exists and if it is
55 not modified in the same run.
56
57 :param table_spec: a list of tuples (old table name, new table name).
58
59 """
60 # Append id sequences
61 to_rename = [x[0] for x in table_spec]
62 for old, new in list(table_spec):
63 if (table_exists(cr, old + '_id_seq') and
64 old + '_id_seq' not in to_rename):
65 table_spec.append((old + '_id_seq', new + '_id_seq'))
66 for (old, new) in table_spec:
67 logger.info("table %s: renaming to %s",
68 old, new)
69 cr.execute('ALTER TABLE "%s" RENAME TO "%s"' % (old, new,))
70
71def rename_columns(cr, column_spec):
72 """
73 Rename table columns. Typically called in the pre script.
74
75 :param column_spec: a hash with table keys, with lists of tuples as values. \
76 Tuples consist of (old_name, new_name).
77
78 """
79 for table in column_spec.keys():
80 for (old, new) in column_spec[table]:
81 logger.info("table %s, column %s: renaming to %s",
82 table, old, new)
83 cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (table, old, new,))
84
85def migrate(cr, version):
86 """
87 Preserve references to Payment Type resources after renaming to
88 Payment Mode Type
89 """
90 if version and version.startswith('5.0.'):
91 rename_models(cr, [['payment.type', 'payment.mode.type']])
92 rename_tables(cr, [['payment_type', 'payment_mode_type']])
93 rename_columns(cr, {'account_bank_statement_line': [
94 ('reconcile_id', 'legacy_bank_statement_reconcile_id')]})

Subscribers

People subscribed via source and target branches