diff --git a/addons/google_base_account/google_base_account.py b/addons/google_base_account/google_base_account.py index 3b98bb37513..c1642730e24 100644 --- a/addons/google_base_account/google_base_account.py +++ b/addons/google_base_account/google_base_account.py @@ -20,7 +20,6 @@ ############################################################################## from osv import fields,osv,orm - class res_users(osv.osv): _inherit = "res.users" @@ -30,14 +29,14 @@ class res_users(osv.osv): } 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: diff --git a/addons/sync_base/wizard/sync_base_view.xml b/addons/sync_base/wizard/sync_base_view.xml index 2e348b0beec..6f61e0b6855 100644 --- a/addons/sync_base/wizard/sync_base_view.xml +++ b/addons/sync_base/wizard/sync_base_view.xml @@ -19,7 +19,7 @@ - Import contacts from remote adress book + Import contacts from remote address book ir.actions.act_window synchronize.base.contact.wizard.import form @@ -29,7 +29,7 @@ - diff --git a/addons/sync_google_contact/__init__.py b/addons/sync_google_contact/__init__.py index f8a7a810426..202f8f989f2 100644 --- a/addons/sync_google_contact/__init__.py +++ b/addons/sync_google_contact/__init__.py @@ -19,6 +19,7 @@ # ############################################################################## +import sync_google_contact import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sync_google_contact/sync_google_contact.py b/addons/sync_google_contact/sync_google_contact.py new file mode 100644 index 00000000000..9e580af9f6b --- /dev/null +++ b/addons/sync_google_contact/sync_google_contact.py @@ -0,0 +1,35 @@ +# -*- 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 + +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: diff --git a/addons/sync_google_contact/wizard/google_contact_import.py b/addons/sync_google_contact/wizard/google_contact_import.py index 941ffa0e4d9..b6e85bbcd96 100644 --- a/addons/sync_google_contact/wizard/google_contact_import.py +++ b/addons/sync_google_contact/wizard/google_contact_import.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 L (). +# 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 @@ -24,11 +24,9 @@ from tools.translate import _ 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 @@ class google_base_import(osv.osv_memory): 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 @@ class synchronize_google_contact(osv.osv_memory): 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 @@ class synchronize_google_contact(osv.osv_memory): 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 @@ class synchronize_google_contact(osv.osv_memory): 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 @@ class synchronize_google_contact(osv.osv_memory): 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