From 5afacd17c037551e3d116593cb4ecf3932e7acfa Mon Sep 17 00:00:00 2001 From: "Sbh (OpenERP)" Date: Tue, 15 Feb 2011 12:51:21 +0530 Subject: [PATCH] [ADD] sync_google_contact:Add synchronized with openerp to gmail on Create address bzr revid: sbh@tinyerp.com-20110215072121-01aas21x05xwmh3m --- .../sync_google_contact.py | 27 ++++++++++++++++++- .../sync_google_contact_view.xml | 1 + .../wizard/google_contact_import.py | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/addons/sync_google_contact/sync_google_contact.py b/addons/sync_google_contact/sync_google_contact.py index 7bac97cb5d8..7ef2bff4d6c 100644 --- a/addons/sync_google_contact/sync_google_contact.py +++ b/addons/sync_google_contact/sync_google_contact.py @@ -26,6 +26,7 @@ try: import gdata from gdata import contacts import gdata.contacts.service + 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')) @@ -58,7 +59,8 @@ class google_lib(object): new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name)) # Create a work email address for the contact and use as primary. - new_contact.email.append(gdata.contacts.Email(address=primary_email, + if primary_email: + new_contact.email.append(gdata.contacts.Email(address=primary_email, primary='true', rel=gdata.contacts.REL_WORK)) entry = self.contact.CreateContact(new_contact) return entry @@ -75,6 +77,29 @@ class res_partner_address(osv.osv): } + def create(self, cr, uid, vals, context=None): + + if context is None: + context = {} + if vals.get('sync_google') : + self.sync_create(cr,uid,vals,context=context,synchronize=vals.get('sync_google')) + return super(res_partner_address, self).create(cr, uid, vals, context=context) + + def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True): + if context is None: + context = {} + return super(res_partner_address, self).write(cr, uid, ids, vals, context=context) + + def sync_create(self, cr, uid, vals, context=None,synchronize=True): + # we all more detail soon + user_obj=self.pool.get('res.users').browse(cr, uid, uid) + gmail_user=user_obj.gmail_user + gamil_pwd=user_obj.gmail_password + google_obj =google_lib(gmail_user, gamil_pwd) + name=vals.get('name') + email=vals.get('email') + contact = google_obj._create_contact(name,email) + return True res_partner_address() diff --git a/addons/sync_google_contact/sync_google_contact_view.xml b/addons/sync_google_contact/sync_google_contact_view.xml index abbce4a2019..f7c077c1158 100644 --- a/addons/sync_google_contact/sync_google_contact_view.xml +++ b/addons/sync_google_contact/sync_google_contact_view.xml @@ -9,6 +9,7 @@ + diff --git a/addons/sync_google_contact/wizard/google_contact_import.py b/addons/sync_google_contact/wizard/google_contact_import.py index 43601ad8fa1..605ae43b506 100644 --- a/addons/sync_google_contact/wizard/google_contact_import.py +++ b/addons/sync_google_contact/wizard/google_contact_import.py @@ -57,7 +57,7 @@ class google_contact_import(osv.osv_memory): 'email': emails, 'google_id':google_id } - contact_ids = addresss_obj.search(cr, uid, [('email','ilike',emails)]) + contact_ids = addresss_obj.search(cr, uid, [('email','ilike',emails),]) if not contact_ids: addresses.append(addresss_obj.create(cr, uid, data, context=context)) if not contact: