openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #05205
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/56885
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/56885
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-08 07:09:25 +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': ['crm', 'hr', 'project'],
'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-08 07:09:25 +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')
@@ -306,7 +307,231 @@
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')
+ partner_obj = sugar_obj.pool.get('res.partner')
+ 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[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)
+ if address_id.partner_id:
+ partner_id = address_id.partner_id
+
+ return partner_id, partner_address_id
+
+def import_tasks(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ partner_id = False
+ partner_address_id = False
+ 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 import_meetings(sugar_obj, cr, uid, context=None):
+ if not context:
+ context = {}
+ partner_id = False
+ partner_address_id = False
+ 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)
+ 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 = {}
+ partner_id = False
+ partner_address_id = False
+ 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,6 +546,18 @@
resource_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 import_employees(sugar_obj, cr, uid, context=None):
if not context:
context = {}
@@ -338,7 +575,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 +584,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,6 +601,81 @@
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=None
+
+ 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 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',
+ '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:
+ 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:
@@ -449,7 +754,6 @@
'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')
@@ -460,13 +764,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
@@ -494,10 +793,34 @@
{'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'],
+ 'process' : import_projects,
+ },
+ 'Project Tasks':
+ {'dependencies' : ['Users', 'Projects'],
+ 'process' : import_project_tasks,
+ },
'Resources':
{'dependencies' : ['Users'],
'process' : import_resources,
@@ -516,6 +839,11 @@
'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"),
'username': fields.char('User Name', size=64),
'password': fields.char('Password', size=24),
}
@@ -525,7 +853,12 @@
'user' : True,
'contact' : True,
'account' : True,
- 'employee' : True,
+ 'employee' : True,
+ 'meeting' : True,
+ 'call' : True,
+ 'email' : True,
+ 'project' : True,
+ 'project_task': True
}
def get_key(self, cr, uid, ids, context=None):
@@ -545,7 +878,17 @@
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')
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-08 07:09:25 +0000
@@ -17,6 +17,11 @@
<field name= "contact" />
<field name= "account" />
<field name= "employee" />
+ <field name= "meeting" />
+ <field name= "call" />
+ <field name= "email" />
+ <field name= "project" />
+ <field name= "project_task" />
<field name="username" invisible="1"/>
<field name="password" invisible="1"/>
</group>
=== 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-08 07:09:25 +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
Follow ups