← 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/175915

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/175915
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/openupgrade/openupgrade.py'
--- openerp/openupgrade/openupgrade.py	2013-06-11 08:09:44 +0000
+++ openerp/openupgrade/openupgrade.py	2013-07-19 18:12:25 +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,22 @@
     return 'openupgrade_legacy_'+('_').join(
         map(str, release.version_info[0:2]))+'_'+original_name
 
+def m2o_to_m2m(cr, model, table, field, source_field):
+    """
+    :param model: The target model
+    :param table: The source table
+    :param field: The field name of the target model
+    :param source_field: the many2one column on the source table.
+    """
+    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


Follow ups