← Back to team overview

credativ team mailing list archive

[Merge] lp:~savoirfairelinux-openerp/openupgrade-server/base_contact into lp:openupgrade-server

 

Sandy Carter (http://www.savoirfairelinux.com) has proposed merging lp:~savoirfairelinux-openerp/openupgrade-server/base_contact into lp:openupgrade-server.

Requested reviews:
  OpenUpgrade Committers (openupgrade-committers)

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/openupgrade-server/base_contact/+merge/194762

Marks base_contact module to be removed.
Moves entries from res_partner_contact to res_partner.
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/openupgrade-server/base_contact/+merge/194762
Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~savoirfairelinux-openerp/openupgrade-server/base_contact into lp:openupgrade-server.
=== modified file 'openerp/addons/base/migrations/7.0.1.3/post-migration.py'
--- openerp/addons/base/migrations/7.0.1.3/post-migration.py	2013-10-21 08:59:09 +0000
+++ openerp/addons/base/migrations/7.0.1.3/post-migration.py	2013-11-11 22:40:44 +0000
@@ -56,11 +56,61 @@
             SET rml_footer = rml_footer1
         """)
 
+def migrate_base_contact(cr):
+    """
+    Move entries of res_partner_contact into res_partner
+    """
+    cr.execute("SELECT * FROM information_schema.tables WHERE table_name = 'res_partner_contact';")
+    if not cr.fetchall():
+        return
+    fields = [
+        'create_date',
+        'name',
+        'website',
+        'image',
+        'active',
+        'comment',
+        'title',
+        'phone',
+        'country_id',
+        'email',
+        'birthdate',
+        'lang',
+        'parent_id',
+    ]
+    # Add lang from lang_id
+    openupgrade.logged_query(cr, "ALTER TABLE res_partner_contact ADD COLUMN lang character varying(5);")
+    openupgrade.logged_query(cr, """
+        UPDATE res_partner_contact
+        SET lang = (SELECT code
+                    FROM res_lang l
+                    WHERE lang_id = l.id
+                    LIMIT 1);""")
+    # Add parent_id
+    openupgrade.logged_query(cr, "ALTER TABLE res_partner_contact ADD COLUMN parent_id integer;")
+    openupgrade.logged_query(cr, """
+        UPDATE res_partner_contact
+        SET parent_id = (SELECT openupgrade_7_migrated_to_partner_id
+                         FROM res_partner_address a
+                         WHERE id = a.contact_id
+                         LIMIT 1);""")
+    # Make sure fields exist
+    cr.execute(
+        "SELECT column_name "
+        "FROM information_schema.columns "
+        "WHERE table_name = 'res_partner_contact';")
+    available_fields = set(i[0] for i in cr.fetchall())
+    fields = list(available_fields.intersection(fields))
+    # Move data
+    openupgrade.logged_query(cr, """
+        INSERT INTO res_partner (%s)
+        SELECT %s
+        FROM res_partner_contact;""" % (", ".join(fields + ['customer', 'is_company']),
+                                        ", ".join(fields + ['TRUE', 'FALSE'])))
+
 def migrate_partner_address(cr, pool):
     """ res.partner.address is obsolete. Move existing data to
     partner
-
-    TODO: break hard when base_contact is installed
     """
     partner_obj = pool.get('res.partner')
     cr.execute(
@@ -82,6 +132,14 @@
     partner_found = []
     processed_ids = []
 
+    # Make sure fields exist
+    cr.execute(
+        "SELECT column_name "
+        "FROM information_schema.columns "
+        "WHERE table_name = 'res_partner_address';")
+    available_fields = set(i[0] for i in cr.fetchall())
+    fields = available_fields.intersection(fields)
+
     def set_address_partner(address_id, partner_id):
         cr.execute(
             "UPDATE res_partner_address "
@@ -222,6 +280,7 @@
     migrate_ir_translation(cr)
     migrate_company(cr)
     migrate_partner_address(cr, pool)
+    migrate_base_contact(cr)
     update_users_partner(cr, pool)
     reset_currency_companies(cr, pool)
     migrate_res_company_logo(cr, pool)

=== 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-10-25 19:54:27 +0000
+++ openerp/addons/base/migrations/7.0.1.3/pre-migration.py	2013-11-11 22:40:44 +0000
@@ -63,6 +63,19 @@
         cr,
         "UPDATE ir_module_module SET demo = false")
 
+def rename_base_contact_columns(cr):
+    """
+    Rename columns only if res_partner_contact is installed
+    """
+    cr.execute("SELECT * FROM information_schema.tables WHERE table_name = 'res_partner_contact';")
+    if cr.fetchall():
+        openupgrade.rename_columns(cr, {
+            'res_partner_contact': [
+                ('photo', 'image'),
+                ('mobile', 'phone'),
+            ]
+        })
+
 def migrate_ir_attachment(cr):
     # Data is now stored in db_datas column and datas is a function field
     # like in the document module in 6.1. If the db_datas column already
@@ -175,6 +188,7 @@
 def remove_obsolete_modules(cr):
     obsolete_modules = (
         'base_tools',
+        'base_contact',
         )
     cr.execute(
         """
@@ -192,6 +206,7 @@
         )
     openupgrade.drop_columns(cr, [('ir_actions_todo', 'action_id')])
     openupgrade.rename_columns(cr, column_renames)
+    rename_base_contact_columns(cr)
     openupgrade.rename_xmlids(cr, xmlid_renames)
     openupgrade.rename_models(cr, model_renames)
     migrate_ir_attachment(cr)


Follow ups