[MERGE] atp team bakclog 4 5 6 complete

bzr revid: tfr@openerp.com-20110525132914-d19doksprb4mfa03
This commit is contained in:
tfr@openerp.com 2011-05-25 15:29:14 +02:00
commit a84c8d0757
8 changed files with 555 additions and 676 deletions

View File

@ -29,7 +29,7 @@
'website': 'http://www.openerp.com',
'depends': ['import_base', 'crm_claim', 'project', 'project_issue', 'hr', 'document'],
'init_xml': [],
'update_xml': ["wizard/sugarcrm_login_view.xml",
'update_xml': [
"wizard/import_message_view.xml",
"import_sugarcrm_view.xml"],
'demo_xml': [],

View File

@ -23,7 +23,7 @@ import sugar
from tools.translate import _
from import_base.import_framework import *
from import_base.mapper import *
from datetime import datetime
import base64
import pprint
pp = pprint.PrettyPrinter(indent=4)
@ -38,7 +38,6 @@ class related_ref(dbmapper):
return self.parent.xml_id_exist(external_val['parent_type'], external_val['parent_id'])
return ''
class sugar_import(import_framework):
TABLE_CONTACT = 'Contacts'
TABLE_ACCOUNT = 'Accounts'
@ -48,17 +47,25 @@ class sugar_import(import_framework):
TABLE_OPPORTUNITY = 'Opportunities'
TABLE_LEAD = 'Leads'
TABLE_STAGE = 'crm_stage'
TABLE_ATTENDEE = 'calendar_attendee'
TABLE_CALL = 'Calls'
TABLE_MEETING = 'Meetings'
TABLE_TASK = 'Tasks'
TABLE_PROJECT = 'Project'
TABLE_PROJECT_TASK = 'ProjectTask'
TABLE_BUG = 'Bugs'
TABLE_CASE = 'Cases'
TABLE_NOTE = 'Notes'
TABLE_EMAIL = 'Emails'
TABLE_DOCUMENT = 'DocumentRevisions'
TABLE_COMPAIGN = 'Campaigns'
TABLE_HISTORY_ATTACHMNET = 'history_attachment'
def initialize(self):
#login
PortType,sessionid = sugar.login(self.context.get('username',''), self.context.get('password',''), self.context.get('url',''))
if sessionid == '-1':
raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
self.context['port'] = PortType
self.context['session_id'] = sessionid
@ -66,8 +73,9 @@ class sugar_import(import_framework):
return sugar.search(self.context.get('port'), self.context.get('session_id'), table)
"""
Common import method
Common import method
"""
def get_category(self, val, model, name):
fields = ['name', 'object_id']
data = [name, model]
@ -75,13 +83,14 @@ class sugar_import(import_framework):
def get_job_title(self, dict, salutation):
fields = ['shortcut', 'name', 'domain']
data = [salutation, salutation, 'Contact']
return self.import_object(fields, data, 'res.partner.title', 'contact_title', salutation, [('shortcut', '=', salutation)])
if salutation:
data = [salutation, salutation, 'Contact']
return self.import_object(fields, data, 'res.partner.title', 'contact_title', salutation, [('shortcut', '=', salutation)])
def get_campaign_id(self, dict, val):
def get_channel_id(self, dict, val):
fields = ['name']
data = [val]
return self.import_object(fields, data, 'crm.case.resource.type', 'crm_campaign', val)
return self.import_object(fields, data, 'res.partner.canal', 'crm_channel', val)
def get_all_states(self, external_val, country_id):
"""Get states or create new state unless country_id is False"""
@ -90,7 +99,6 @@ class sugar_import(import_framework):
data = [country_id, external_val, state_code]
if country_id:
return self.import_object(fields, data, 'res.country.state', 'country_state', external_val)
return False
def get_all_countries(self, val):
@ -100,6 +108,348 @@ class sugar_import(import_framework):
def get_float_time(self, dict, hour, min):
min = int(min) * 100 / 60
return "%s.%i" % (hour, min)
def get_attachment(self, val):
File, Filename = sugar.attachment_search(self.context.get('port'), self.context.get('session_id'), self.TABLE_NOTE, val.get('id'))
attach_xml_id = False
attachment_obj = self.obj.pool.get('ir.attachment')
model_obj = self.obj.pool.get('ir.model.data')
mailgate_obj = self.obj.pool.get('mailgate.message')
if File:
fields = ['name', 'datas', 'datas_fname','res_id', 'res_model']
name = 'attachment_'+ (Filename or val.get('name'))
datas = [Filename or val.get('name'), File, Filename, val.get('res_id'),val.get('model',False)]
attach_xml_id = self.import_object(fields, datas, 'ir.attachment', self.TABLE_HISTORY_ATTACHMNET, name, [('res_id', '=', val.get('res_id'), ('model', '=', val.get('model')))])
return attach_xml_id
"""
import Documents
"""
#THIS IS A JOKE ? NOT FUNNY
def import_document(self, val):
filepath = '/home/openerp/Public/sugarcrm/cache/upload/'+ val.get('id')
f = open(filepath, "r")
datas = f.read()
f.close()
val['datas'] = base64.encodestring(datas)
val['datas_fname'] = val.get('filename')
return val
def get_document_mapping(self):
return {
'model' : 'ir.attachment',
'dependencies' : [self.TABLE_USER],
'hook' : self.import_document,
'map' : {'name':'filename',
'description': ppconcat('description'),
'datas': 'datas',
'datas_fname': 'datas_fname',
}
}
"""
import Emails
"""
def import_email(self, val):
print 'import email'
model_obj = self.obj.pool.get('ir.model.data')
xml_id = self.xml_id_exist(val.get('parent_type'), val.get('parent_id'))
model_ids = model_obj.search(self.cr, self.uid, [('name', 'like', xml_id)])
if model_ids:
print 'model_id', xml_id, model_ids
model = model_obj.browse(self.cr, self.uid, model_ids)[0]
if model.model == 'res.partner':
val['partner_id/.id'] = model.res_id
else:
val['res_id'] = model.res_id
val['model'] = model.model
return val
def get_email_mapping(self):
return {
'model' : 'mailgate.message',
'dependencies' : [self.TABLE_USER, self.TABLE_PROJECT, self.TABLE_PROJECT_TASK, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD, self.TABLE_OPPORTUNITY, self.TABLE_MEETING, self.TABLE_CALL],
'hook' : self.import_email,
'map' : {'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',
'res_id': 'res_id',
'model': 'model',
'partner_id/.id': 'partner_id/.id',
'attachment_ids/id': self.get_attachment,
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'description': ppconcat('description', 'description_html'),
}
}
"""
import History(Notes)
"""
def import_history(self, val):
model_obj = self.obj.pool.get('ir.model.data')
xml_id = self.xml_id_exist(val.get('parent_type'), val.get('parent_id'))
model_ids = model_obj.search(self.cr, self.uid, [('name', 'like', xml_id)])
if model_ids:
model = model_obj.browse(self.cr, self.uid, model_ids)[0]
if model.model == 'res.partner':
val['partner_id/.id'] = model.res_id
else:
val['res_id'] = model.res_id
val['model'] = model.model
return val
def get_history_mapping(self):
return {
'model' : 'mailgate.message',
'dependencies' : [self.TABLE_USER, self.TABLE_PROJECT, self.TABLE_PROJECT_TASK, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD, self.TABLE_OPPORTUNITY, self.TABLE_MEETING, self.TABLE_CALL],
'hook' : self.import_history,
'map' : {
'name':'name',
'date': 'date_entered',
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'description': ppconcat('description', 'description_html'),
'res_id': 'res_id',
'model': 'model',
'attachment_ids/id': self.get_attachment,
'partner_id/.id' : 'partner_id/.id',
}
}
"""
import Claims(Cases)
"""
def get_claim_priority(self, val):
priority_dict = {
'High': '2',
'Medium': '3',
'Low': '4'
}
return priority_dict.get(val.get('priority'), '')
def get_contact_info_from_account(self, val):
partner_id = self.get_mapped_id(self.TABLE_ACCOUNT, val.get('account_id'))
partner_address_id = False
partner_phone = False
partner_email = False
partner = self.obj.pool.get('res.partner').browse(self.cr, self.uid, [partner_id])[0]
if partner.address and partner.address[0]:
address = partner.address[0]
partner_address_id = address.id
partner_phone = address.phone
partner_email = address.email
return partner_address_id, partner_phone,partner_email
def import_crm_claim(self, val):
partner_address_id, partner_phone,partner_email = self.get_contact_info_from_account(val)
val['partner_address_id/.id'] = partner_address_id
val['partner_address_id/.id'] = partner_address_id
val['partner_phone'] = partner_phone
val['email_from'] = partner_email
return val
def get_crm_claim_mapping(self):
return {
'model' : 'crm.claim',
'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD],
'hook' : self.import_crm_claim,
'map' : {
'name': 'name',
'date': 'date_entered',
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'description': ppconcat('description'),
'partner_id/id': ref(self.TABLE_ACCOUNT, 'account_id'),
'partner_address_id/.id': 'partner_address_id/.id',
'partner_phone': 'partner_phone',
'email_from': 'email_from',
'priority': self.get_claim_priority,
'state': map_val('status', self.project_issue_state)
}
}
"""
Import Project Issue(Bugs)
"""
project_issue_state = {
'New' : 'draft',
'Assigned':'open',
'Closed': 'done',
'Pending': 'pending',
'Rejected': 'cancel',
}
def get_project_issue_priority(self, val):
priority_dict = {
'Urgent': '1',
'High': '2',
'Medium': '3',
'Low': '4'
}
return priority_dict.get(val.get('priority'), '')
def get_bug_project_id(self, dict, val):
fields = ['name']
data = [val]
return self.import_object(fields, data, 'project.project', 'project_issue', val)
def get_project_issue_mapping(self):
return {
'model' : 'project.issue',
'dependencies' : [self.TABLE_USER, self.TABLE_PROJECT, self.TABLE_PROJECT_TASK],
'map' : {
'name': 'name',
'project_id/id': call(self.get_bug_project_id, 'sugarcrm_bugs'),
'categ_id/id': call(self.get_category, 'project.issue', value('type')),
'description': ppconcat('description', 'bug_number', 'fixed_in_release_name', 'source', 'fixed_in_release', 'work_log', 'found_in_release', 'release_name', 'resolution'),
'priority': self.get_project_issue_priority,
'state': map_val('status', self.project_issue_state)
}
}
"""
import Project Tasks
"""
project_task_state = {
'Not Started': 'draft',
'In Progress': 'open',
'Completed': 'done',
'Pending Input': 'pending',
'Deferred': 'cancelled',
}
def get_project_task_priority(self, val):
priority_dict = {
'High': '0',
'Medium': '2',
'Low': '3'
}
return priority_dict.get(val.get('priority'), '')
def get_project_task_mapping(self):
return {
'model' : 'project.task',
'dependencies' : [self.TABLE_USER, self.TABLE_PROJECT],
'map' : {
'name': 'name',
'date_start': 'date_start',
'date_end': 'date_finish',
'progress': 'progress',
'project_id/id': ref(self.TABLE_PROJECT, 'project_id'),
'planned_hours': 'planned_hours',
'total_hours': 'total_hours',
'priority': self.get_project_task_priority,
'description': ppconcat('description','milestone_flag', 'project_task_id', 'task_number'),
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'partner_id/id': 'partner_id/id',
'contact_id/id': 'contact_id/id',
'state': map_val('status', self.project_task_state)
}
}
"""
import Projects
"""
project_state = {
'Draft' : 'draft',
'In Review': 'open',
'Published': 'close'
}
def import_project_account(self, val):
partner_id = False
partner_invoice_id = False
sugar_project_account = sugar.relation_search(self.context.get('port'), self.context.get('session_id'), 'Project', module_id=val.get('id'), related_module=self.TABLE_ACCOUNT, query=None, deleted=None)
sugar_project_contact = sugar.relation_search(self.context.get('port'), self.context.get('session_id'), 'Project', module_id=val.get('id'), related_module=self.TABLE_CONTACT, query=None, deleted=None)
for contact_id in sugar_project_contact:
partner_invoice_id = self.get_mapped_id(self.TABLE_CONTACT, contact_id)
for account_id in sugar_project_account:
partner_id = self.get_mapped_id(self.TABLE_ACCOUNT, account_id)
return partner_id, partner_invoice_id
def import_project(self, val):
partner_id, partner_invoice_id = self.import_project_account(val)
val['partner_id/.id'] = partner_id
val['contact_id/.id'] = partner_invoice_id
return val
def get_project_mapping(self):
return {
'model' : 'project.project',
'dependencies' : [self.TABLE_CONTACT, self.TABLE_ACCOUNT, self.TABLE_USER],
'hook' : self.import_project,
'map' : {
'name': 'name',
'date_start': 'estimated_start_date',
'date': 'estimated_end_date',
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'partner_id/.id': 'partner_id/.id',
'contact_id/.id': 'contact_id/.id',
'state': map_val('status', self.project_state)
}
}
"""
import Tasks
"""
task_state = {
'Completed' : 'done',
'Not Started':'draft',
'In Progress': 'open',
'Pending Input': 'draft',
'deferred': 'cancel'
}
def import_task(self, val):
val['date'] = val.get('date_start') or datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
val['date_deadline'] = val.get('date_due') or datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
return val
def get_task_mapping(self):
return {
'model' : 'crm.meeting',
'dependencies' : [self.TABLE_CONTACT, self.TABLE_ACCOUNT, self.TABLE_USER],
'hook' : self.import_task,
'map' : {
'name': 'name',
'date': 'date',
'date_deadline': 'date_deadline',
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'categ_id/id': call(self.get_category, 'crm.meeting', const('Tasks')),
'partner_id/id': related_ref(self.TABLE_ACCOUNT),
'partner_address_id/id': ref(self.TABLE_CONTACT,'contact_id'),
'state': map_val('status', self.task_state)
}
}
"""
import Calls
"""
call_state = {
'Planned' : 'open',
'Held':'done',
'Not Held': 'pending',
}
def get_calls_mapping(self):
return {
'model' : 'crm.phonecall',
'dependencies' : [self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_OPPORTUNITY, self.TABLE_LEAD],
'map' : {
'name': 'name',
'date': 'date_start',
'duration': call(self.get_float_time, value('duration_hours'), value('duration_minutes')),
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'partner_id/id': related_ref(self.TABLE_ACCOUNT),
'partner_address_id/id': related_ref(self.TABLE_CONTACT),
'categ_id/id': call(self.get_category, 'crm.phonecall', value('direction')),
'opportunity_id/id': related_ref(self.TABLE_OPPORTUNITY),
'description': ppconcat('description'),
'state': map_val('status', self.call_state)
}
}
"""
import meeting
@ -109,6 +459,23 @@ class sugar_import(import_framework):
'Held': 'open',
'Not Held': 'draft',
}
#TODO
def get_attendee_id(self, cr, uid, module_name, module_id):
contact_id = False
user_id = False
attendee_id= []
attendee_dict = sugar.user_get_attendee_list(self.context.get('port'), self.context.get('session_id'), module_name, module_id)
for attendee in attendee_dict:
user_id = self.xml_id_exist(self.TABLE_USER, attendee.get('id', False))
if user_id:
contact_id = False
else:
contact_id = self.xml_id_exist(self.TABLE_CONTACT, attendee.get('id', False))
fields = ['user_id/id', 'email', 'partner_address_id/id']
data = [user_id or False, attendee.get('email1'), contact_id]
attendee_xml_id = self.import_object(fields, data, 'calendar.attendee', self.TABLE_ATTENDEE, user_id or contact_id or attendee.get('email1'), ['|',('user_id', '=', attendee.get('id')),('partner_address_id','=',attendee.get('id')),('email', '=', attendee.get('email1'))])
attendee_id.append(attendee_xml_id)
return ','.join(attendee_id)
def get_alarm_id(self, dict_val, val):
alarm_dict = {
@ -122,16 +489,22 @@ class sugar_import(import_framework):
return self.mapped_id_if_exist('res.alarm', [('name', 'like', alarm_dict.get(val))], 'alarm', val)
#TODO attendees
def import_meeting(self, val):
attendee_id = self.get_attendee_id(self.cr, self.uid, 'Meetings', val.get('id')) #TODO
val['attendee_ids/id'] = attendee_id
return val
def get_meeting_mapping(self):
return {
'model' : 'crm.meeting',
'dependencies' : [self.TABLE_CONTACT, self.TABLE_OPPORTUNITY, self.TABLE_LEAD],
'hook': self.import_meeting,
'map' : {
'name': 'name',
'date': 'date_start',
'duration': call(self.get_float_time, value('duration_hours'), value('duration_minutes')),
'location': 'location',
'attendee_ids/id':'attendee_ids/id',
'alarm_id/id': call(self.get_alarm_id, value('reminder_time')),
'user_id/id': ref(self.TABLE_USER, 'assigned_user_id'),
'partner_id/id': related_ref(self.TABLE_ACCOUNT),
@ -143,6 +516,14 @@ class sugar_import(import_framework):
"""
import Opportunity
"""
opp_state = {
'Need Analysis' : 'New',
'Closed Lost': 'Lost',
'Closed Won': 'Won',
'Value Proposition': 'Proposition',
'Negotiation/Review': 'Negotiation'
}
def get_opportunity_status(self, sugar_val):
fields = ['name', 'type']
name = 'Opportunity_' + sugar_val['sales_stage']
@ -180,7 +561,7 @@ class sugar_import(import_framework):
def get_opp_mapping(self):
return {
'model' : 'crm.lead',
'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT],
'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT,self.TABLE_COMPAIGN],
'hook' : self.import_opp,
'map' : {
'name': 'name',
@ -195,10 +576,22 @@ class sugar_import(import_framework):
'type' : const('opportunity'),
'categ_id/id': call(self.get_category, 'crm.lead', value('opportunity_type')),
'email_from': 'email_from',
'state' : const('open'), #TODO
'state': map_val('status', self.opp_state) , #TODO
}
}
"""
import campaign
"""
def get_compaign_mapping(self):
return {
'model' : 'crm.case.resource.type',
'map' : {
'name': 'name',
}
}
"""
import lead
"""
@ -221,7 +614,6 @@ class sugar_import(import_framework):
def import_lead(self, val):
if val.get('opportunity_id'): #if lead is converted into opp, don't import as lead
return False
if val.get('primary_address_country'):
country_id = self.get_all_countries(val.get('primary_address_country'))
val['country_id/id'] = country_id
@ -231,6 +623,7 @@ class sugar_import(import_framework):
def get_lead_mapping(self):
return {
'model' : 'crm.lead',
'dependencies' : [self.TABLE_COMPAIGN],
'hook' : self.import_lead,
'map' : {
'name': concat('first_name', 'last_name'),
@ -253,7 +646,8 @@ class sugar_import(import_framework):
'fax': 'phone_fax',
'referred': 'refered_by',
'optout': 'do_not_call',
'type_id/id': call(self.get_campaign_id, value('lead_source')),
'channel_id/id': call(self.get_channel_id, value('lead_source')),
'type_id/id': ref(self.TABLE_COMPAIGN, 'campaign_id'),
'country_id/id': 'country_id/id',
'state_id/id': 'state_id/id'
}
@ -263,14 +657,16 @@ class sugar_import(import_framework):
import contact
"""
def get_email(self, val):
return val.get('email1') + ','+ val.get('email2')
email_address = sugar.get_contact_by_email(self.context.get('port'), self.context.get('username'), self.context.get('password'), val.get('email1'))
if email_address:
return ','.join(email_address)
def import_contact(self, val):
if val.get('primary_address_country'):
country_id = self.get_all_countries(val.get('primary_address_country'))
state = self.get_all_states(val.get('primary_address_state'), country_id)
val['country_id/id'] = country_id
val['state_id/id'] = state
val['state_id/id'] = state
return val
def get_contact_mapping(self):
@ -317,7 +713,6 @@ class sugar_import(import_framework):
'type': 'type',
}
if val.get(type_address +'_address_country'):
country_id = self.get_all_countries(val.get(type_address +'_address_country'))
state = self.get_all_states(val.get(type_address +'_address_state'), country_id)
@ -378,6 +773,9 @@ class sugar_import(import_framework):
'street': 'address_street',
'zip': 'address_postalcode',
'fax': 'fax',
'phone': 'phone_work',
'mobile':'phone_mobile',
'email': 'email1'
}
if val.get('address_country'):
@ -387,7 +785,7 @@ class sugar_import(import_framework):
val['state_id/id'] = state_id
return self.import_object_mapping(map_user_address, val, 'res.partner.address', self.TABLE_CONTACT, val['id'], self.DO_NOT_FIND_DOMAIN)
def get_employee_mapping(self):
return {
'model' : 'hr.employee',
@ -399,7 +797,7 @@ class sugar_import(import_framework):
'mobile_phone': 'phone_mobile',
'user_id/id': ref(self.TABLE_USER, 'id'),
'address_home_id/id': self.get_user_address,
'notes': 'description',
'notes': ppconcat('messenger_type', 'messenger_id', 'description'),
'job_id/id': self.get_job_id,
}
}
@ -449,10 +847,23 @@ class sugar_import(import_framework):
self.TABLE_LEAD : self.get_lead_mapping(),
self.TABLE_OPPORTUNITY : self.get_opp_mapping(),
self.TABLE_MEETING : self.get_meeting_mapping(),
self.TABLE_CALL : self.get_calls_mapping(),
self.TABLE_TASK : self.get_task_mapping(),
self.TABLE_PROJECT : self.get_project_mapping(),
self.TABLE_PROJECT_TASK: self.get_project_task_mapping(),
self.TABLE_BUG: self.get_project_issue_mapping(),
self.TABLE_CASE: self.get_crm_claim_mapping(),
self.TABLE_NOTE: self.get_history_mapping(),
self.TABLE_EMAIL: self.get_email_mapping(),
self.TABLE_DOCUMENT: self.get_document_mapping(),
self.TABLE_COMPAIGN: self.get_compaign_mapping()
}
def get_email_subject(self, result):
return "your sugarcrm data were successfully imported at %s" % self.date_ended
def get_body_header(self, result):
return "Sugarcrm import : report of last import"
class import_sugarcrm(osv.osv):
@ -461,6 +872,11 @@ class import_sugarcrm(osv.osv):
_name = "import.sugarcrm"
_description = __doc__
_columns = {
'username': fields.char('User Name', size=64, required=True),
'password': fields.char('Password', size=24,required=True),
'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."),
'opportunity': fields.boolean('Leads and Opportunities', help="If Opportunities are checked, SugarCRM opportunities data imported in OpenERP crm-Opportunity form"),
'user': fields.boolean('Users', 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"),
@ -476,8 +892,9 @@ class import_sugarcrm(osv.osv):
'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"),
'document': fields.boolean('Documents', help="If Documents is checked, SugarCRM Documents data imported in OpenERP Document Form"),
'username': fields.char('User Name', size=64),
'password': fields.char('Password', size=24),
'email_from': fields.char('Notify End Of Import To:', size=128),
'instance_name': fields.char("Instance's Name", size=64, help="Prefix of SugarCRM id to differentiate xml_id of SugarCRM models datas come from different server."),
}
_defaults = {#to be set to true, but easier for debugging
'opportunity': False,
@ -493,7 +910,12 @@ class import_sugarcrm(osv.osv):
'project' : False,
'project_task': False,
'bug': False,
'document': False
'document': False,
'instance_name': 'sugarcrm',
'email_from': 'tfr@openerp.com',
'username' : 'tfr',
'password' : 'a',
'url': "http://localhost/sugarcrm/soap.php"
}
def get_key(self, cr, uid, ids, context=None):
@ -502,6 +924,7 @@ class import_sugarcrm(osv.osv):
context = {}
key_list = []
for current in self.browse(cr, uid, ids, context):
context.update({'username': current.username, 'password': current.password, 'url': current.url, 'email_user': current.email_from or False, 'instance_name': current.instance_name or False})
if current.opportunity:
key_list.append('Leads')
key_list.append('Opportunities')
@ -520,27 +943,55 @@ class import_sugarcrm(osv.osv):
if current.call:
key_list.append('Calls')
if current.claim:
key_list.append('Claims')
key_list.append('Cases')
if current.email:
key_list.append('Emails')
if current.project:
key_list.append('Projects')
key_list.append('Project')
if current.project_task:
key_list.append('Project Tasks')
key_list.append('ProjectTask')
if current.bug:
key_list.append('Bugs')
if current.attachment:
key_list.append('Notes')
if current.document:
key_list.append('Documents')
key_list.append('DocumentRevisions')
return key_list
def do_import_all(self, cr, uid, *args):
"""
scheduler Method
"""
print 'args of schedule method', args
context = {'username': args[4], 'password': args[5], 'url': args[3], 'instance_name': args[3]}
print context
imp = sugar_import(self, cr, uid, args[2], "import_sugarcrm", [args[1]], context)
imp.set_table_list(args[0])
imp.start()
return True
def import_from_scheduler_all(self, cr, uid, ids, context=None):
keys = self.get_key(cr, uid, ids, context)
if not keys:
raise osv.except_osv(_('Warning !'), _('Select Module to Import.'))
cron_obj = self.pool.get('ir.cron')
args = (keys,context.get('email_user'), context.get('instance_name'), context.get('url'), context.get('username'), context.get('password') )
new_create_id = cron_obj.create(cr, uid, {'name': 'Import SugarCRM datas','interval_type': 'hours','interval_number': 1, 'numbercall': -1,'model': 'import.sugarcrm','function': 'do_import_all', 'args': args, 'active': False})
return {
'name': 'SugarCRM Scheduler',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'ir.cron',
'res_id': new_create_id,
'type': 'ir.actions.act_window',
}
def import_all(self, cr, uid, ids, context=None):
# """Import all sugarcrm data into openerp module"""
keys = self.get_key(cr, uid, ids, context)
imp = sugar_import(self, cr, uid, "sugarcrm", "import_sugarcrm", ["tfr@openerp.com"], context)
imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", [context.get('email_user')], context)
imp.set_table_list(keys)
imp.start()

View File

@ -8,28 +8,60 @@
<field name="model">import.sugarcrm</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Import SugarCRM">
<group colspan="4" width="700">
<separator string="Select SugarCRM Module Name" colspan="4"/>
<form string="Import Data From SugarCRM">
<group colspan="4" width="800">
<separator string="Login Information" colspan="4"/>
<field name="url" colspan="4" widget="url"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
<separator string="Choose Data You Want to Import" colspan="4"/>
<group colspan="4" col="6">
<field name="opportunity" />
<field name= "meeting" />
<field name= "task" string="Meeting Tasks"/>
<field name= "call" />
<field name= "claim" />
<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"/>
<field name= "document" />
<field name= "attachment" string="History and Attachment" />
</group>
<field name="username" invisible="1"/>
<field name="password" invisible="1"/>
<group colspan="1" col="2">
<separator string="Module: Base" colspan="4"/>
<field name="user" />
<field name= "account" />
<field name= "contact" />
</group>
<group colspan="3" col="4">
<separator string="Module: CRM" colspan="4"/>
<field name="opportunity" />
<field name= "meeting" />
<field name= "task" string="Meeting Tasks"/>
<field name= "call" />
<field name= "claim" />
<field name= "email" />
</group>
<group colspan="2" col="2">
<separator string="Module: Project" colspan="4"/>
<field name= "project" />
<field name= "project_task" />
<field name= "bug" string="Project Issue"/>
</group>
<group colspan="1" col="2">
<separator string="Module: HR" colspan="4"/>
<field name= "employee" />
</group>
<group colspan="2" col="4">
<separator string="Module: Document" colspan="4"/>
<field name= "document" />
<field name= "attachment" string="History and Attachment" />
</group>
</group>
<group colspan="4">
<separator string="Email Notification When Import is finished" colspan="4"/>
<field name="email_from" widget="email" string="Email Address to Notify"/>
</group>
<group colspan="4">
<separator string="Multi Instance Management" colspan="4"/>
<field name="instance_name"/>
</group>
<group colspan="4">
<separator string="" colspan="4"/>
<button name="import_from_scheduler_all" string="Create Recurrent Report"
type="object" icon="terp-camera_test"/>
<label string="" colspan="2"/>
</group>
</group>
<separator string="" colspan="4" />
<group colspan="4" >
@ -53,6 +85,8 @@
<field name="target">new</field>
</record>
<menuitem name="SugarCRM" id="menu_sugarcrm" parent="base.menu_base_partner"/>
<menuitem name="Import SugarCRM" id="menu_sugarcrm_import" parent="menu_sugarcrm" action="action_import_sugarcrm" icon="STOCK_EXECUTE"/>
</data>
</openerp>

View File

@ -1,514 +0,0 @@
'''
Created on 9 mai 2011
@author: openerp
'''
#TODO old source code to be deleted once it's migrated
#print 'xml ids exist', sugar_obj.pool.get('ir.model.data').search(cr, uid, [('name', 'in', address_id )])
OPENERP_FIEDS_MAPS = {'Leads': 'crm.lead',
'Opportunities': 'crm.lead',
'Contacts': 'res.partner.address',
'Accounts': 'res.partner',
'Resources': 'resource.resource',
'Users': 'res.users',
'Meetings': 'crm.meeting',
'Calls': 'crm.phonecall',
'Claims': 'crm.claim',
'Employee': 'hr.employee',
'Project': 'project.project',
'ProjectTask': 'project.task',
'Bugs': 'project.issue',
'Documents': 'ir.attachment',
}
STATE_MAP = {
TABLE_CALL : {
'Planned' : 'open',
'Held':'done',
'Not Held': 'pending',
},
TABLE_TASK : {
'Completed' : 'done',
'Not Started':'draft',
'In Progress': 'open',
'Pending Input': 'draft',
'deferred': 'cancel'
},
TABLE_PROJECT: {
'Draft' : 'draft',
'In Review': 'open',
'Published': 'close',
},
TABLE_PROJECT_TASK: {
'Not Started': 'draft',
'In Progress': 'open',
'Completed': 'done',
'Pending Input': 'pending',
'Deferred': 'cancelled',
},
TABLE_CASE : {
'New' : 'draft',
'Assigned':'open',
'Closed': 'done',
'Pending Input': 'pending',
'Rejected': 'cancel',
'Duplicate': 'draft',
},
}
def get_related_objects(sugar_obj,cr,uid, id, TABLE_PARENT, TABLE_CHILD, context=None):
if not context:
context={}
PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''), context.get('url',''))
sugar_links = sugar.relation_search(PortType, sessionid, TABLE_PARENT, module_id=id, related_module=TABLE_CHILD, query=None, deleted=None)
res = []
for link in sugar_links:
xml_id = xml_id_exist(sugar_obj, cr, uid, TABLE_CHILD, link, context)
res.append(xml_id)
return res
def get_related_object(sugar_obj,cr,uid, id, TABLE_PARENT, TABLE_CHILD, context=None):
res = get_related_objects(sugar_obj,cr,uid, id, TABLE_PARENT, TABLE_CHILD, context)
return res and res[0] or ''
def get_contact_info_from_account(sugar_obj, cr, uid, account_id, context=None):
partner_id = get_mapped_id(sugar_obj, cr, uid, TABLE_ACCOUNT, account_id, context)
partner_address_id = False
partner_phone = False
partner_email = False
if not partner_id:
return partner_address_id, partner_phone,partner_email
partner = sugar_obj.pool.get('res.partner').browse(cr, uid, [partner_id], context=context)[0]
if partner.address and partner.address[0]:
address = partner.address[0]
partner_address_id = address.id
partner_phone = address.phone
partner_email = address.email
return partner_address_id, partner_phone,partner_email
def get_project_task_state(sugar_obj, cr, uid, val,context=None):
if not context:
context = {}
state_dict = {}
state = state_dict['status'].get(val, '')
return state
def import_documents(sugar_obj, cr, uid, context=None):
if not context:
context = {}
map_document = {'id' : 'id',
'name': 'filename',
'description': 'description',
'datas': 'datas',
'datas_fname': 'datas_fname',
}
attach_obj = sugar_obj.pool.get('ir.attachment')
PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''), context.get('url',''))
sugar_data = sugar.search(PortType,sessionid, 'DocumentRevisions')
for val in sugar_data:
filepath = '/var/www/sugarcrm/cache/upload/'+ val.get('id')
f = open(filepath, "r")
datas = f.read()
f.close()
val['datas'] = base64.encodestring(datas)
val['datas_fname'] = val.get('filename')
fields, datas = sugarcrm_fields_mapp(val, map_document, context)
attach_obj.import_data(cr, uid, fields, [datas], mode='update', current_module='sugarcrm_import', noupdate=True, context=context)
def import_tasks(sugar_obj, cr, uid, context=None):
map_task = {
'name': 'name',
'date': ['__datetime__', 'date_start'],
'date_deadline' : ['__datetime__', 'date_due'],
'user_id/id': 'user_id/id',
'categ_id/id': 'categ_id/id',
'partner_id/id': 'partner_id/id',
'partner_address_id/id': 'partner_address_id/id',
'state': 'state'
}
sugar_data = get_sugar_data(TABLE_TASK, context)
for val in sugar_data:
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'], context)
val['partner_id/id'] = get_related_id(sugar_obj, cr, uid, val, TABLE_ACCOUNT, context)
val['partner_address_id/id'] = get_related_id(sugar_obj, cr, uid, val, TABLE_CONTACT, context) or xml_id_exist(sugar_obj, cr, uid, TABLE_CONTACT, val['contact_id'], context)
val['categ_id/id'] = get_category(sugar_obj, cr, uid, 'crm.meeting', 'Tasks')
val['state'] = STATE_MAP[TABLE_TASK].get(val['status'])
val['date_start'] = val['date_start'] or datetime.now().strftime('%Y-%m-%d %H:%M:%S')
val['date_due'] = val['date_due'] or datetime.now().strftime('%Y-%m-%d %H:%M:%S')
import_module(sugar_obj, cr, uid, 'crm.meeting', map_task, sugar_data, TABLE_TASK, context=context)
#TODO
def get_attendee_id(sugar_obj, cr, uid, module_name, module_id, context=None):
if not context:
context = {}
PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''), context.get('url',''))
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)
#TODO there is more then just user in attendee list
#there is contact, partner, lead (but we don't import the link) and user
for user in user_dict:
continue
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)]})
def import_meetings(sugar_obj, cr, uid, context=None):
map_meeting =
sugar_data = get_sugar_data(TABLE_MEETING, context)
for val in sugar_data:
val['alarm_id/id'] = get_alarm_id(sugar_obj, cr, uid, val.get('reminder_time'), context)
get_attendee_id(sugar_obj, cr, uid, 'Meetings', val.get('id'), context) #TODO
import_module(sugar_obj, cr, uid, 'crm.meeting', map_meeting, sugar_data, TABLE_MEETING, context=context)
def import_calls(sugar_obj, cr, uid, context=None):
if not context:
context = {}
map_calls = {
'name': 'name',
'date': ['__datetime__', 'date_start'],
'duration': ['duration_hours', 'duration_minutes'],
'user_id/id': 'user_id/id',
'partner_id/id': 'partner_id/id',
'partner_address_id/id': 'partner_address_id/id',
'categ_id/id': 'categ_id/id',
'state': 'state',
'opportunity_id/id': 'opportunity_id/id',
'description': 'description',
}
sugar_data = get_sugar_data('Calls', context)
for val in sugar_data:
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'], context)
val['opportunity_id/id'] = get_related_id(sugar_obj, cr, uid, val, [TABLE_OPPORTUNITY, TABLE_LEAD], context)
val['partner_id/id'] = get_related_id(sugar_obj, cr, uid, val, [TABLE_ACCOUNT], context)
val['partner_address_id/id'] = get_related_id(sugar_obj, cr, uid, val, [TABLE_CONTACT], context)
val['state'] = STATE_MAP[TABLE_CALL].get(val['status'])
val['categ_id/id'] = get_category(sugar_obj, cr, uid, 'crm.phonecall', val.get('direction'))
import_module(sugar_obj, cr, uid, 'crm.phonecall', map_calls, sugar_data, TABLE_CALL, context=context)
def get_bug_priority(sugar_obj, cr, uid, val,context=None):
if not context:
context = {}
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_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 import_claims(sugar_obj, cr, uid, context=None):
map_claim = {
'name': 'name',
'date': ['__datetime__', 'date_entered'],
'user_id/id': 'user_id/id',
'priority':'priority',
'partner_id/id': 'partner_id/id',
'partner_address_id/.id': 'partner_address_id/.id',
'partner_phone': 'partner_phone',
'email_from': 'email_from',
'description': 'description',
'state': 'state',
}
def get_claim_priority(val):
priority_dict = {
'High': '2',
'Medium': '3',
'Low': '4'
}
return priority_dict.get(val, '')
sugar_data = get_sugar_data(TABLE_CASE, context)
print sugar_data
for val in sugar_data:
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'], context)
val['partner_address_id/.id'], val['partner_phone'],val['email_from'] = get_contact_info_from_account(sugar_obj, cr, uid, val['account_id'], context)
val['partner_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_ACCOUNT, val['account_id'], context=context)
val['priority'] = get_claim_priority(val.get('priority'))
val['state'] = STATE_MAP[TABLE_CASE].get( val.get('status'))
print "cases"
pp.pprint(val)
import_module(sugar_obj, cr, uid, 'crm.claim', map_claim, sugar_data, TABLE_CASE, context=context)
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': ['__prettyprint__','description', 'bug_number', 'fixed_in_release_name', 'source', 'fixed_in_release', 'work_log', 'found_in_release', 'release_name', 'resolution'],
'state': 'state',
}
issue_obj = sugar_obj.pool.get('project.issue')
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, 'Bugs')
for val in sugar_data:
project_ids = project_obj.search(cr, uid, [('name', 'like', 'sugarcrm_bugs')])
if project_ids:
project_id = project_ids[0]
else:
project_id = project_obj.create(cr, uid, {'name':'sugarcrm_bugs'})
val['project_id/.id'] = project_id
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_mapp(val, map_resource, context)
issue_obj.import_data(cr, uid, fields, [datas], mode='update', current_module=MODULE_NAME, noupdate=True, context=context)
def get_attachment(sugar_obj, cr, uid, val, model, File, Filename, parent_type, 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')
attach_ids = attachment_obj.search(cr, uid, [('res_id','=', val.get('res_id'), ('res_model', '=', val.get('model')))])
if not attach_ids and Filename:
if parent_type == 'Accounts':
new_attachment_id = attachment_obj.create(cr, uid, {'name': Filename, 'datas_fname': Filename, 'datas': File, 'res_id': val.get('res_id', False),'res_model': val.get('model',False), 'partner_id': val.get('partner_id/.id')})
else:
new_attachment_id = attachment_obj.create(cr, uid, {'name': Filename, 'datas_fname': Filename, 'datas': File, 'res_id': val.get('res_id', False),'res_model': val.get('model',False)})
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:
if parent_type == 'Accounts':
mailgate_obj.write(cr, uid, [message_xml_id[0].res_id], {'attachment_ids': [(4, new_attachment_id)], 'partner_id': val.get('partner_id/.id')})
else:
mailgate_obj.write(cr, uid, [message_xml_id[0].res_id], {'attachment_ids': [(4, new_attachment_id)]})
def import_history(sugar_obj, cr, uid, context=None):
if not context:
context = {}
map_attachment = {'id' : 'id',
'name':'name',
'date': ['__datetime__', 'date_entered'],
'user_id/id': 'assigned_user_id',
'description': ['__prettyprint__','description', 'description_html'],
'res_id': 'res_id',
'model': 'model',
'partner_id/.id' : 'partner_id/.id',
}
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, Filename = sugar.attachment_search(PortType, sessionid, 'Notes', val.get('id'))
model_ids = model_obj.search(cr, uid, [('name', 'like', val.get('parent_id')),('model','=', OPENERP_FIEDS_MAPS[val.get('parent_type')])])
if model_ids:
model = model_obj.browse(cr, uid, model_ids)[0]
if model.model == 'res.partner':
val['partner_id/.id'] = model.res_id
else:
val['res_id'] = model.res_id
val['model'] = model.model
fields, datas = sugarcrm_fields_mapp(val, map_attachment, context)
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, Filename, val.get('parent_type'), context)
#Validated
def import_emails(sugar_obj, cr, uid, context=None):
if not context:
context= {}
map_emails = {
'id': 'id',
'name':'name',
'date':['__datetime__', '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': ['__prettyprint__', 'description', 'description_html'],
'res_id': 'res_id',
'model': 'model',
'partner_id/.id': 'partner_id/.id'
}
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')),('model','=', OPENERP_FIEDS_MAPS[val.get('parent_type')])])
for model in model_obj.browse(cr, uid, model_ids):
if model.model == 'res.partner':
val['partner_id/.id'] = model.res_id
else:
val['res_id'] = model.res_id
val['model'] = model.model
fields, datas = sugarcrm_fields_mapp(val, map_emails, context)
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):
map_project = {
'name': 'name',
'date_start': ['__datetime__', 'estimated_start_date'],
'date': ['__datetime__', 'estimated_end_date'],
'user_id/id': 'user_id/id',
'partner_id/id': 'partner_id/id',
'contact_id/id' : 'contact_id/id',
'state': 'state'
}
sugar_data = get_sugar_data(TABLE_PROJECT, context)
for val in sugar_data:
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'], context)
val['partner_id/id'] = get_related_object(sugar_obj,cr,uid, val['id'], TABLE_PROJECT, TABLE_ACCOUNT, context)
val['contact_id/id'] = get_related_object(sugar_obj,cr,uid, val['id'], TABLE_PROJECT, TABLE_CONTACT, context)
val['state'] = STATE_MAP[TABLE_PROJECT].get(val['status'])
import_module(sugar_obj, cr, uid, 'project.project', map_project, sugar_data, TABLE_PROJECT, context)
def import_project_tasks(sugar_obj, cr, uid, context=None):
map_project_task = {
'name': 'name',
'date_start': ['__datetime__', 'date_start'],
'date_end': ['__datetime__', 'date_finish'],
'progress': 'progress',
'project_id/id': 'project_id/id',
'planned_hours': 'planned_hours',
'total_hours': 'total_hours',
'priority': 'priority',
'description': 'description',
'user_id/id': 'user_id/id',
'state': 'state'
}
def get_project_task_priority(val):
priority_dict = {
'High': '0',
'Medium': '2',
'Low': '3'
}
return priority_dict.get(val, '')
sugar_data = get_sugar_data(TABLE_PROJECT_TASK, context)
for val in sugar_data:
val['project_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_PROJECT, val['project_id'], context)
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'], context)
val['state'] = STATE_MAP[TABLE_PROJECT_TASK].get( val.get('status'))
val['priority'] = get_project_task_priority(val.get('priority'))
import_module(sugar_obj, cr, uid, 'project.task', map_project_task, sugar_data, TABLE_PROJECT_TASK, context)
MAP_FIELDS = {'Documents':
{'dependencies' : ['Users'],
'process' : import_documents,
},
'Tasks':
{'dependencies' : ['Accounts', 'Contacts', 'Users'],
'process' : import_tasks,
},
'Calls':
{'dependencies' : ['Accounts', 'Contacts', 'Users', 'Opportunities', 'Leads'],
'process' : import_calls,
},
'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,
},
'Claims':
{'dependencies' : ['Users', 'Accounts', 'Contacts', 'Leads'],
'process' : import_claims,
},
'Emails':
{'dependencies' : ['Users', 'Projects', 'Project Tasks', 'Accounts', 'Contacts', 'Leads', 'Opportunities', 'Meetings', 'Calls'],
'process' : import_emails,
},
'Notes':
{'dependencies' : ['Users', 'Projects', 'Project Tasks', 'Accounts', 'Contacts', 'Leads', 'Opportunities', 'Meetings', 'Calls'],
'process' : import_history,
},
}

