← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-contact-google-sync-import-contacts-uco into lp:~openerp-dev/openobject-addons/trunk-contact-google-sync

 

Ujjvala Collins (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-contact-google-sync-import-contacts-uco into lp:~openerp-dev/openobject-addons/trunk-contact-google-sync.

Requested reviews:
  OpenERP R&D Team (openerp-dev)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-contact-google-sync-import-contacts-uco/+merge/50917

Check if the google id exist in ir.model.data
                if yes, merge information
		Else
		check if there is a contact with the same email (exactly the same email)
			if yes 
				Associate the id of the existing address with google id => in ir.model.data
				Merge information
			if no
				Associate the id of the new address with google id => in ir.model.data
				create a new address (and a new partner if create partner is link)
	The merge
		Fill with google value only if it's empty
		Never create a new partner while merging
	Delete an address (need to overwrite partner.address unlink method)
		Check if it exist in the table ir.model.data => if yes delete it
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-contact-google-sync-import-contacts-uco/+merge/50917
Your team OpenERP R&D Team is requested to review the proposed merge of lp:~openerp-dev/openobject-addons/trunk-contact-google-sync-import-contacts-uco into lp:~openerp-dev/openobject-addons/trunk-contact-google-sync.
=== modified file 'google_base_account/google_base_account.py'
--- google_base_account/google_base_account.py	2011-02-18 10:22:57 +0000
+++ google_base_account/google_base_account.py	2011-02-23 13:21:35 +0000
@@ -20,7 +20,6 @@
 ##############################################################################
 
 from osv import fields,osv,orm
-
     
 class res_users(osv.osv):
     _inherit = "res.users"
@@ -30,14 +29,14 @@
     }
 res_users()    
 
-class res_partner_address(osv.osv):
+class ir_model_data(osv.osv):
     
-    _inherit = "res.partner.address"
+    _inherit = "ir.model.data"
     _columns = {
         'google_id': fields.char('Google Contact Id', size=128, readonly=True),  
     }
 
-res_partner_address()
+ir_model_data()
 
 # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
 

=== modified file 'sync_base/wizard/sync_base_view.xml'
--- sync_base/wizard/sync_base_view.xml	2011-02-21 17:29:35 +0000
+++ sync_base/wizard/sync_base_view.xml	2011-02-23 13:21:35 +0000
@@ -19,7 +19,7 @@
         </record>
 
          <record model="ir.actions.act_window" id="act_google_contact_import_form">
-          <field name="name">Import contacts from remote adress book</field>
+          <field name="name">Import contacts from remote address book</field>
           <field name="type">ir.actions.act_window</field>
           <field name="res_model">synchronize.base.contact.wizard.import</field>
           <field name="view_type">form</field>
@@ -29,7 +29,7 @@
         </record>
 
 
-        <menuitem name="Import contacts from remote adress book" id="menu_sync_contact"
+        <menuitem name="Import contacts from remote address book" id="menu_sync_contact"
              parent="base.menu_address_book" action="act_google_contact_import_form"
              sequence="40" />
 

=== modified file 'sync_google_contact/__init__.py'
--- sync_google_contact/__init__.py	2011-02-16 11:15:32 +0000
+++ sync_google_contact/__init__.py	2011-02-23 13:21:35 +0000
@@ -19,6 +19,7 @@
 #
 ##############################################################################
 
