banking-addons-team team mailing list archive
-
banking-addons-team team
-
Mailing list archive
-
Message #00114
[Merge] lp:~therp-nl/banking-addons/6.0-support_v5_migration into lp:banking-addons/6.0
Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/banking-addons/6.0-support_v5_migration into lp:banking-addons/6.0.
Requested reviews:
Banking Addons Team (banking-addons-team)
For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/6.0-support_v5_migration/+merge/111743
--
https://code.launchpad.net/~therp-nl/banking-addons/6.0-support_v5_migration/+merge/111743
Your team Banking Addons Team is requested to review the proposed merge of lp:~therp-nl/banking-addons/6.0-support_v5_migration into lp:banking-addons/6.0.
=== 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 @@
##############################################################################
{
'name': 'Account Banking',
- 'version': '0.1.62',
+ 'version': '0.1.78',
'license': 'GPL-3',
'author': 'EduSense BV',
'website': 'http://www.edusense.nl',
=== 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 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# This module copyright (C) 2011-2012 Therp BV (<http://therp.nl>)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import logging
+logger = logging.getLogger('Migration: account_banking')
+
+# methods from openupgrade. Need a proper python library
+def table_exists(cr, table):
+ """ Check whether a certain table or view exists """
+ cr.execute(
+ 'SELECT count(relname) FROM pg_class WHERE relname = %s',
+ (table,))
+ return cr.fetchone()[0] == 1
+
+def rename_models(cr, model_spec):
+ """
+ Rename models. Typically called in the pre script.
+ :param model_spec: a list of tuples (old model name, new model name).
+
+ Use case: if a model changes name, but still implements equivalent
+ functionality you will want to update references in for instance
+ relation fields.
+
+ """
+ for (old, new) in model_spec:
+ logger.info("model %s: renaming to %s",
+ old, new)
+ cr.execute('UPDATE ir_model_fields SET relation = %s '
+ 'WHERE relation = %s', (new, old,))
+ cr.execute('UPDATE ir_model_data SET model = %s '
+ 'WHERE model = %s', (new, old,))
+
+def rename_tables(cr, table_spec):
+ """
+ Rename tables. Typically called in the pre script.
+ This function also renames the id sequence if it exists and if it is
+ not modified in the same run.
+
+ :param table_spec: a list of tuples (old table name, new table name).
+
+ """
+ # Append id sequences
+ to_rename = [x[0] for x in table_spec]
+ for old, new in list(table_spec):
+ if (table_exists(cr, old + '_id_seq') and
+ old + '_id_seq' not in to_rename):
+ table_spec.append((old + '_id_seq', new + '_id_seq'))
+ for (old, new) in table_spec:
+ logger.info("table %s: renaming to %s",
+ old, new)
+ cr.execute('ALTER TABLE "%s" RENAME TO "%s"' % (old, new,))
+
+def rename_columns(cr, column_spec):
+ """
+ Rename table columns. Typically called in the pre script.
+
+ :param column_spec: a hash with table keys, with lists of tuples as values. \
+ Tuples consist of (old_name, new_name).
+
+ """
+ for table in column_spec.keys():
+ for (old, new) in column_spec[table]:
+ logger.info("table %s, column %s: renaming to %s",
+ table, old, new)
+ cr.execute('ALTER TABLE "%s" RENAME "%s" TO "%s"' % (table, old, new,))
+
+def migrate(cr, version):
+ """
+ Preserve references to Payment Type resources after renaming to
+ Payment Mode Type
+ """
+ if version and version.startswith('5.0.'):
+ rename_models(cr, [['payment.type', 'payment.mode.type']])
+ rename_tables(cr, [['payment_type', 'payment_mode_type']])
+ rename_columns(cr, {'account_bank_statement_line': [
+ ('reconcile_id', 'legacy_bank_statement_reconcile_id')]})
Follow ups