View File

@ -93,6 +93,23 @@ def user_get_attendee_list(portType, sessionid, module_name=None, module_id=None
attendee_list.append(attendee_dict)
return attendee_list
def get_contact_by_email(portType, username, password, email_address=None):
se_req = contact_by_emailRequest()
se_req._user_name = username
se_req._password = password
se_req._email_address = email_address
try:
se_resp = portType.contact_by_email(se_req)
email_list = []
for list in se_resp.get_element_return():
if list.Email_address in email_list:
continue
elif list.Email_address:
email_list.append(list.Email_address)
return email_list
except Exception,e:
return 'Exception: %s\n' % (tools.ustr(e))
def search(portType, sessionid, module_name=None):
se_req = get_entry_listRequest()
se_req._session = sessionid

View File

@ -19,5 +19,4 @@
#
##############################################################################
import sugarcrm_login
import import_message

View File

@ -1,62 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
from tools.translate import _
from import_sugarcrm import sugar
class sugarcrm_login(osv.osv):
"""SugarCRM Login"""
_name = "sugarcrm.login"
_description = __doc__
_columns = {
'username': fields.char('User Name', size=64, required=True),
'password': fields.char('Password', size=24,required=True),
'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' : 'tfr',
'password' : 'a',
'url': "http://localhost/sugarcrm/soap.php"
}
def open_import(self, cr, uid, ids, context=None):
for current in self.browse(cr, uid, ids, context):
PortType,sessionid = sugar.login(current.username, current.password, current.url)
if sessionid == '-1':
raise osv.except_osv(_('Error !'), _('Authentication error !\nBad Username or Password !'))
obj_model = self.pool.get('ir.model.data')
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','import.sugarcrm.form')])
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
context.update({'rec_id': ids, 'username': current.username, 'password': current.password, 'url': current.url})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'import.sugarcrm',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'context': context
}
sugarcrm_login()

