← Back to team overview

credativ team mailing list archive

[Merge] lp:~therp-nl/openupgrade-server/7.0-API_m2o_to_m2m into lp:openupgrade-server

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/openupgrade-server/7.0-API_m2o_to_m2m into lp:openupgrade-server.

Requested reviews:
  OpenUpgrade Committers (openupgrade-committers)

For more details, see:
https://code.launchpad.net/~therp-nl/openupgrade-server/7.0-API_m2o_to_m2m/+merge/175848

Refactored from http://bazaar.launchpad.net/~credativ/openupgrade-server/7.0/revision/4615

-- 
https://code.launchpad.net/~therp-nl/openupgrade-server/7.0-API_m2o_to_m2m/+merge/175848
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~therp-nl/openupgrade-server/7.0-API_m2o_to_m2m into lp:openupgrade-server.
=== modified file 'openerp/addons/base/migrations/7.0.1.3/pre-migration.py'
--- openerp/addons/base/migrations/7.0.1.3/pre-migration.py	2013-06-11 08:09:44 +0000
+++ openerp/addons/base/migrations/7.0.1.3/pre-migration.py	2013-07-19 14:28:27 +0000
@@ -43,9 +43,16 @@
 }
 
 xmlid_renames = []
+<<<<<<< TREE
 model_renames = [
     ('ir.actions.url', 'ir.actions.act_url'),
     ]
+=======
+xmlid_removals = [
+    ('base', 'view_partner_form'),
+    ('base', 'view_users_form'),
+    ]
+>>>>>>> MERGE-SOURCE
 
 def migrate_ir_attachment(cr):
     # Data is now stored in db_datas column and datas is a function field
@@ -156,6 +163,13 @@
                 "VALUES(%s, 'res.partner', 'base', 'partner_root', TRUE) ",
                 (partner_id,))
 
+def remove_xmlids(cr, xmlids_spec):
+    for spec in xmlids_spec:
+        cr.execute("select id, res_id from ir_model_data where module = %s and name = %s", spec)
+        row = cr.fetchone()
+        if row:
+            cr.execute("delete from ir_model_data where id = %s", row[:1])
+
 @openupgrade.migrate()
 def migrate(cr, version):
     update_base_sql(cr)
@@ -165,6 +179,10 @@
     openupgrade.drop_columns(cr, [('ir_actions_todo', 'action_id')])
     openupgrade.rename_columns(cr, column_renames)
     openupgrade.rename_xmlids(cr, xmlid_renames)
+<<<<<<< TREE
     openupgrade.rename_models(cr, model_renames)
+=======
+    remove_xmlids(cr, xmlid_removals)
+>>>>>>> MERGE-SOURCE
     migrate_ir_attachment(cr)
     create_users_partner(cr)

=== modified file 'openerp/openupgrade/openupgrade.py'
--- openerp/openupgrade/openupgrade.py	2013-06-11 08:09:44 +0000
+++ openerp/openupgrade/openupgrade.py	2013-07-19 14:28:27 +0000
@@ -48,6 +48,7 @@
     'rename_models',
     'rename_xmlids',
     'get_legacy_name',
+    'm2o_to_m2m',
 ]    
 
 def load_data(cr, module_name, filename, idref=None, mode='init'):
@@ -331,6 +332,26 @@
     return 'openupgrade_legacy_'+('_').join(
         map(str, release.version_info[0:2]))+'_'+original_name
 
+def m2o_to_m2m(cr, model, table, field, source_field=None):
+    """
+    :param model: The target model
+    :param table: The source table
+    :param field: The field name of the target model
+    :parm source_field: the many2one column on the source table. \
+    If None, the legacy name for parameter 'field' is used.
+    """
+    if source_field is None:
+        source_field = get_legacy_name(field)
+
+    cr.execute('SELECT id, %(field)s '
+               'FROM %(table)s '
+               'WHERE %(field)s is not null' % {
+                   'table': table,
+                   'field': source_field,
+                   })
+    for row in cr.fetchall():
+        model.write(cr, SUPERUSER_ID, row[0], {field: [(4, row[1])]})
+
 def migrate():
     """
     This is the decorator for the migrate() function

=== added file 'openerp/openupgrade/openupgrade70.py'
--- openerp/openupgrade/openupgrade70.py	1970-01-01 00:00:00 +0000
+++ openerp/openupgrade/openupgrade70.py	2013-07-19 14:28:27 +0000
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    This migration script copyright (C) 2012-2013 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 openupgrade
+
+def partner_address_to_partner(cr, table, field):
+    openupgrade.logged_query(cr, """
+        UPDATE %(table)s
+        SET %(field)s = a.openupgrade_7_migrated_to_partner_id
+        FROM %(table)s t
+        JOIN res_partner_address a
+        ON t.%(field)s = a.id
+        WHERE t.%(field)s is not null""" % { 'table': table,
+                                             'field': field })