From 5730c74cb35d55c43cd9983e12df3f02629db8b9 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Wed, 8 Jun 2011 18:20:29 +0530 Subject: [PATCH 01/25] [MERGE]:Merging the google_contact bzr revid: dbr@tinyerp.com-20110608125029-gbv6z7869r3duxnv --- .../wizard/google_contact_import.py | 213 +++--------------- addons/import_google/wizard/import_google.py | 81 +++++++ 2 files changed, 112 insertions(+), 182 deletions(-) diff --git a/addons/import_google/wizard/google_contact_import.py b/addons/import_google/wizard/google_contact_import.py index 8616c363837..f945d243eab 100644 --- a/addons/import_google/wizard/google_contact_import.py +++ b/addons/import_google/wizard/google_contact_import.py @@ -31,14 +31,13 @@ from osv import osv from tools.translate import _ from import_google import import_contact + class google_login_contact(osv.osv_memory): _inherit = 'google.login' _name = 'google.login.contact' - - def _get_next_action(self, cr, uid, context): + def _get_next_action(self, cr, uid, context=None): data_obj = self.pool.get('ir.model.data') data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form') - view_id = False if data_id: view_id = data_obj.browse(cr, uid, data_id, context=context).res_id @@ -54,6 +53,7 @@ class google_login_contact(osv.osv_memory): 'target': 'new', } return value + google_login_contact() class synchronize_google_contact(osv.osv_memory): @@ -88,191 +88,41 @@ class synchronize_google_contact(osv.osv_memory): 'create_partner': 'create_all', 'group_name': 'all', } -# -# def create_partner(self, cr, uid, data={}, context=None): -# if context == None: -# context = {} -# if not data: -# return False -# name = data.get("company") or data.get('name','') -# partner_pool = self.pool.get('res.partner') -# partner_id = partner_pool.create(cr, uid, { -# 'name': name, -# 'user_id': uid, -# 'address' : [(6, 0, [data['address_id']])], -# 'customer': data.get('customer', False), -# 'supplier': data.get('supplier', False) -# }, context=context) -# return partner_id -# -# def set_partner(self, cr, uid, name, address_id, context=None): -# partner_pool = self.pool.get('res.partner') -# partner_ids = partner_pool.search(cr, uid, [('name', '=', name)], context=context) -# if partner_ids: -# address_pool = self.pool.get('res.partner.address')#TODO create partner of find the one with the same name -# data = {'partner_id' : partner_ids[0]} -# address_pool.write(cr, uid, [address_id], data, context=context) -# return partner_ids[0] -# return False def import_contact_all(self, cr, uid, ids, context=None): - tables = ['contact'] obj = self.browse(cr, uid, ids, context=context)[0] + cust = obj.customer + sup = obj.supplier + tables=[] user_obj = self.pool.get('res.users').browse(cr, uid, uid) - google = self.pool.get('google.login') - + gmail_user = user_obj.gmail_user gmail_pwd = user_obj.gmail_password - context = {} + + google = self.pool.get('google.login') gd_client = google.google_login(gmail_user, gmail_pwd, type='contact') - context.update({'user': gmail_user,'password': gmail_pwd,'gd_client':gd_client}) - - imp = import_contact(self, cr, uid,'google', "synchronize_google_contact", context=context) + if not gd_client: + raise osv.except_osv(_('Error'), _("Please specify correct user and password !")) + if obj.group_name not in ['all']: + query = gdata.contacts.service.ContactsQuery() + query.group = obj.group_name + contact = gd_client.GetContactsFeed(query.ToUri()) + else: + contact = gd_client.GetContactsFeed() + if obj.create_partner=='create_all': + tables.append('Contact') + else: + tables.append('Address') + + context.update({'gd_client':contact}) + context.update({'client':gd_client}) + context.update({'table':tables}) + context.update({'customer':cust}) + context.update({'supplier':sup}) + imp = google_import(self, cr, uid, 'google', "synchronize_google_contact", gmail_user, context) imp.set_table_list(tables) - imp.start() - return {'type': 'ir.actions.act_window_close'} -# -# if not gd_client: -# raise osv.except_osv(_('Error'), _("Please specify correct user and password !")) -# -# if obj.group_name not in ['all']: -# query = gdata.contacts.service.ContactsQuery() -# query.group = obj.group_name -# contact = gd_client.GetContactsFeed(query.ToUri()) -# else: -# contact = gd_client.GetContactsFeed() -# -# ids = self.create_contact(cr, uid, ids, gd_client, contact, option=obj.create_partner,context=context) -# if not ids: -# return {'type': 'ir.actions.act_window_close'} -# -# return { -# 'name': _(obj.create_partner =='create_all' and 'Partners') or _('Contacts'), -# 'domain': "[('id','in', ["+','.join(map(str,ids))+"])]", -# 'view_type': 'form', -# 'view_mode': 'tree,form', -# 'res_model': obj.create_partner =='create_all' and 'res.partner' or 'res.partner.address', -# 'context': context, -# 'views': [(False, 'tree'),(False, 'form')], -# 'type': 'ir.actions.act_window', -# } - - -# def create_contact(self, cr, uid, ids, gd_client, contact, option,context=None): -# model_obj = self.pool.get('ir.model.data') -# addresss_obj = self.pool.get('res.partner.address') -# company_pool = self.pool.get('res.company') -# addresses = [] -# partner_ids = [] -# contact_ids = [] -# if 'tz' in context and context['tz']: -# time_zone = context['tz'] -# else: -# time_zone = tools.get_server_timezone() -# au_tz = timezone(time_zone) -# while contact: -# for entry in contact.entry: -# data = self._retreive_data(entry) -# google_id = data.pop('id') -# model_data = { -# 'name': google_id, -# 'model': 'res.partner.address', -# 'module': 'sync_google_contact', -# 'noupdate': True -# } -# -# data_ids = model_obj.search(cr, uid, [('model','=','res.partner.address'), ('name','=', google_id)]) -# if data_ids: -# contact_ids = [model_obj.browse(cr, uid, data_ids[0], context=context).res_id] -# elif data['email']: -# contact_ids = addresss_obj.search(cr, uid, [('email', 'ilike', data['email'])]) -# -# if contact_ids: -# addresses.append(contact_ids[0]) -# 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 -# data.update({'type': 'default'}) -# res_id = addresss_obj.create(cr, uid, data, context=context) -# data['address_id'] = res_id -# if option == 'create_all': -# obj = self.browse(cr, uid, ids, context=context)[0] -# data['customer'] = obj.customer -# data['supplier'] = obj.supplier -# res = False -# if 'company' in data: -# res = self.set_partner(cr, uid, data.get('company'), res_id, context=context) -# if res: -# partner_ids.append(res) -# if not res: -# partner_id = self.create_partner(cr, uid, data, context=context) -# partner_ids.append(partner_id) -# addresses.append(res_id) -# -# if not data_ids: #link to google_id if it was not the case before -# model_data.update({'res_id': res_id}) -# model_obj.create(cr, uid, model_data, context=context) -# -# next = contact.GetNextLink() -# contact = next and gd_client.GetContactsFeed(next.href) or None -# -# if option == 'create_all': -# return partner_ids -# else: -# return addresses - -# def _retreive_data(self, entry): -# data = {} -# data['id'] = entry.id.text -# name = tools.ustr(entry.title.text) -# if name == "None": -# name = entry.email[0].address -# data['name'] = name -# emails = ','.join(email.address for email in entry.email) -# data['email'] = emails -# if entry.organization: -# if entry.organization.org_name: -# data.update({'company': entry.organization.org_name.text}) -# if entry.organization.org_title: -# data.update ({'function': entry.organization.org_title.text}) -# -# -# if entry.phone_number: -# for phone in entry.phone_number: -# if phone.rel == gdata.contacts.REL_WORK: -# data['phone'] = phone.text -# if phone.rel == gdata.contacts.PHONE_MOBILE: -# data['mobile'] = phone.text -# if phone.rel == gdata.contacts.PHONE_WORK_FAX: -# data['fax'] = phone.text -# return data - -# def update_contact(self, cr, uid, contact_ids, data, context=None): -# addresss_obj = self.pool.get('res.partner.address') -# vals = {} -# 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')) -# -# if name != data.get('name'): -# vals['name'] = data.get('name','') -# if addr.email != data.get('email'): -# vals['email'] = data.get('email','') -# if addr.mobile != data.get('mobile'): -# vals['mobile'] = data.get('mobile','') -# if addr.phone != data.get('phone'): -# vals['phone'] = data.get('phone','') -# if addr.fax != data.get('fax'): -# vals['fax'] = data.get('fax','') -# -# addresss_obj.write(cr, uid, contact_ids, vals, context=context) -# return {'type': 'ir.actions.act_window_close'} + imp.start() + return {} synchronize_google_contact() @@ -303,7 +153,6 @@ class google_login_calendar(osv.osv_memory): return value google_login_calendar() - class synchronize_google_calendar_events(osv.osv_memory): """ Wizard to initiate import specific calendar or all calendars @@ -354,7 +203,7 @@ class synchronize_google_calendar_events(osv.osv_memory): 'password': gmail_pwd, 'calendars': calendars, 'instance': 'calendar'}) - imp = import_contact(self, cr, uid, 'import_google', "import_google_calendar", [gmail_user], context) + imp = google_import(self, cr, uid, 'import_google', "import_google_calendar", [gmail_user], context) imp.set_table_list(table) imp.start() return {} diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index 1408662bd4a..97b22200dc0 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -47,6 +47,8 @@ class import_contact(import_framework): def initialize(self): google = self.obj.pool.get('google.login') + self.external_id_field = 'Id' + self.gclient=self.context.get('gd_client', False) self.gd_client = google.google_login(self.context.get('user'), self.context.get('password'), type = self.context.get('instance')) @@ -56,11 +58,14 @@ class import_contact(import_framework): def get_mapping(self): return { self.TABLE_EVENT: self.get_event_mapping(), + self.TABLE_CONTACT: self.get_contact_mapping(), + self.TABLE_ADDRESS: self.get_address_mapping(), } def get_data(self, table): val = { self.TABLE_EVENT: self.get_events(), + self.TABLE_CONTACT: self.get_contact(), } return val.get(table) @@ -257,3 +262,79 @@ class import_contact(import_framework): } } + + def get_contact(self): + contact=self.gclient + gclient=self.context.get('client',False) + datas = [] + while contact: + for entry in contact.entry: + data = {} + data['id'] = entry.id.text + name = tools.ustr(entry.title.text) + if name == "None": + name = entry.email[0].address + data['name'] = name + emails = ','.join(email.address for email in entry.email) + data['email'] = emails + if entry.organization: + if entry.organization.org_name: + data.update({'company': entry.organization.org_name.text}) + if entry.organization.org_title: + data.update ({'function': entry.organization.org_title.text}) + if entry.phone_number: + for phone in entry.phone_number: + if phone.rel == gdata.contacts.REL_WORK: + data['phone'] = phone.text + if phone.rel == gdata.contacts.PHONE_MOBILE: + data['mobile'] = phone.text + if phone.rel == gdata.contacts.PHONE_WORK_FAX: + data['fax'] = phone.text + datas.append(data) + next = contact.GetNextLink() + contact = next and gclient.GetContactsFeed(next.href) or None + return datas + + + def get_partner_address(self,val): + field_map = { + 'name': 'name', + 'type': 'Type', + 'city': 'city', + 'phone': 'phone', + 'mobile': 'mobile', + 'email': 'email', + 'fax': 'fax', + } + val.update({'Type':'contact'}) + val.update({'id_new': val['id']+'address_contact' }) + return self.import_object_mapping(field_map , val, 'res.partner.address', self.context.get('table')[0], val['id_new'], self.DO_NOT_FIND_DOMAIN) + + def get_contact_mapping(self): + return { + 'model': 'res.partner', + 'dependencies': [], + 'map': { + 'name': 'name', + 'customer': str(self.context.get('customer')), + 'supplier': str(self.context.get('supplier')), + 'address/id': self.get_partner_address, + } + } + + def get_address_mapping(self): + print"RRRRRRRRRREEElated to Address ONLY......................" + return { + 'model': 'res.partner.address', + 'dependencies': [], + 'map': { + 'name': 'name', + 'city': 'city', + 'phone': 'phone', + 'mobile': 'mobile', + 'email': 'email', + 'fax': 'fax' + } + + } + \ No newline at end of file From c99804865035669628f8d6f9a46ed7b299c259c8 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Wed, 8 Jun 2011 18:31:17 +0530 Subject: [PATCH 02/25] [MERGE]:change the class name bzr revid: dbr@tinyerp.com-20110608130117-at23f0wvvrt7ugml --- addons/import_google/wizard/google_contact_import.py | 4 ++-- addons/import_google/wizard/import_google.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/import_google/wizard/google_contact_import.py b/addons/import_google/wizard/google_contact_import.py index f945d243eab..db59714ac6b 100644 --- a/addons/import_google/wizard/google_contact_import.py +++ b/addons/import_google/wizard/google_contact_import.py @@ -29,7 +29,7 @@ except ImportError: from osv import fields from osv import osv from tools.translate import _ -from import_google import import_contact +from import_google import google_import class google_login_contact(osv.osv_memory): @@ -89,7 +89,7 @@ class synchronize_google_contact(osv.osv_memory): 'group_name': 'all', } - def import_contact_all(self, cr, uid, ids, context=None): + def import_contact(self, cr, uid, ids, context=None): obj = self.browse(cr, uid, ids, context=context)[0] cust = obj.customer sup = obj.supplier diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index 97b22200dc0..af264bcdedd 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -37,7 +37,7 @@ except ImportError: from import_base.import_framework import * from import_base.mapper import * -class import_contact(import_framework): +class google_import(import_framework): gd_client = False calendars = False @@ -323,7 +323,6 @@ class import_contact(import_framework): } def get_address_mapping(self): - print"RRRRRRRRRREEElated to Address ONLY......................" return { 'model': 'res.partner.address', 'dependencies': [], @@ -337,4 +336,4 @@ class import_contact(import_framework): } } - \ No newline at end of file + From ff45483f72583e420a6c9a5f92fd3115c96116e5 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Wed, 8 Jun 2011 19:01:39 +0530 Subject: [PATCH 03/25] [IMP]:Change in get_data bzr revid: dbr@tinyerp.com-20110608133139-g5n8uy1z58nda07c --- addons/import_google/wizard/import_google.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index af264bcdedd..31655da0025 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -42,7 +42,8 @@ class google_import(import_framework): gd_client = False calendars = False DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" - TABLE_CONTACT = 'contact' + TABLE_CONTACT = 'Contact' + TABLE_ADDRESS ='Address' TABLE_EVENT = 'Events' def initialize(self): @@ -63,10 +64,14 @@ class google_import(import_framework): } def get_data(self, table): - val = { - self.TABLE_EVENT: self.get_events(), - self.TABLE_CONTACT: self.get_contact(), - } + if table == "Contact" or table == "Address": + val = { + self.TABLE_CONTACT: self.get_contact(), + } + elif table == "Events": + val = { + self.TABLE_EVENT: self.get_events(), + } return val.get(table) From c6a69ccaf5ad847848a6bd9e1e765f3ae8bbfe06 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Thu, 9 Jun 2011 16:25:57 +0530 Subject: [PATCH 04/25] [IMP]:change in google_contact bzr revid: dbr@tinyerp.com-20110609105557-y4dkp2avrzl9zodt --- addons/import_base/import_framework.py | 5 ----- addons/import_google/wizard/import_google.py | 8 ++++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/import_base/import_framework.py b/addons/import_base/import_framework.py index 8994e1568e6..8e930828206 100644 --- a/addons/import_base/import_framework.py +++ b/addons/import_base/import_framework.py @@ -346,11 +346,6 @@ class import_framework(Thread): result = [] imported = set() #to invoid importing 2 times the sames modules for table in self.table_list: -# try: -# to_import = self.get_mapping()[table].get('import', True) -# except: -# import traceback,sys -# info = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) to_import = self.get_mapping()[table].get('import', True) if not table in imported: res = self._resolve_dependencies(self.get_mapping()[table].get('dependencies', []), imported) diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index 31655da0025..9f6358aed21 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -271,6 +271,7 @@ class google_import(import_framework): def get_contact(self): contact=self.gclient gclient=self.context.get('client',False) + table = self.context.get('table')[0] datas = [] while contact: for entry in contact.entry: @@ -282,6 +283,9 @@ class google_import(import_framework): data['name'] = name emails = ','.join(email.address for email in entry.email) data['email'] = emails + if table == 'Contact': + data.update({'customer': str(self.context.get('customer')), + 'supplier': str(self.context.get('supplier'))}) if entry.organization: if entry.organization.org_name: data.update({'company': entry.organization.org_name.text}) @@ -321,8 +325,8 @@ class google_import(import_framework): 'dependencies': [], 'map': { 'name': 'name', - 'customer': str(self.context.get('customer')), - 'supplier': str(self.context.get('supplier')), + 'customer': 'customer', + 'supplier': 'supplier', 'address/id': self.get_partner_address, } } From 62d3359c14cc742aae2de7ee4062b85356100562 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Fri, 10 Jun 2011 13:19:30 +0530 Subject: [PATCH 05/25] [IMP]: Imp for company details bzr revid: dbr@tinyerp.com-20110610074930-gxmiaqtzpt8evjph --- addons/import_google/wizard/import_google.py | 64 ++++++++++++++------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index 9f6358aed21..b5073199fb5 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -275,6 +275,7 @@ class google_import(import_framework): datas = [] while contact: for entry in contact.entry: + data = {} data['id'] = entry.id.text name = tools.ustr(entry.title.text) @@ -298,32 +299,59 @@ class google_import(import_framework): if phone.rel == gdata.contacts.PHONE_MOBILE: data['mobile'] = phone.text if phone.rel == gdata.contacts.PHONE_WORK_FAX: - data['fax'] = phone.text + data['fax'] = phone.text datas.append(data) next = contact.GetNextLink() contact = next and gclient.GetContactsFeed(next.href) or None return datas - + + def get_partner_address1(self, val): + partner_id = False + address_pool = self.obj.pool.get('res.partner.address') + company_pool = self.obj.pool.get('res.company') + if 'company' in val: + cids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))]) + if cids: + records = company_pool.browse(self.cr, self.uid, cids) + for rec in records: + if rec.partner_id: + partner_id = rec.partner_id + return partner_id + contact = self.xml_id_exist(self.TABLE_PARTNER, val.get('id')) + if contact: + partner_id = self.get_mapped_id(self.TABLE_PARTNER, val.get('id')) + return partner_id def get_partner_address(self,val): - field_map = { - 'name': 'name', - 'type': 'Type', - 'city': 'city', - 'phone': 'phone', - 'mobile': 'mobile', - 'email': 'email', - 'fax': 'fax', - } - val.update({'Type':'contact'}) - val.update({'id_new': val['id']+'address_contact' }) - return self.import_object_mapping(field_map , val, 'res.partner.address', self.context.get('table')[0], val['id_new'], self.DO_NOT_FIND_DOMAIN) + partner_id = False + address_pool = self.obj.pool.get('res.partner.address') + company_pool = self.obj.pool.get('res.company') + if 'company' in val: + cids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))]) + if cids: + records = company_pool.browse(self.cr, self.uid, cids) + for rec in records: + if rec.partner_id: + partner_id = rec.partner_id + field_map = { + 'name': 'name', + 'type': 'Type', + 'city': 'city', + 'phone': 'phone', + 'mobile': 'mobile', + 'email': 'email', + 'fax': 'fax', + } + val.update({'Type':'contact'}) + val.update({'id_new': val['id']+'address_contact' }) + return self.import_object_mapping(field_map , val, 'res.partner.address', self.context.get('table')[0], val['id_new'], self.DO_NOT_FIND_DOMAIN) def get_contact_mapping(self): return { 'model': 'res.partner', 'dependencies': [], 'map': { + 'id':'id', 'name': 'name', 'customer': 'customer', 'supplier': 'supplier', @@ -336,13 +364,15 @@ class google_import(import_framework): 'model': 'res.partner.address', 'dependencies': [], 'map': { - 'name': 'name', + 'id':'id', + 'name': 'name', 'city': 'city', 'phone': 'phone', 'mobile': 'mobile', 'email': 'email', - 'fax': 'fax' + 'fax': 'fax', + 'function': 'function' } } - + From 9feb8f173c00f49600a5f0ebc9db02d588a2a3d3 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Fri, 10 Jun 2011 14:24:48 +0530 Subject: [PATCH 06/25] [IMP]: Remove extra function bzr revid: dbr@tinyerp.com-20110610085448-zrz4k56lhd94qsxb --- addons/import_google/wizard/import_google.py | 23 +++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/addons/import_google/wizard/import_google.py b/addons/import_google/wizard/import_google.py index b5073199fb5..b4c0a69bea8 100644 --- a/addons/import_google/wizard/import_google.py +++ b/addons/import_google/wizard/import_google.py @@ -64,10 +64,14 @@ class google_import(import_framework): } def get_data(self, table): - if table == "Contact" or table == "Address": + if table == "Contact": val = { self.TABLE_CONTACT: self.get_contact(), } + if table == "Address": + val = { + self.TABLE_ADDRESS: self.get_contact(), + } elif table == "Events": val = { self.TABLE_EVENT: self.get_events(), @@ -305,23 +309,6 @@ class google_import(import_framework): contact = next and gclient.GetContactsFeed(next.href) or None return datas - def get_partner_address1(self, val): - partner_id = False - address_pool = self.obj.pool.get('res.partner.address') - company_pool = self.obj.pool.get('res.company') - if 'company' in val: - cids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))]) - if cids: - records = company_pool.browse(self.cr, self.uid, cids) - for rec in records: - if rec.partner_id: - partner_id = rec.partner_id - return partner_id - contact = self.xml_id_exist(self.TABLE_PARTNER, val.get('id')) - if contact: - partner_id = self.get_mapped_id(self.TABLE_PARTNER, val.get('id')) - return partner_id - def get_partner_address(self,val): partner_id = False address_pool = self.obj.pool.get('res.partner.address') From a77c1649edf95c74b1cdd42bd191fe9a40930ae9 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 11:32:15 +0530 Subject: [PATCH 07/25] Import_google:[IMP] remove unused code and merge the action code bzr revid: dbr@tinyerp.com-20110613060215-kih9rmzu9de0letu --- addons/import_google/__openerp__.py | 2 +- .../wizard/google_contact_import.py | 85 ++++++------------- .../wizard/google_contact_import_view.xml | 6 +- 3 files changed, 30 insertions(+), 63 deletions(-) diff --git a/addons/import_google/__openerp__.py b/addons/import_google/__openerp__.py index d76c0a32831..462e07c5cb4 100644 --- a/addons/import_google/__openerp__.py +++ b/addons/import_google/__openerp__.py @@ -36,7 +36,7 @@ 'test': [ # 'test/test_sync_google_contact_import_partner.yml', # 'test/test_sync_google_contact_import_address.yml', - 'test/test_sync_google_calendar.yml', +# 'test/test_sync_google_calendar.yml', ], 'installable': True, 'active': False, diff --git a/addons/import_google/wizard/google_contact_import.py b/addons/import_google/wizard/google_contact_import.py index db59714ac6b..6c3bea47f21 100644 --- a/addons/import_google/wizard/google_contact_import.py +++ b/addons/import_google/wizard/google_contact_import.py @@ -34,15 +34,20 @@ from import_google import google_import class google_login_contact(osv.osv_memory): _inherit = 'google.login' - _name = 'google.login.contact' + _name = 'google.login' + def _get_next_action(self, cr, uid, context=None): data_obj = self.pool.get('ir.model.data') data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form') view_id = False + if context.get('contact'): + data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form') + if context.get('calendar'): + data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_calendar_import_form') if data_id: view_id = data_obj.browse(cr, uid, data_id, context=context).res_id value = { - 'name': _('Import Contact'), + 'name': _('Import google'), 'view_type': 'form', 'view_mode': 'form,tree', 'res_model': 'synchronize.google.contact.import', @@ -77,16 +82,32 @@ class synchronize_google_contact(osv.osv_memory): res.append(('all','All Groups')) return res + def _get_calendars(self, cr, uid, context=None): + user_obj = self.pool.get('res.users').browse(cr, uid, uid) + google = self.pool.get('google.login') + res = [] + try: + gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar') + calendars = gd_client.GetAllCalendarsFeed() + for cal in calendars.entry: + res.append((cal.id.text, cal.title.text)) + except Exception, e: + raise osv.except_osv('Error !', e.args[0].get('body')) + res.append(('all', 'All Calendars')) + return res + _columns = { 'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'), 'customer': fields.boolean('Customer', help="Check this box to set newly created partner as Customer."), 'supplier': fields.boolean('Supplier', help="Check this box to set newly created partner as Supplier."), 'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."), + 'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32), } _defaults = { 'create_partner': 'create_all', 'group_name': 'all', + 'calendar_name': 'all', } def import_contact(self, cr, uid, ids, context=None): @@ -124,63 +145,6 @@ class synchronize_google_contact(osv.osv_memory): imp.start() return {} -synchronize_google_contact() - - -class google_login_calendar(osv.osv_memory): - """Gdata Login Object for Google Calendar Import""" - _inherit = 'google.login' - _name = 'google.login' - - def _get_next_action(self, cr, uid, context): - data_obj = self.pool.get('ir.model.data') - data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_calendar_import_form') - - view_id = False - if data_id: - view_id = data_obj.browse(cr, uid, data_id, context=context).res_id - value = { - 'name': _('Import Events'), - 'view_type': 'form', - 'view_mode': 'form,tree', - 'res_model': 'synchronize.google.calendar', - 'view_id': False, - 'context': context, - 'views': [(view_id, 'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - } - return value -google_login_calendar() - -class synchronize_google_calendar_events(osv.osv_memory): - """ - Wizard to initiate import specific calendar or all calendars - """ - _name = 'synchronize.google.calendar' - - def _get_calendars(self, cr, uid, context=None): - user_obj = self.pool.get('res.users').browse(cr, uid, uid) - google = self.pool.get('google.login') - res = [] - try: - gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar') - calendars = gd_client.GetAllCalendarsFeed() - for cal in calendars.entry: - res.append((cal.id.text, cal.title.text)) - except Exception, e: - raise osv.except_osv('Error !', e.args[0].get('body')) - res.append(('all', 'All Calendars')) - return res - - _columns = { - 'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32), - } - - _defaults = { - 'calendar_name': 'all', - } - def import_calendar_events(self, cr, uid, ids, context=None): if context == None: context = {} @@ -207,6 +171,7 @@ class synchronize_google_calendar_events(osv.osv_memory): imp.set_table_list(table) imp.start() return {} + +synchronize_google_contact() -synchronize_google_calendar_events() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/wizard/google_contact_import_view.xml b/addons/import_google/wizard/google_contact_import_view.xml index c5f2b9c0bb7..cc044554b31 100644 --- a/addons/import_google/wizard/google_contact_import_view.xml +++ b/addons/import_google/wizard/google_contact_import_view.xml @@ -34,7 +34,7 @@ synchronize.google.calendar.form - synchronize.google.calendar + synchronize.google.contact.import form
@@ -62,16 +62,18 @@ form form new + {'calendar':True} Import Google Contacts ir.actions.act_window - google.login.contact + google.login form form new + {'contact':True} From 8ae2663f12b48eb0c7203f03ef2b8461815245b0 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 11:39:00 +0530 Subject: [PATCH 08/25] [REF]import_google: rename the file bzr revid: dbr@tinyerp.com-20110613060900-v7h2gzp14ao36j7a --- addons/import_google/__init__.py | 2 +- .../{import_google_contact.py => import_google_data.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename addons/import_google/{import_google_contact.py => import_google_data.py} (100%) diff --git a/addons/import_google/__init__.py b/addons/import_google/__init__.py index 1889d262ff8..0967b82e0b7 100644 --- a/addons/import_google/__init__.py +++ b/addons/import_google/__init__.py @@ -19,7 +19,7 @@ # ############################################################################## -import import_google_contact +import import_google_data import sync_google_calendar import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/import_google_contact.py b/addons/import_google/import_google_data.py similarity index 100% rename from addons/import_google/import_google_contact.py rename to addons/import_google/import_google_data.py From 0baaa4ea17ff540ca4746f592e5df12ff4bef0d4 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 11:46:48 +0530 Subject: [PATCH 09/25] [REMOVE]import_google: remove the file and merge the code bzr revid: dbr@tinyerp.com-20110613061648-oo35e030m88skywj --- addons/import_google/__init__.py | 1 - addons/import_google/import_google_data.py | 7 ++++ addons/import_google/sync_google_calendar.py | 37 -------------------- 3 files changed, 7 insertions(+), 38 deletions(-) delete mode 100644 addons/import_google/sync_google_calendar.py diff --git a/addons/import_google/__init__.py b/addons/import_google/__init__.py index 0967b82e0b7..bdd83a09208 100644 --- a/addons/import_google/__init__.py +++ b/addons/import_google/__init__.py @@ -20,6 +20,5 @@ ############################################################################## import import_google_data -import sync_google_calendar import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/import_google_data.py b/addons/import_google/import_google_data.py index 1c00a67cd52..b7c640a7850 100644 --- a/addons/import_google/import_google_data.py +++ b/addons/import_google/import_google_data.py @@ -36,4 +36,11 @@ class res_partner_address(osv.osv): res_partner_address() +class crm_case_categ(osv.osv): + """ Category of Case """ + _inherit = "crm.case.categ" + _columns = { + 'user_id': fields.many2one('res.users', 'User') + } +crm_case_categ() # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/sync_google_calendar.py b/addons/import_google/sync_google_calendar.py deleted file mode 100644 index a8807d355bb..00000000000 --- a/addons/import_google/sync_google_calendar.py +++ /dev/null @@ -1,37 +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 osv, fields - -class crm_meeting(osv.osv): - _inherit = "crm.meeting" - -crm_meeting() - -class crm_case_categ(osv.osv): - """ Category of Case """ - _inherit = "crm.case.categ" - _columns = { - 'user_id': fields.many2one('res.users', 'User') - } -crm_case_categ() - -# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: From 2c6023b559af79d655efa1b45476f0b631cda6d8 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 12:08:39 +0530 Subject: [PATCH 10/25] [REF]import_google: rename the file bzr revid: dbr@tinyerp.com-20110613063839-zy27ck9t21j6sjdh --- addons/import_google/{import_google_data.py => partner.py} | 0 .../wizard/{google_contact_import.py => import_google_data.py} | 0 ...google_contact_import_view.xml => import_google_data_view.xml} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename addons/import_google/{import_google_data.py => partner.py} (100%) rename addons/import_google/wizard/{google_contact_import.py => import_google_data.py} (100%) rename addons/import_google/wizard/{google_contact_import_view.xml => import_google_data_view.xml} (100%) diff --git a/addons/import_google/import_google_data.py b/addons/import_google/partner.py similarity index 100% rename from addons/import_google/import_google_data.py rename to addons/import_google/partner.py diff --git a/addons/import_google/wizard/google_contact_import.py b/addons/import_google/wizard/import_google_data.py similarity index 100% rename from addons/import_google/wizard/google_contact_import.py rename to addons/import_google/wizard/import_google_data.py diff --git a/addons/import_google/wizard/google_contact_import_view.xml b/addons/import_google/wizard/import_google_data_view.xml similarity index 100% rename from addons/import_google/wizard/google_contact_import_view.xml rename to addons/import_google/wizard/import_google_data_view.xml From 1737deabb14457eaf0ec45c9063e44ce8b532a5d Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 12:17:58 +0530 Subject: [PATCH 11/25] [IMP]import_google bzr revid: dbr@tinyerp.com-20110613064758-bezxriw47gujgen5 --- addons/import_google/__init__.py | 2 +- addons/import_google/__openerp__.py | 2 +- addons/import_google/wizard/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/import_google/__init__.py b/addons/import_google/__init__.py index bdd83a09208..7ca8ce67ab3 100644 --- a/addons/import_google/__init__.py +++ b/addons/import_google/__init__.py @@ -19,6 +19,6 @@ # ############################################################################## -import import_google_data +import partner import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/__openerp__.py b/addons/import_google/__openerp__.py index 462e07c5cb4..9c468bf5609 100644 --- a/addons/import_google/__openerp__.py +++ b/addons/import_google/__openerp__.py @@ -30,7 +30,7 @@ 'init_xml': [], 'update_xml': [ 'sync_google_calendar_view.xml', - 'wizard/google_contact_import_view.xml', + 'wizard/import_google_data_view.xml', ], 'demo_xml': [], 'test': [ diff --git a/addons/import_google/wizard/__init__.py b/addons/import_google/wizard/__init__.py index a36445eebaa..233409a111e 100644 --- a/addons/import_google/wizard/__init__.py +++ b/addons/import_google/wizard/__init__.py @@ -19,5 +19,5 @@ # ############################################################################## import import_google -import google_contact_import +import import_google_data # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 0e588677ed41d9a56994de5ca1b59a195176b45a Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Mon, 13 Jun 2011 12:40:42 +0530 Subject: [PATCH 12/25] [ADD]import_google: Add two files bzr revid: dbr@tinyerp.com-20110613071042-b1zp3enejqip7z5p --- addons/crm/crm_installer.py | 2 +- addons/import_google/__openerp__.py | 1 + addons/import_google/wizard/__init__.py | 1 + .../wizard/google_import_message.py | 42 +++++++++++++++++++ .../wizard/google_import_message_view.xml | 25 +++++++++++ .../wizard/import_google_data.py | 30 ++++++++++++- 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 addons/import_google/wizard/google_import_message.py create mode 100644 addons/import_google/wizard/google_import_message_view.xml diff --git a/addons/crm/crm_installer.py b/addons/crm/crm_installer.py index b1a1ff0fe18..f48526b6846 100644 --- a/addons/crm/crm_installer.py +++ b/addons/crm/crm_installer.py @@ -37,7 +37,7 @@ class crm_installer(osv.osv_memory): 'thunderbird': fields.boolean('Thunderbird', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."), 'outlook': fields.boolean('MS-Outlook', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."), 'wiki_sale_faq': fields.boolean('Sale FAQ', help="Helps you manage wiki pages for Frequently Asked Questions on Sales Application."), - 'import_google': fields.boolean('Google Contacts', help="Imports contacts from your google account."), + 'import_google': fields.boolean('Google Import', help="Imports contacts from your google account."), } def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): diff --git a/addons/import_google/__openerp__.py b/addons/import_google/__openerp__.py index 9c468bf5609..003d9c9acb5 100644 --- a/addons/import_google/__openerp__.py +++ b/addons/import_google/__openerp__.py @@ -31,6 +31,7 @@ 'update_xml': [ 'sync_google_calendar_view.xml', 'wizard/import_google_data_view.xml', + 'wizard/google_import_message_view.xml' ], 'demo_xml': [], 'test': [ diff --git a/addons/import_google/wizard/__init__.py b/addons/import_google/wizard/__init__.py index 233409a111e..41c118a0ef3 100644 --- a/addons/import_google/wizard/__init__.py +++ b/addons/import_google/wizard/__init__.py @@ -20,4 +20,5 @@ ############################################################################## import import_google import import_google_data +import google_import_message # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/import_google/wizard/google_import_message.py b/addons/import_google/wizard/google_import_message.py new file mode 100644 index 00000000000..5e2b2b6f4b1 --- /dev/null +++ b/addons/import_google/wizard/google_import_message.py @@ -0,0 +1,42 @@ +# -*- 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 osv +from osv import fields + + +class google_import_message(osv.osv): + """Import Message""" + + _name = "google.import.message" + _description = "Import Message" + _columns = { + 'name': fields.text('Message', readonly=True), + } + + def default_get(self, cr, uid, fields, context=None): + if context == None: + context = {} + res = super(google_import_message, self).default_get(cr, uid, fields, context=context) + res.update({'name': context.get('message')}) + return res + +google_import_message() diff --git a/addons/import_google/wizard/google_import_message_view.xml b/addons/import_google/wizard/google_import_message_view.xml new file mode 100644 index 00000000000..639f3da16bd --- /dev/null +++ b/addons/import_google/wizard/google_import_message_view.xml @@ -0,0 +1,25 @@ + + + + + + google.import.message.form + google.import.message + form + + + + + + + + + +