diff --git a/addons/google_contact/__init__.py b/addons/google_contact/__init__.py index ab21f4a289b..24942ad978b 100644 --- a/addons/google_contact/__init__.py +++ b/addons/google_contact/__init__.py @@ -20,5 +20,7 @@ ############################################################################## import google_contact +import wizard + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_contact/__openerp__.py b/addons/google_contact/__openerp__.py index 645362a0729..9af25a1b4db 100644 --- a/addons/google_contact/__openerp__.py +++ b/addons/google_contact/__openerp__.py @@ -30,7 +30,8 @@ 'depends': ['base'], 'init_xml': [], 'update_xml': [ - # 'google_contact_view.xml' + #'google_contact_view.xml', + 'wizard/google_contact_import_view.xml' ], 'demo_xml': [], 'installable': True, diff --git a/addons/google_contact/google_contact.py b/addons/google_contact/google_contact.py index fe823f118c1..ad4ab1f6988 100644 --- a/addons/google_contact/google_contact.py +++ b/addons/google_contact/google_contact.py @@ -20,10 +20,11 @@ ############################################################################## from osv import fields,osv,orm +from tools.translate import _ try: import gdata - from gdata import contacts + from gdata import contacts import gdata.contacts.service 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')) @@ -36,10 +37,16 @@ class google_lib(object): self.contact.email = email self.contact.password = password self.contact.source = 'GoogleInc-ContactsPythonSample-1' - self.contact.ProgrammaticLogin() + try: + self.contact.ProgrammaticLogin() + except Exception, e: + raise osv.except_osv(_('Error!'),_('%s' % (e))) - def _get_contact(self): - feed= self.contact.GetContactsFeed() + def _get_contact(self, href=''): + if href: + feed = self.contact.GetContactsFeed(href) + else: + feed = self.contact.GetContactsFeed() return feed def _get_contact_allGroups(self): @@ -59,28 +66,5 @@ class google_lib(object): self.contact.DeleteContact(selected_entry.GetEditLink().href) return True -class google_contact(osv.osv): - _description ='Google Contact' - _name = 'google.contact' - _columns = { - 'user': fields.char('Login', size=64, required=True,), - 'password': fields.char('Password', size=64,), - } - def get_contact(self, cr, uid, ids, context): - # Only see the result , we will change the code - for obj in self.browse(cr, uid, ids, context=context): - google_obj=google_lib(obj.user,obj.password) - contact=google_obj._get_contact() - while contact: - for i, contact in enumerate(contact.entry): - if contact.title.text: - print contact.title.text - next = contact.GetNextLink() - contact=None - if next: - contact = google_obj._get_contact(next.href) - return {} -google_contact() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_contact/wizard/__init__.py b/addons/google_contact/wizard/__init__.py new file mode 100644 index 00000000000..a7356cede9e --- /dev/null +++ b/addons/google_contact/wizard/__init__.py @@ -0,0 +1,24 @@ +# -*- 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 . +# +############################################################################## + +import google_contact_import + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_contact/wizard/google_contact_import.py b/addons/google_contact/wizard/google_contact_import.py new file mode 100644 index 00000000000..9a398b587da --- /dev/null +++ b/addons/google_contact/wizard/google_contact_import.py @@ -0,0 +1,74 @@ +# -*- 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 _ + +from google_contact import google_contact + +class google_contact_import(osv.osv_memory): + _description ='Google Contact' + _name = 'google.contact.import' + _columns = { + 'user': fields.char('User Name', size=64, required=True), + 'password': fields.char('Password', size=64), + } + + def get_contact(self, cr, uid, ids, context=None): + # Only see the result, we will change the code + addresss_obj = self.pool.get('res.partner.address') + for obj in self.browse(cr, uid, ids, context=context): + google_obj = google_contact.google_lib(obj.user, obj.password) + contact = google_obj._get_contact() + addresses = [] + while contact: + for entry in contact.entry: + 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) + data = { + 'name': name, + 'phone': phone_numbers, + 'email': 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: + break + 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', + } + +google_contact_import() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/google_contact/wizard/google_contact_import_view.xml b/addons/google_contact/wizard/google_contact_import_view.xml new file mode 100644 index 00000000000..5f9f9d98932 --- /dev/null +++ b/addons/google_contact/wizard/google_contact_import_view.xml @@ -0,0 +1,42 @@ + + + + + + google.contact.import.form + google.contact.import + form + +
+ + + + + + +