View File

@ -1,46 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Sugarcrm Login Form View -->
<record model="ir.ui.view" id="view_sugarcrm_login_form">
<field name="name">sugarcrm.login.form</field>
<field name="model">sugarcrm.login</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="SugarCRM Login">
<group colspan="4" width="500" >
<separator string="Connection with SugarCRM" colspan="4"/>
<field name="url" colspan="4" widget="url"/>
<field name="username"/>
<newline/>
<field name="password" password="True" />
</group>
<separator string="" colspan="4" />
<group colspan="4" >
<label string="" colspan="2"/>
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button name="open_import" string="_Login"
type="object" icon="terp-camera_test"/>
</group>
</form>
</field>
</record>
<!-- Sugarcrm Login Action -->
<record model="ir.actions.act_window" id="action_sugarcrm_login">
<field name="name">SugarCRM Login</field>
<field name="res_model">sugarcrm.login</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_sugarcrm_login_form"/>
<field name="target">new</field>
</record>
<menuitem name="SugarCRM" id="menu_sugarcrm" parent="base.menu_base_partner"/>
<menuitem name="Import SugarCRM" id="menu_sugarcrm_login" parent="menu_sugarcrm" action="action_sugarcrm_login" icon="STOCK_EXECUTE"/>
</data>
</openerp>