openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #05513
lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm-import_meetings_calls_emails-atp into lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm
Atul Patel(OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm-import_meetings_calls_emails-atp into lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm.
Requested reviews:
Bhumika (OpenERP) (sbh-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_sugarcrm-import_meetings_calls_emails-atp/+merge/57811
Hello,
1) Import SugarCRM Meetings into Crm Meetings.
2) Import SugarCRM Calls into Crm Phonecalls with inbound and outbound Type.
3) Import SugarCRM Emails into Emails/Messages.
4) Import SugarCRM Projects and Projects Tasks into Projects.
5) Import Tasks into Crm Meeting with 'Tasks' type.
Thanks.
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_sugarcrm-import_meetings_calls_emails-atp/+merge/57811
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm.
=== modified file 'import_sugarcrm/__openerp__.py'
--- import_sugarcrm/__openerp__.py 2011-04-01 05:45:46 +0000
+++ import_sugarcrm/__openerp__.py 2011-04-15 06:23:37 +0000
@@ -24,10 +24,10 @@
'version': '1.0',
'category': 'Generic Modules',
'description': """This Module Import SugarCRM "Leads", "Opportunities", "Users", "Accounts",
- "Contacts" and "Employees" Data into OpenERP Module.""",
+ "Contacts", "Employees", Meetings, Phonecalls, Emails, and Project, Project Tasks Data into OpenERP Module.""",
'author': 'OpenERP SA',
'website': 'http://www.openerp.com',
- 'depends': ['crm', 'hr'],
+ 'depends': ['project_timesheet', 'project_issue'],
'init_xml': [],
'update_xml': ["wizard/sugarcrm_login_view.xml",
"wizard/import_message_view.xml",
=== modified file 'import_sugarcrm/import_sugarcrm.py'
--- import_sugarcrm/import_sugarcrm.py 2011-04-08 06:29:45 +0000
+++ import_sugarcrm/import_sugarcrm.py 2011-04-15 06:23:37 +0000
@@ -63,6 +63,7 @@
else:
state_id = res_country_state_obj.create(cr, uid, {'name': sugar_val, 'code': sugar_val, 'country_id': country_id})
return state_id
+
def get_all_countries(sugar_obj, cr, uid, sugar_country_val, context=None):
"""Get Country or Create new country"""
res_country_obj = sugar_obj.pool.get('res.country')
@@ -89,17 +90,18 @@
'street': 'primary_address_street',
'zip': 'primary_address_postalcode',
'city': 'primary_address_city',
- 'country_id/.id': 'country_id/.id',
- 'state_id/.id': 'state_id/id'
+ 'country_id.id': 'country_id.id',
+ 'state_id.id': 'state_id.id'
}
address_obj = sugar_obj.pool.get('res.partner.address')
PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
sugar_data = sugar.search(PortType, sessionid, 'Contacts')
for val in sugar_data:
- country_id = get_all_countries(sugar_obj, cr, uid, val.get('primary_address_country'), context)
- state = get_all_states(sugar_obj,cr, uid, val.get('primary_address_state'), country_id, context)
- val['country_id/.id'] = country_id
- val['state_id/.id'] = state
+ if val.get('primary_address_country'):
+ country_id = get_all_countries(sugar_obj, cr, uid, val.get('primary_address_country'), context)
+ state = get_all_states(sugar_obj,cr, uid, val.get('primary_address_state'), country_id, context)
+ val['country_id.id'] = country_id
+ val['state_id.id'] = state
fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_partner_address)
address_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
return True
@@ -123,7 +125,6 @@
map_user = {'id' : 'id',
'name': ['first_name', 'last_name'],
'login': 'user_name',
-
'context_lang' : 'context_lang',
'password' : 'password',
'.id' : '.id',
@@ -210,11 +211,12 @@
'street': 'address_street',
'zip': 'address_postalcode',
}
- address_ids = address_obj.search(cr, uid, [('name', '=',val.get('first_name') +''+ val.get('last_name'))])
- country_id = get_all_countries(sugar_obj, cr, uid, val.get('address_country'), context)
- state_id = get_all_states(sugar_obj, cr, uid, val.get('address_state'), country_id, context)
- val['country_id'] = country_id
- val['state_id'] = state_id
+ address_ids = address_obj.search(cr, uid, [('name', 'like', val.get('first_name') +' '+ val.get('last_name'))])
+ if val.get('address_country'):
+ country_id = get_all_countries(sugar_obj, cr, uid, val.get('address_country'), context)
+ state_id = get_all_states(sugar_obj, cr, uid, val.get('address_state'), country_id, context)
+ val['country_id'] = country_id
+ val['state_id'] = state_id
fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_user_address)
dict_val = dict(zip(fields,datas))
if address_ids:
@@ -240,10 +242,11 @@
'type': 'type',
})
val['type'] = type
- country_id = get_all_countries(sugar_obj, cr, uid, val.get(type_address +'_address_country'), context)
- state = get_all_states(sugar_obj, cr, uid, val.get(type_address +'_address_state'), country_id, context)
- val['country_id'] = country_id
- val['state_id'] = state
+ if val.get(type_address +'_address_country'):
+ country_id = get_all_countries(sugar_obj, cr, uid, val.get(type_address +'_address_country'), context)
+ state = get_all_states(sugar_obj, cr, uid, val.get(type_address +'_address_state'), country_id, context)
+ val['country_id'] = country_id
+ val['state_id'] = state
fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_partner_address)
#Convert To list into Dictionary(Key, val). value pair.
dict_val = dict(zip(fields,datas))
@@ -306,7 +309,246 @@
address_obj.write(cr,uid,address.id,{'partner_id':data_id[0]})
return True
-
+def get_category(sugar_obj, cr, uid, model, name, context=None):
+ categ_id = False
+ categ_obj = sugar_obj.pool.get('crm.case.categ')
+ categ_ids = categ_obj.search(cr, uid, [('object_id.model','=',model), ('name', 'like', name)] )
+ if categ_ids:
+ categ_id = categ_ids[0]
+ else:
+ categ_id = categ_obj.create(cr, uid, {'name': name, 'object_id.model': model})
+ return categ_id
+
+def get_alarm_id(sugar_obj, cr, uid, val, context=None):
+
+ alarm_dict = {'60': '1 minute before',
+ '300': '5 minutes before',
+ '600': '10 minutes before',
+ '900': '15 minutes before',
+ '1800':'30 minutes before',
+ '3600': '1 hour before',
+ }
+ alarm_id = False
+ alarm_obj = sugar_obj.pool.get('res.alarm')
+ if alarm_dict.get(val):
+ alarm_ids = alarm_obj.search(cr, uid, [('name', 'like', alarm_dict.get(val))])
+ for alarm in alarm_obj.browse(cr, uid, alarm_ids, context):
+ alarm_id = alarm.id
+ return alarm_id
+
+def get_meeting_state(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm stage : openerp meeting stage
+ 'Planned' : 'draft',
+ 'Held':'open',
+ 'Not Held': 'draft',
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def get_task_state(sugar_obj, cr, uid, val, context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm stage : openerp meeting stage
+ 'Completed' : 'done',
+ 'Not Started':'draft',
+ 'In Progress': 'open',
+ 'Pending Input': 'draft',
+ 'deferred': 'cancel'
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def get_project_state(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm staus : openerp Projects state
+ 'Draft' : 'draft',
+ 'In Review': 'open',
+ 'Published': 'close',
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def get_project_task_state(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm status : openerp Porject Tasks state
+ 'Not Started': 'draft',
+ 'In Progress': 'open',
+ 'Completed': 'done',
+ 'Pending Input': 'pending',
+ 'Deferred': 'cancelled',
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def get_project_task_priority(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ priority = False
+ priority_dict = {'priority': #field in the sugarcrm database
+ { #Mapping of sugarcrm status : openerp Porject Tasks state
+ 'High': '0',
+ 'Medium': '2',
+ 'Low': '3'
+ },}
+ priority = priority_dict['priority'].get(val, '')
+ return priority
+
+
+def get_account(sugar_obj, cr, uid, val, context=None):
+ if not context:
+ context = {}
+ partner_id = False
+ partner_address_id = False
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ address_obj = sugar_obj.pool.get('res.partner.address')
+ if val.get('parent_type') == 'Accounts':
+ model_ids = model_obj.search(cr, uid, [('name', '=', val.get('parent_id')), ('model', '=', 'res.partner')])
+ if model_ids:
+ model = model_obj.browse(cr, uid, model_ids)[0]
+ partner_id = model.res_id
+ address_ids = address_obj.search(cr, uid, [('partner_id', '=', partner_id)])
+ partner_address_id = address_ids and address_ids[0]
+
+ if val.get('parent_type') == 'Contacts':
+ model_ids = model_obj.search(cr, uid, [('name', '=', val.get('parent_id')), ('model', '=', 'res.partner.address')])
+ for model in model_obj.browse(cr, uid, model_ids):
+ partner_address_id = model.res_id
+ address_id = address_obj.browse(cr, uid, partner_address_id)
+ partner_id = address_id and address_id.partner_id or False
+ return partner_id, partner_address_id
+
+def import_tasks(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_task = {'id' : 'id',
+ 'name': 'name',
+ 'date': 'date_entered',
+ 'user_id/id': 'assigned_user_id',
+ 'categ_id/.id': 'categ_id/.id',
+ 'partner_id/.id': 'partner_id/.id',
+ 'partner_address_id/.id': 'partner_address_id/.id',
+ 'state': 'state'
+ }
+ meeting_obj = sugar_obj.pool.get('crm.meeting')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ categ_id = get_category(sugar_obj, cr, uid, 'crm.meeting', 'Tasks')
+ sugar_data = sugar.search(PortType, sessionid, 'Tasks')
+ for val in sugar_data:
+ partner_xml_id = find_mapped_id(sugar_obj, cr, uid, 'res.partner.address', val.get('contact_id'), context)
+ if not partner_xml_id:
+ raise osv.except_osv(_('Warning !'), _('Reference Contact %s cannot be created, due to Lower Record Limit in SugarCRM Configuration.') % val.get('contact_name'))
+ partner_id, partner_address_id = get_account(sugar_obj, cr, uid, val, context)
+ val['partner_id/.id'] = partner_id
+ val['partner_address_id/.id'] = partner_address_id
+ val['categ_id/.id'] = categ_id
+ val['state'] = get_task_state(sugar_obj, cr, uid, val.get('status'), context=None)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_task)
+ meeting_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
+
+def get_attendee_id(sugar_obj, cr, uid, PortType, sessionid, module_name, module_id, context=None):
+ if not context:
+ context = {}
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ att_obj = sugar_obj.pool.get('calendar.attendee')
+ meeting_obj = sugar_obj.pool.get('crm.meeting')
+ user_dict = sugar.user_get_attendee_list(PortType, sessionid, module_name, module_id)
+ for user in user_dict:
+ user_model_ids = find_mapped_id(sugar_obj, cr, uid, 'res.users', user.get('id'), context)
+ user_resource_id = model_obj.browse(cr, uid, user_model_ids)
+ if user_resource_id:
+ user_id = user_resource_id[0].res_id
+ attend_ids = att_obj.search(cr, uid, [('user_id', '=', user_id)])
+ if attend_ids:
+ attendees = attend_ids[0]
+ else:
+ attendees = att_obj.create(cr, uid, {'user_id': user_id, 'email': user.get('email1')})
+ meeting_model_ids = find_mapped_id(sugar_obj, cr, uid, 'crm.meeting', module_id, context)
+ meeting_xml_id = model_obj.browse(cr, uid, meeting_model_ids)
+ if meeting_xml_id:
+ meeting_obj.write(cr, uid, [meeting_xml_id[0].res_id], {'attendee_ids': [(4, attendees)]})
+ return True
+
+def import_meetings(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_meeting = {'id' : 'id',
+ 'name': 'name',
+ 'date': 'date_start',
+ 'duration': ['duration_hours', 'duration_minutes'],
+ 'location': 'location',
+ 'alarm_id/.id': 'alarm_id/.id',
+ 'user_id/id': 'assigned_user_id',
+ 'partner_id/.id':'partner_id/.id',
+ 'partner_address_id/.id':'partner_address_id/.id',
+ 'state': 'state'
+ }
+ meeting_obj = sugar_obj.pool.get('crm.meeting')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Meetings')
+ for val in sugar_data:
+ partner_id, partner_address_id = get_account(sugar_obj, cr, uid, val, context)
+ val['partner_id/.id'] = partner_id
+ val['partner_address_id/.id'] = partner_address_id
+ val['state'] = get_meeting_state(sugar_obj, cr, uid, val.get('status'),context)
+ val['alarm_id/.id'] = get_alarm_id(sugar_obj, cr, uid, val.get('reminder_time'), context)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_meeting)
+ meeting_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ get_attendee_id(sugar_obj, cr, uid, PortType, sessionid, 'Meetings', val.get('id'), context)
+ return True
+
+def get_calls_state(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm stage : openerp calls stage
+ 'Planned' : 'open',
+ 'Held':'done',
+ 'Not Held': 'pending',
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def import_calls(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_calls = {'id' : 'id',
+ 'name': 'name',
+ 'date': 'date_start',
+ 'duration': ['duration_hours', 'duration_minutes'],
+ 'user_id/id': 'assigned_user_id',
+ 'partner_id/.id': 'partner_id/.id',
+ 'partner_address_id/.id': 'partner_address_id/.id',
+ 'categ_id/.id': 'categ_id/.id',
+ 'state': 'state',
+ }
+ phonecall_obj = sugar_obj.pool.get('crm.phonecall')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Calls')
+ for val in sugar_data:
+ categ_id = get_category(sugar_obj, cr, uid, 'crm.phonecall', val.get('direction'))
+ val['categ_id/.id'] = categ_id
+ partner_id, partner_address_id = get_account(sugar_obj, cr, uid, val, context)
+ val['partner_id/.id'] = partner_id
+ val['partner_address_id/.id'] = partner_address_id
+ val['state'] = get_calls_state(sugar_obj, cr, uid, val.get('status'), context)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_calls)
+ phonecall_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
+
def import_resources(sugar_obj, cr, uid, context=None):
if not context:
context = {}
@@ -321,10 +563,126 @@
resource_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
return True
+def get_bug_priority(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ priority = False
+ priority_dict = {'priority': #field in the sugarcrm database
+ { #Mapping of sugarcrm priority : openerp bugs priority
+ 'Urgent': '1',
+ 'High': '2',
+ 'Medium': '3',
+ 'Low': '4'
+ },}
+ priority = priority_dict['priority'].get(val, '')
+ return priority
+
+def get_bug_state(sugar_obj, cr, uid, val,context=None):
+ if not context:
+ context = {}
+ state = False
+ state_dict = {'status': #field in the sugarcrm database
+ { #Mapping of sugarcrm status : openerp Bugs state
+ 'New' : 'draft',
+ 'Assigned':'open',
+ 'Closed': 'done',
+ 'Pending': 'pending',
+ 'Rejected': 'cancel',
+ },}
+ state = state_dict['status'].get(val, '')
+ return state
+
+def get_issue_related_project(sugar_obj,cr,uid, PortType, sessionid, val, context=None):
+ if not context:
+ context={}
+ project_id = False
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ project_obj = sugar_obj.pool.get('project.project')
+ sugar_bug_project = sugar.relation_search(PortType, sessionid, 'Bugs', module_id=val.get('id'), related_module='Project', query=None, deleted=None)
+ for project_id in sugar_bug_project:
+ model_ids = find_mapped_id(sugar_obj, cr, uid, 'project.project', project_id, context)
+ if model_ids:
+ model_id = model_obj.browse(cr, uid, model_ids)[0].res_id
+ project_id = project_obj.browse(cr, uid, model_id).id
+ return project_id
+
+def import_bug(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_resource = {'id' : 'id',
+ 'name': 'name',
+ 'project_id/.id':'project_id/.id',
+ 'categ_id.id': 'categ_id.id',
+ 'priority':'priority',
+ 'description': 'description',
+ 'state': 'state',
+ }
+ issue_obj = sugar_obj.pool.get('project.issue')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Bugs')
+ for val in sugar_data:
+ val['project_id/.id'] = get_issue_related_project(sugar_obj,cr,uid, PortType, sessionid, val, context)
+ val['categ_id.id'] = get_category(sugar_obj, cr, uid, 'project.issue', val.get('type'))
+ val['priority'] = get_bug_priority(sugar_obj, cr, uid, val.get('priority'),context)
+ val['state'] = get_bug_state(sugar_obj, cr, uid, val.get('status'),context)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_resource)
+ issue_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
+
+def get_job_id(sugar_obj, cr, uid, val, context=None):
+ if not context:
+ context={}
+ job_id = False
+ job_obj = sugar_obj.pool.get('hr.job')
+ job_ids = job_obj.search(cr, uid, [('name', '=', val)])
+ if job_ids:
+ job_id = job_ids[0]
+ else:
+ job_id = job_obj.create(cr, uid, {'name': val})
+ return job_id
+
+def get_attachment(sugar_obj, cr, uid, val, model, File, context=None):
+ if not context:
+ context = {}
+ attachment_obj = sugar_obj.pool.get('ir.attachment')
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ mailgate_obj = sugar_obj.pool.get('mailgate.message')
+ new_attachment_id = attachment_obj.create(cr, uid, {'name': val.get('name'), 'datas': File, 'res_id': val['res_id'],'res_model': val['model']})
+ message_model_ids = find_mapped_id(sugar_obj, cr, uid, model, val.get('id'), context)
+ message_xml_id = model_obj.browse(cr, uid, message_model_ids)
+ if message_xml_id:
+ mailgate_obj.write(cr, uid, [message_xml_id[0].res_id], {'attachment_ids': [(4, new_attachment_id)]})
+ return True
+
+def import_history(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_attachment = {'id' : 'id',
+ 'name':'name',
+ 'date':'date_entered',
+ 'user_id/id': 'assigned_user_id',
+ 'description': 'description_html',
+ 'res_id': 'res_id',
+ 'model': 'model',
+ }
+ mailgate_obj = sugar_obj.pool.get('mailgate.message')
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Notes')
+ for val in sugar_data:
+ File = sugar.attachment_search(PortType, sessionid, 'Notes', val.get('id'))
+ model_ids = model_obj.search(cr, uid, [('name', 'like', val.get('parent_id'))])
+ for model in model_obj.browse(cr, uid, model_ids):
+ val['res_id'] = model.res_id
+ val['model'] = model.model
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_attachment)
+ mailgate_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ get_attachment(sugar_obj, cr, uid, val, 'mailgate.message', File, context)
+ return True
+
def import_employees(sugar_obj, cr, uid, context=None):
if not context:
context = {}
- job_id = False
map_employee = {'id' : 'user_hash',
'resource_id/.id': 'resource_id/.id',
'name': ['first_name', 'last_name'],
@@ -338,7 +696,6 @@
'job_id/.id': 'job_id/.id'
}
employee_obj = sugar_obj.pool.get('hr.employee')
- job_obj = sugar_obj.pool.get('hr.job')
PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
sugar_data = sugar.search(PortType, sessionid, 'Employees')
for val in sugar_data:
@@ -348,13 +705,7 @@
resource_id = sugar_obj.pool.get('ir.model.data').browse(cr, uid, model_ids)
if resource_id:
val['resource_id/.id'] = resource_id[0].res_id
-
- job_ids = job_obj.search(cr, uid, [('name', '=', val.get('title'))])
- if job_ids:
- job_id = job_ids[0]
- else:
- job_id = job_obj.create(cr, uid, {'name': val.get('title')})
- val['job_id/.id'] = job_id
+ val['job_id/.id'] = get_job_id(sugar_obj, cr, uid, val.get('title'), context)
fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_employee)
employee_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
return True
@@ -371,11 +722,107 @@
title_id = contact_title_obj.create(cr, uid, {'name': salutation, 'shortcut': salutation, 'domain': domain})
return title_id
+def import_emails(sugar_obj, cr, uid, context=None):
+ if not context:
+ context= {}
+ map_emails = {'id': 'id',
+ 'name':'name',
+ 'date':'date_sent',
+ 'email_from': 'from_addr_name',
+ 'email_to': 'reply_to_addr',
+ 'email_cc': 'cc_addrs_names',
+ 'email_bcc': 'bcc_addrs_names',
+ 'message_id': 'message_id',
+ 'user_id/id': 'assigned_user_id',
+ 'description': 'description_html',
+ 'res_id': 'res_id',
+ 'model': 'model',
+ }
+ mailgate_obj = sugar_obj.pool.get('mailgate.message')
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Emails')
+ for val in sugar_data:
+ model_ids = model_obj.search(cr, uid, [('name', 'like', val.get('parent_id'))])
+ for model in model_obj.browse(cr, uid, model_ids):
+ val['res_id'] = model.res_id
+ val['model'] = model.model
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_emails)
+ mailgate_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
+
+def get_project_account(sugar_obj,cr,uid, PortType, sessionid, val, context=None):
+ if not context:
+ context={}
+ partner_id = False
+ partner_invoice_id = False
+ model_obj = sugar_obj.pool.get('ir.model.data')
+ partner_obj = sugar_obj.pool.get('res.partner')
+ partner_address_obj = sugar_obj.pool.get('res.partner.address')
+ sugar_project_account = sugar.relation_search(PortType, sessionid, 'Project', module_id=val.get('id'), related_module='Accounts', query=None, deleted=None)
+ for account_id in sugar_project_account:
+ model_ids = find_mapped_id(sugar_obj, cr, uid, 'res.partner', account_id, context)
+ if model_ids:
+ model_id = model_obj.browse(cr, uid, model_ids)[0].res_id
+ partner_id = partner_obj.browse(cr, uid, model_id).id
+ address_ids = partner_address_obj.search(cr, uid, [('partner_id', '=', partner_id),('type', '=', 'invoice')])
+ partner_invoice_id = address_ids[0]
+ return partner_id, partner_invoice_id
+
+def import_projects(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_project = {'id': 'id',
+ 'name': 'name',
+ 'date_start': 'estimated_start_date',
+ 'date': 'estimated_end_date',
+ 'user_id/id': 'assigned_user_id',
+ 'partner_id/.id': 'partner_id/.id',
+ 'contact_id/.id': 'contact_id/.id',
+ 'state': 'state'
+ }
+ project_obj = sugar_obj.pool.get('project.project')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'Project')
+ for val in sugar_data:
+ partner_id, partner_invoice_id = get_project_account(sugar_obj,cr,uid, PortType, sessionid, val, context)
+ val['partner_id/.id'] = partner_id
+ val['contact_id/.id'] = partner_invoice_id
+ val['state'] = get_project_state(sugar_obj, cr, uid, val.get('status'),context)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_project)
+ project_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
+
+
+def import_project_tasks(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ map_project_task = {'id': 'id',
+ 'name': 'name',
+ 'date_start': 'date_start',
+ 'date_end': 'date_finish',
+ 'progress': 'progress',
+ 'project_id/name': 'project_name',
+ 'planned_hours': 'planned_hours',
+ 'total_hours': 'total_hours',
+ 'priority': 'priority',
+ 'description': 'description',
+ 'user_id/id': 'assigned_user_id',
+ 'state': 'state'
+ }
+ task_obj = sugar_obj.pool.get('project.task')
+ PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
+ sugar_data = sugar.search(PortType, sessionid, 'ProjectTask')
+ for val in sugar_data:
+ val['state'] = get_project_task_state(sugar_obj, cr, uid, val.get('status'),context)
+ val['priority'] = get_project_task_priority(sugar_obj, cr, uid, val.get('priority'),context)
+ fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, map_project_task)
+ task_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
+ return True
def import_leads(sugar_obj, cr, uid, context=None):
if not context:
context = {}
- title_id = False
map_lead = {
'id' : 'id',
'name': ['first_name', 'last_name'],
@@ -419,23 +866,26 @@
partner_contact_name = False
model_obj = sugar_obj.pool.get('ir.model.data')
partner_address_obj = sugar_obj.pool.get('res.partner.address')
- sugar_opportunity_contact = sugar.relation_search(PortType, sessionid, 'Opportunities', module_id=val.get('id'), related_module='Contacts', query=None, deleted=None)
- for contact in sugar_opportunity_contact:
- model_ids = find_mapped_id(sugar_obj, cr, uid, 'res.partner.address', contact, context)
- if model_ids:
- model_id = model_obj.browse(cr, uid, model_ids)[0].res_id
- address_id = partner_address_obj.browse(cr, uid, model_id)
- partner_address_obj.write(cr, uid, [address_id.id], {'partner_id': partner_xml_id[0]})
- partner_contact_name = address_id.name
- else:
- partner_contact_name = val.get('account_name')
+ model_account_ids = model_obj.search(cr, uid, [('res_id', '=', partner_xml_id[0]), ('model', '=', 'res.partner'), ('module', '=', 'sugarcrm_import')])
+ model_xml_id = model_obj.browse(cr, uid, model_account_ids)[0].name
+ sugar_account_contact = set(sugar.relation_search(PortType, sessionid, 'Accounts', module_id=model_xml_id, related_module='Contacts', query=None, deleted=None))
+ sugar_opportunities_contact = set(sugar.relation_search(PortType, sessionid, 'Opportunities', module_id=val.get('id'), related_module='Contacts', query=None, deleted=None))
+ sugar_contact = list(sugar_account_contact.intersection(sugar_opportunities_contact))
+ if sugar_contact:
+ for contact in sugar_contact:
+ model_ids = find_mapped_id(sugar_obj, cr, uid, 'res.partner.address', contact, context)
+ if model_ids:
+ model_id = model_obj.browse(cr, uid, model_ids)[0].res_id
+ address_id = partner_address_obj.browse(cr, uid, model_id)
+ partner_address_obj.write(cr, uid, [address_id.id], {'partner_id': partner_xml_id[0]})
+ partner_contact_name = address_id.name
+ else:
+ partner_contact_name = val.get('account_name')
return partner_contact_name
def import_opportunities(sugar_obj, cr, uid, context=None):
if not context:
context = {}
- categ_id = False
- partner_contact_name = False
map_opportunity = {'id' : 'id',
'name': 'name',
'probability': 'probability',
@@ -449,10 +899,8 @@
'type' : 'type',
'categ_id.id': 'categ_id.id'
}
-
lead_obj = sugar_obj.pool.get('crm.lead')
partner_obj = sugar_obj.pool.get('res.partner')
- categ_obj = sugar_obj.pool.get('crm.case.categ')
PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
sugar_data = sugar.search(PortType, sessionid, 'Opportunities')
for val in sugar_data:
@@ -460,13 +908,8 @@
if not partner_xml_id:
raise osv.except_osv(_('Warning !'), _('Reference Partner %s cannot be created, due to Lower Record Limit in SugarCRM Configuration.') % val.get('account_name'))
partner_contact_name = get_opportunity_contact(sugar_obj,cr,uid, PortType, sessionid, val, partner_xml_id, context)
- val['partner_address_id/name'] = partner_contact_name
- categ_ids = categ_obj.search(cr, uid, [('object_id.model','=','crm.lead'), ('name', 'like',val.get('opportunity_type'))])
- if categ_ids:
- categ_id = categ_ids[0]
- else:
- categ_id = categ_obj.create(cr, uid, {'name': val.get('opportunity_type'), 'object_id.model': 'crm.lead'})
- val['categ_id.id'] = categ_id
+ val['partner_address_id/name'] = partner_contact_name
+ val['categ_id.id'] = get_category(sugar_obj, cr, uid, 'crm.lead', val.get('opportunity_type'))
val['type'] = 'opportunity'
stage_id = get_opportunity_status(sugar_obj, cr, uid, val, context)
val['stage_id.id'] = stage_id
@@ -475,7 +918,7 @@
return True
MAP_FIELDS = {'Opportunities': #Object Mapping name
- {'dependencies' : ['Users', 'Accounts'], #Object to import before this table
+ {'dependencies' : ['Users', 'Accounts', 'Contacts'], #Object to import before this table
'process' : import_opportunities,
},
'Leads':
@@ -494,10 +937,42 @@
{'dependencies' : [],
'process' : import_users,
},
+ 'Meetings':
+ {'dependencies' : ['Users', 'Tasks'],
+ 'process' : import_meetings,
+ },
+ 'Tasks':
+ {'dependencies' : ['Users', 'Accounts', 'Contacts'],
+ 'process' : import_tasks,
+ },
+ 'Calls':
+ {'dependencies' : ['Users', 'Accounts', 'Contacts'],
+ 'process' : import_calls,
+ },
'Employees':
{'dependencies' : ['Resources'],
'process' : import_employees,
+ },
+ 'Emails':
+ {'dependencies' : ['Users'],
+ 'process' : import_emails,
},
+ 'Projects':
+ {'dependencies' : ['Users', 'Accounts', 'Contacts'],
+ 'process' : import_projects,
+ },
+ 'Project Tasks':
+ {'dependencies' : ['Users', 'Projects'],
+ 'process' : import_project_tasks,
+ },
+ 'Bugs':
+ {'dependencies' : ['Users', 'Projects', 'Project Tasks'],
+ 'process' : import_bug,
+ },
+ 'Notes':
+ {'dependencies' : ['Users', 'Projects', 'Project Tasks', 'Accounts', 'Contacts', 'Leads', 'Opportunities', 'Meetings', 'Calls'],
+ 'process' : import_history,
+ },
'Resources':
{'dependencies' : ['Users'],
'process' : import_resources,
@@ -510,12 +985,19 @@
_name = "import.sugarcrm"
_description = __doc__
_columns = {
- 'lead': fields.boolean('Leads', help="If Leads are checked, SugarCRM Leads data imported in openERP crm-Lead form"),
- 'opportunity': fields.boolean('Opportunities', help="If Opportunities are checked, SugarCRM opportunities data imported in openERP crm-Opportunity form"),
- 'user': fields.boolean('User', help="If Users are checked, SugarCRM Users data imported in openERP Users form"),
- 'contact': fields.boolean('Contacts', help="If Contacts are checked, SugarCRM Contacts data imported in openERP partner address form"),
- 'account': fields.boolean('Accounts', help="If Accounts are checked, SugarCRM Accounts data imported in openERP partners form"),
- 'employee': fields.boolean('Employee', help="If Employees is checked, SugarCRM Employees data imported in openERP employees form"),
+ 'lead': fields.boolean('Leads', help="If Leads are checked, SugarCRM Leads data imported in OpenERP crm-Lead form"),
+ 'opportunity': fields.boolean('Opportunities', help="If Opportunities are checked, SugarCRM opportunities data imported in OpenERP crm-Opportunity form"),
+ 'user': fields.boolean('User', help="If Users are checked, SugarCRM Users data imported in OpenERP Users form"),
+ 'contact': fields.boolean('Contacts', help="If Contacts are checked, SugarCRM Contacts data imported in OpenERP partner address form"),
+ 'account': fields.boolean('Accounts', help="If Accounts are checked, SugarCRM Accounts data imported in OpenERP partners form"),
+ 'employee': fields.boolean('Employee', help="If Employees is checked, SugarCRM Employees data imported in OpenERP employees form"),
+ 'meeting': fields.boolean('Meetings', help="If Meetings is checked, SugarCRM Meetings data imported in OpenERP meetings form"),
+ 'call': fields.boolean('Calls', help="If Calls is checked, SugarCRM Calls data imported in OpenERP phonecalls form"),
+ 'email': fields.boolean('Emails', help="If Emails is checked, SugarCRM Emails data imported in OpenERP Emails form"),
+ 'project': fields.boolean('Projects', help="If Projects is checked, SugarCRM Projects data imported in OpenERP Projects form"),
+ 'project_task': fields.boolean('Project Tasks', help="If Project Tasks is checked, SugarCRM Project Tasks data imported in OpenERP Project Tasks form"),
+ 'bug': fields.boolean('Bugs', help="If Bugs is checked, SugarCRM Bugs data imported in OpenERP Project Issues form"),
+ 'attachment': fields.boolean('Attachments', help="If Attachments is checked, SugarCRM Notes data imported in OpenERP's Related module's History with attachment"),
'username': fields.char('User Name', size=64),
'password': fields.char('Password', size=24),
}
@@ -525,7 +1007,13 @@
'user' : True,
'contact' : True,
'account' : True,
- 'employee' : True,
+ 'employee' : True,
+ 'meeting' : True,
+ 'call' : True,
+ 'email' : True,
+ 'project' : True,
+ 'project_task': True,
+ 'bug': True,
}
def get_key(self, cr, uid, ids, context=None):
@@ -545,7 +1033,21 @@
if current.account:
key_list.append('Accounts')
if current.employee:
- key_list.append('Employees')
+ key_list.append('Employees')
+ if current.meeting:
+ key_list.append('Meetings')
+ if current.call:
+ key_list.append('Calls')
+ if current.email:
+ key_list.append('Emails')
+ if current.project:
+ key_list.append('Projects')
+ if current.project_task:
+ key_list.append('Project Tasks')
+ if current.bug:
+ key_list.append('Bugs')
+ if current.attachment:
+ key_list.append('Notes')
return key_list
def import_all(self, cr, uid, ids, context=None):
=== modified file 'import_sugarcrm/import_sugarcrm_view.xml'
--- import_sugarcrm/import_sugarcrm_view.xml 2011-04-01 05:45:46 +0000
+++ import_sugarcrm/import_sugarcrm_view.xml 2011-04-15 06:23:37 +0000
@@ -9,14 +9,24 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import SugarCRM">
- <group colspan="4" width="400" col="3">
+ <group colspan="4" width="500">
<separator string="Select SugarCRM Module Name" colspan="4"/>
- <field name="lead" />
- <field name="opportunity" />
- <field name="user" />
- <field name= "contact" />
- <field name= "account" />
- <field name= "employee" />
+ <group colspan="4" col="6">
+ <field name="lead" />
+ <field name="opportunity" />
+ <field name= "meeting" />
+ <field name= "call" />
+ <field name= "account" />
+ <field name= "contact" />
+ <field name="user" />
+ <field name= "employee" />
+ <field name= "email" />
+ <field name= "project" />
+ <field name= "project_task" />
+ <field name= "bug" string="Project Issue"/>
+ </group>
+ <separator string="" colspan="4"/>
+ <field name= "attachment" />
<field name="username" invisible="1"/>
<field name="password" invisible="1"/>
</group>
=== modified file 'import_sugarcrm/sugar.py'
--- import_sugarcrm/sugar.py 2011-04-04 09:13:05 +0000
+++ import_sugarcrm/sugar.py 2011-04-15 06:23:37 +0000
@@ -25,7 +25,9 @@
from sugarsoap_services_types import *
from osv import osv
from tools.translate import _
-
+import base64
+from lxml import etree
+import tools
class LoginError(Exception): pass
def login(username, password, url):
@@ -61,6 +63,33 @@
ans_list.append(i.get_element_id())
return ans_list
+def attachment_search(portType, sessionid, module_name, module_id=None):
+ se_req = get_note_attachmentRequest()
+ se_req._session = sessionid
+ se_req._id = module_id
+ se_req._module_name = module_name
+ se_resp = portType.get_note_attachment(se_req)
+ file = False
+ file = se_resp._return._note_attachment.File
+ return file
+
+def user_get_attendee_list(portType, sessionid, module_name=None, module_id=None):
+ se_req = get_attendee_listRequest()
+ se_req._session = sessionid
+ se_req._module_name = module_name
+ se_req._id = module_id
+ se_resp = portType.get_attendee_list(se_req)
+ list = se_resp.get_element_return()
+ arch = base64.decodestring(list.Result)
+ eview = False
+ eview = etree.XML(arch)
+ attendee_list = []
+ for child in eview:
+ attendee_dict = {}
+ for ch in child.getchildren():
+ attendee_dict[ch.tag] = tools.ustr(ch.text)
+ attendee_list.append(attendee_dict)
+ return attendee_list
def search(portType, sessionid, module_name=None):
se_req = get_entry_listRequest()
@@ -73,7 +102,7 @@
for i in list:
ans_dir = {}
for j in i._name_value_list:
- ans_dir[j._name.encode('utf-8')] = j._value.encode('utf-8')
+ ans_dir[tools.ustr(j._name)] = tools.ustr(j._value)
#end for
ans_list.append(ans_dir)
#end for
=== modified file 'import_sugarcrm/sugarcrm_fields_mapping.py'
--- import_sugarcrm/sugarcrm_fields_mapping.py 2011-04-04 11:55:21 +0000
+++ import_sugarcrm/sugarcrm_fields_mapping.py 2011-04-15 06:23:37 +0000
@@ -26,7 +26,10 @@
if key not in fields and dict_sugar:
fields.append(key)
if isinstance(val, list) and val:
- data_lst.append(' '.join(map(lambda x : dict_sugar[x], val)))
+ if key == 'duration':
+ data_lst.append('.'.join(map(lambda x : dict_sugar[x], val)))
+ else:
+ data_lst.append(' '.join(map(lambda x : dict_sugar[x], val)))
else:
data_lst.append(dict_sugar.get(val,''))
return fields,data_lst
=== modified file 'import_sugarcrm/wizard/sugarcrm_login.py'
--- import_sugarcrm/wizard/sugarcrm_login.py 2011-03-24 04:39:01 +0000
+++ import_sugarcrm/wizard/sugarcrm_login.py 2011-04-15 06:23:37 +0000
@@ -30,7 +30,7 @@
_columns = {
'username': fields.char('User Name', size=64, required=True),
'password': fields.char('Password', size=24,required=True),
- 'url' : fields.char('SugarCRM Path', size=264, required=True, help="Path for SugarCRM connection should be 'http://localhost/sugarcrm/soap.php' Format."),
+ 'url' : fields.char('Service', size=264, required=True, help="Connection with Sugarcrm Using Soap Protocol Services and For that Path should be 'http://localhost/sugarcrm/soap.php' Format."),
}
_defaults = {
'username' : 'admin',
=== modified file 'import_sugarcrm/wizard/sugarcrm_login_view.xml'
--- import_sugarcrm/wizard/sugarcrm_login_view.xml 2011-04-04 11:55:21 +0000
+++ import_sugarcrm/wizard/sugarcrm_login_view.xml 2011-04-15 06:23:37 +0000
@@ -10,9 +10,8 @@
<field name="arch" type="xml">
<form string="SugarCRM Login">
<group colspan="4" width="500" >
- <separator string="Please Enter Path to Connect with SugarCRM" colspan="4"/>
+ <separator string="Connection with SugarCRM" colspan="4"/>
<field name="url" colspan="4" widget="url"/>
- <separator string="Please enter your user name and password." colspan="4"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
Follow ups