diff --git a/addons/google_base_account/wizard/google_login.py b/addons/google_base_account/wizard/google_login.py index e60af4305f4..23602be0403 100644 --- a/addons/google_base_account/wizard/google_login.py +++ b/addons/google_base_account/wizard/google_login.py @@ -24,8 +24,6 @@ from tools.translate import _ import gdata.contacts import gdata.contacts.service -from sync_google_contact import sync_google_contact - class google_login(osv.osv_memory): _description ='Google Contact' _name = 'google.login' @@ -35,24 +33,26 @@ class google_login(osv.osv_memory): } def check_login(self, cr, uid, ids, context=None): - if context==None: - context={} - data=self.read(cr,uid,ids)[0] - user=data['user'] - password=data['password'] + if context == None: + context = {} + data = self.read(cr, uid, ids)[0] + user = data['user'] + password = data['password'] gd_client = gdata.contacts.service.ContactsService() gd_client.email = user gd_client.password = password gd_client.source = 'OpenERP' try: gd_client.ProgrammaticLogin() - res={'gmail_user':user, - 'gmail_password':password} - self.pool.get('res.users').write(cr,uid,uid,res,context=context) + res = { + 'gmail_user': user, + 'gmail_password': password + } + self.pool.get('res.users').write(cr, uid, uid, res, context=context) except Exception, e: raise osv.except_osv(_('Error!'),_('%s' % (e))) - return {} + return gd_client google_login() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sync_google_contact/__init__.py b/addons/sync_google_contact/__init__.py index 202f8f989f2..f8a7a810426 100644 --- a/addons/sync_google_contact/__init__.py +++ b/addons/sync_google_contact/__init__.py @@ -19,7 +19,6 @@ # ############################################################################## -import sync_google_contact import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sync_google_contact/__openerp__.py b/addons/sync_google_contact/__openerp__.py index df4c1f50a17..4d0d98a48a0 100644 --- a/addons/sync_google_contact/__openerp__.py +++ b/addons/sync_google_contact/__openerp__.py @@ -27,10 +27,9 @@ 'description': """The module adds google contact in partner address""", 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', - 'depends': ['base','sync_base','google_base_account',], + 'depends': ['base','google_base_account'], 'init_xml': [], 'update_xml': [ - 'sync_google_contact_view.xml', 'wizard/google_contact_import_view.xml' ], 'demo_xml': [], diff --git a/addons/sync_google_contact/sync_google_contact.py b/addons/sync_google_contact/sync_google_contact.py deleted file mode 100644 index da42618646f..00000000000 --- a/addons/sync_google_contact/sync_google_contact.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# 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 . -# -############################################################################## - -from osv import fields,osv,orm -from tools.translate import _ - -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')) - -class google_lib(object): - - def __init__(self, email, password): - super(google_lib, self).__init__() - self.contact = gdata.contacts.service.ContactsService() - self.contact.email = email - self.contact.password = password - self.contact.source = 'OpenERP' - try: - self.contact.ProgrammaticLogin() - except Exception, e: - raise osv.except_osv(_('Error!'),_('%s' % (e))) - - def _get_contact(self, href=''): - if href: - feed = self.contact.GetContactsFeed(href) - else: - feed = self.contact.GetContactsFeed() - return feed - - def _get_contact_allGroups(self): - """ fetch all allGroup.""" - feed = self.contact.GetGroupsFeed() - return feed - def _create_contact(self,name,primary_email): - """ create a contact.""" - - new_contact = gdata.contacts.ContactEntry(title=atom.Title(text=name)) - # Create a work email address for the contact and use as primary. - 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 - def _delete_contact(self): - self.contact.DeleteContact(selected_entry.GetEditLink().href) - return True - -class res_partner_address(osv.osv): - - _inherit = "res.partner.address" - _columns = { - 'sync_google':fields.boolean('Synchronize with Google'), - 'google_id': fields.char('Google Contact Id', size=128, readonly=True), - } - - - def create(self, cr, uid, vals, context=None): - id =super(res_partner_address, self).create(cr, uid, vals, context=context) - vals.update({'ids':id}) - if context is None: - context = {} - if vals.get('sync_google') : - self.sync_create(cr,uid,vals,context=context,synchronize=vals.get('sync_google')) - return id - - 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) - openerp_id=vals['ids'] - self.write(cr,uid,[openerp_id],{'google_id':contact.id.text},context=context) - return True -res_partner_address() - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/sync_google_contact/sync_google_contact_view.xml b/addons/sync_google_contact/sync_google_contact_view.xml deleted file mode 100644 index f7c077c1158..00000000000 --- a/addons/sync_google_contact/sync_google_contact_view.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - res.partner.address.google.form.inherited1 - res.partner.address - - form - - - - - - - - - diff --git a/addons/sync_google_contact/test.py b/addons/sync_google_contact/test.py deleted file mode 100644 index 896fd93496b..00000000000 --- a/addons/sync_google_contact/test.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). -# -# 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 . -# -############################################################################## - -# demo script for geeting contact detail' -import sys -import getopt -import getpass -import atom -import gdata.contacts -import gdata.contacts.service -email='user name of gmail' -password='add the password' -gd_client = gdata.contacts.service.ContactsService() -gd_client.email = email -gd_client.password = password -gd_client.source = 'GoogleInc-ContactsPythonSample-1' -gd_client.ProgrammaticLogin() -feed= gd_client.GetContactsFeed() -next = feed.GetNextLink() -for i, entry in enumerate(feed.entry): - print entry.title.text - \ No newline at end of file diff --git a/addons/sync_google_contact/wizard/google_contact_import.py b/addons/sync_google_contact/wizard/google_contact_import.py index 605ae43b506..764cffcb18c 100644 --- a/addons/sync_google_contact/wizard/google_contact_import.py +++ b/addons/sync_google_contact/wizard/google_contact_import.py @@ -19,35 +19,53 @@ # ############################################################################## -from osv import fields,osv,orm +from osv import fields,osv from tools.translate import _ -from sync_google_contact import sync_google_contact - class google_contact_import(osv.osv_memory): - _name = "synchronize.base" - _inherit = 'synchronize.base' + _name = "google.import.contact" + _inherit = 'google.login' _columns = { - 'tools': fields.selection([('gmail','Gmail')],'Tools'), - 'create_partner':fields.selection([('group','Group'),('email_address','Email address'),('gmail_user','Gmail user')], 'Create Partner'), + 'create_partner': fields.boolean('Create Partner', help="It will create Partner for given gmail user otherwise only adds contacts in Partner Addresses.") } + + def default_get(self, cr, uid, fields, context=None): + res = super(google_contact_import, self).default_get(cr, uid, fields, context=context) + user_obj = self.pool.get('res.users').browse(cr, uid, uid) + if 'user' in fields: + res.update({'user': user_obj.gmail_user}) + if 'password' in fields: + res.update({'password': user_obj.gmail_password}) + return res def import_contact(self, cr, uid, ids, context=None): # Only see the result, we will change the code + gd_client = self.check_login(cr, uid, ids, context=context) + if not gd_client: + return {'type': 'ir.actions.act_window_close'} + addresss_obj = self.pool.get('res.partner.address') - user_obj=self.pool.get('res.users').browse(cr, uid, uid) - gmail_user=user_obj.gmail_user - gamil_pwd=user_obj.gmail_password + partner_obj = self.pool.get('res.partner') + user_obj = self.pool.get('res.users').browse(cr, uid, uid) + gmail_user = user_obj.gmail_user + gamil_pwd = user_obj.gmail_password if not gmail_user or not gamil_pwd: raise osv.except_osv(_('Error'), _("Please specify the user and password !")) + + contact = gd_client.GetContactsFeed() + partner_id = [] + addresses = [] + for obj in self.browse(cr, uid, ids, context=context): - google_obj = sync_google_contact.google_lib(gmail_user, gamil_pwd) - contact = google_obj._get_contact() - addresses = [] + if obj.create_partner: + for user in contact.author: + partner_name = user.name.text + partner_id = partner_obj.search(cr, uid, [('name','ilike',partner_name)], context=context) + if not partner_id: + partner_id.append(partner_obj.create(cr, uid, {'name': partner_name}, context=context)) while contact: for entry in contact.entry: - google_id= entry.id.text name = entry.title.text phone_numbers = ','.join(phone_number.text for phone_number in entry.phone_number) emails = ','.join(email.address for email in entry.email) @@ -55,9 +73,9 @@ class google_contact_import(osv.osv_memory): 'name': name, 'phone': phone_numbers, 'email': emails, - 'google_id':google_id + 'partner_id': partner_id and partner_id[0] } - 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: @@ -65,17 +83,32 @@ class google_contact_import(osv.osv_memory): next = contact.GetNextLink() contact = None if next: - contact = google_obj._get_contact(next.href) - return { - 'name': _('Contacts'), - 'domain': "[('id','in',"+str(addresses)+")]", - 'view_type': 'form', - 'view_mode': 'tree,form', - 'res_model': 'res.partner.address', - 'context': context, - 'views': [(False, 'tree'),(False, 'form')], - 'type': 'ir.actions.act_window', - } + contact = gd_client.GetContactsFeed(next.href) + if partner_id: + partner_id = partner_id[0] + return { + 'name': _('Partner'), + 'domain': "[('id','=',"+str(partner_id)+")]", + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'res.partner', + 'context': context, + 'views': [(False, 'tree'),(False, 'form')], + 'type': 'ir.actions.act_window', + } + elif addresses: + return { + 'name': _('Contacts'), + 'domain': "[('id','in', ["+','.join(map(str,addresses))+"])]", + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'res.partner.address', + 'context': context, + 'views': [(False, 'tree'),(False, 'form')], + 'type': 'ir.actions.act_window', + } + else: + return {'type': 'ir.actions.act_window_close'} google_contact_import() diff --git a/addons/sync_google_contact/wizard/google_contact_import_view.xml b/addons/sync_google_contact/wizard/google_contact_import_view.xml index af2c575a080..370636864a3 100644 --- a/addons/sync_google_contact/wizard/google_contact_import_view.xml +++ b/addons/sync_google_contact/wizard/google_contact_import_view.xml @@ -3,15 +3,18 @@ - synchronize.base.import.form - synchronize.base + google.import.contact.form + google.import.contact form
- - + + + + +