← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-contact-google-sync-add_timestamp-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-add_timestamp-uco into lp:~openerp-dev/openobject-addons/trunk-contact-google-sync.

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

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

Backlog merge + conflict handling
------------------------------------------------
* When the contact already exist : there is two case
     * We find the same mail adress
           * We keep the current behavior
      * We find the same google_id in ir.model.data
	   * Check if google send timestamp of last modification
		    * Check timestamp of two record and keep the last one
		    * Take the information from the most recently modified
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-contact-google-sync-add_timestamp-uco/+merge/55335
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-contact-google-sync.
=== modified file 'sync_google_contact/sync_google_contact.py'
--- sync_google_contact/sync_google_contact.py	2011-02-24 06:24:40 +0000
+++ sync_google_contact/sync_google_contact.py	2011-03-29 13:27:52 +0000
@@ -19,11 +19,15 @@
 #
 ##############################################################################
 
-from osv import fields,osv,orm
+from osv import fields,osv
 
 class res_partner_address(osv.osv):
     _inherit = "res.partner.address"
 
+    _columns = {
+        'write_date': fields.datetime('Date Modified', readonly=True, help="Modification date and time of 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),('model','=','res.partner.address'),('module','=','sync_google_contact')], context=context)

=== modified file 'sync_google_contact/wizard/google_contact_import.py'
--- sync_google_contact/wizard/google_contact_import.py	2011-03-25 11:51:10 +0000
+++ sync_google_contact/wizard/google_contact_import.py	2011-03-29 13:27:52 +0000
@@ -18,10 +18,11 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+import datetime
+import dateutil
+from dateutil.parser import *
+from pytz import timezone
 
-from osv import fields,osv
-from tools.translate import _
-import tools
 try:
     import gdata
     import gdata.contacts.service
@@ -29,6 +30,10 @@
 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'))
 
+from osv import fields,osv
+from tools.translate import _
+import tools
+
 class google_contact_import(osv.osv_memory):
     _inherit = 'google.login'
     _name = 'google.login.contact'
@@ -138,6 +143,12 @@
         addresses = []
         partner_ids = []
         contact_ids=[]
+        if 'tz' in context and context['tz']:
+            time_zone = context['tz']
+        else:
+            time_zone = 'Asia/Kolkata'
+        au_tz = timezone(time_zone)
+        
         while contact:
             for entry in contact.entry:
                 data = self._retreive_data(entry)
@@ -157,7 +168,13 @@
 
                 if contact_ids:
                     addresses.append(contact_ids[0])
-                    self.update_contact(cr, uid, contact_ids, data, context=context)
+                    address = addresss_obj.browse(cr, uid, contact_ids[0], context=context)
+                    google_updated = entry.updated.text
+                    utime = dateutil.parser.parse(google_updated)
+                    au_dt = au_tz.normalize(utime.astimezone(au_tz))
+                    updated_dt = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
+                    if address.write_date < updated_dt:
+                        self.update_contact(cr, uid, contact_ids, data, context=context)
                     res_id = contact_ids[0]
                 if not contact_ids:
                     #create or link to an existing partner only if it's a new contact
@@ -192,8 +209,7 @@
         data['name'] = name
         emails = ','.join(email.address for email in entry.email)
         data['email'] = emails
-                    
-
+        
         if entry.phone_number:
             for phone in entry.phone_number:
                 if phone.rel == gdata.contacts.REL_WORK:
@@ -211,17 +227,17 @@
         name = str((addr.name or addr.partner_id and addr.partner_id.name or '').encode('utf-8'))
 
         if not name:
-            vals['name']=data.get('name','')
+            vals['name'] = data.get('name','')
         if not addr.email:
-            vals['email']=data.get('email','')
+            vals['email'] = data.get('email','')
         if not addr.mobile:
-            vals['mobile']=data.get('mobile','')
+            vals['mobile'] = data.get('mobile','')
         if not addr.phone:
-            vals['phone']=data.get('phone','')
+            vals['phone'] = data.get('phone','')
         if not addr.fax:
-            vals['fax']=data.get('fax','')
-            
-        addresss_obj.write(cr,uid,contact_ids,vals,context=context)
+            vals['fax'] = data.get('fax','')
+        
+        addresss_obj.write(cr, uid, contact_ids, vals, context=context)
         return {'type': 'ir.actions.act_window_close'}
 
 synchronize_google_contact()


Follow ups