+import sync_google_contact
 import wizard
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added file 'sync_google_contact/sync_google_contact.py'
--- sync_google_contact/sync_google_contact.py	1970-01-01 00:00:00 +0000
+++ sync_google_contact/sync_google_contact.py	2011-02-23 13:21:35 +0000
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    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/>.
+#
+##############################################################################
+
+from osv import fields,osv,orm
+
+class res_partner_address(osv.osv):
+    _inherit = "res.partner.address"
+
+    def unlink(self, cr, uid, ids, context=None):
+        model_obj = self.pool.get('ir.model.data')
+        model_ids = model_obj.search(cr, uid, [('res_id','in',ids)], context=context)
+        model_obj.unlink(cr, uid, model_ids, context=context)
+        return super(res_partner_address, self).unlink(cr, uid, ids, context=context)
+
+res_partner_address()
+
+# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'sync_google_contact/wizard/google_contact_import.py'
--- sync_google_contact/wizard/google_contact_import.py	2011-02-23 12:50:27 +0000
+++ sync_google_contact/wizard/google_contact_import.py	2011-02-23 13:21:35 +0000
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 L (<http://tiny.be>).
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -24,11 +24,9 @@
 import tools
 try:
     import gdata
-    from gdata import contacts
     import gdata.contacts.service
     import gdata.contacts
     import gdata.contacts.client    
-    import atom
 except ImportError:
     raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
 
@@ -41,7 +39,7 @@
         should be overwritten by subclasses
         """
         names = super(google_base_import, self)._get_tools_name(cr, user, context=context)
-        names.append(('gmail','Gmail adress book'))
+        names.append(('gmail','Gmail address book'))
         return names
 
 
@@ -203,20 +201,25 @@
             return {'type': 'ir.actions.act_window_close'}
         
     def create_contact(self, cr, uid, gd_client,contact, partner_id=False,context=None):  
-          
+        model_obj = self.pool.get('ir.model.data')
         addresss_obj = self.pool.get('res.partner.address')
         addresses = []
         partner_ids = []        
         while contact:
             for entry in contact.entry:
-                data={}
+                data = {}
+                model_data = {
+                    'name': 'google_contacts_information_%s' %(entry.id.text),
+                    'model': 'res.partner.address',
+                    'module': 'sync_google_contact',
+                }
                 name = tools.ustr(entry.title.text)
                 google_id = entry.id.text
                 emails = ','.join(email.address for email in entry.email)
                 if name and name != 'None':
                     data['name'] = name
                 if google_id:
-                    data['google_id'] =google_id
+                    model_data.update({'google_id': google_id})
                 if entry.phone_number:
                     for phone in entry.phone_number:
                         if phone.rel == gdata.contacts.REL_WORK:
@@ -225,11 +228,13 @@
                             data['mobile'] = phone.text
                         if phone.rel == gdata.contacts.PHONE_WORK_FAX:
                             data['fax'] = phone.text
-                if emails:
+     
+                data_ids = model_obj.search(cr, uid, [('google_id','=',google_id)])
+                if data_ids:
+                    contact_ids = [model_obj.browse(cr, uid, data_ids[0], context=context).res_id]
+                elif emails:
                     data['email'] = emails
                     contact_ids = addresss_obj.search(cr, uid, [('email','ilike',emails)])
-                else:
-                    contact_ids = addresss_obj.search(cr, uid, [('google_id','=',google_id)])
 
                 if partner_id and name!='None':
                     partner_id, data = self.create_partner(cr, uid, data, context=context)
@@ -238,7 +243,10 @@
                     addresses.append(contact_ids[0])
                     self.update_contact( cr, uid, contact_ids, data,context=context)
                 if not contact_ids:
-                 addresses.append(addresss_obj.create(cr, uid, data, context=context))
+                    res_id = addresss_obj.create(cr, uid, data, context=context)
+                    addresses.append(res_id)
+                    model_data.update({'res_id': res_id})
+                    model_obj.create(cr, uid, model_data, context=context)
             if not contact:
                 break
             next = contact.GetNextLink()
@@ -252,8 +260,8 @@
         addresss_obj = self.pool.get('res.partner.address')
         if context==None:
             context={}
-        res={}
-        addr=addresss_obj.browse(cr,uid,contact_ids)[0]
+        res = {}
+        addr = addresss_obj.browse(cr,uid,contact_ids)[0]
         name = str((addr.name or addr.partner_id and addr.partner_id.name or '').encode('utf-8'))
         email = addr.email
         phone = addr.phone


Follow ups