diff --git a/addons/import_base/import_framework.py b/addons/import_base/import_framework.py index d041951ca11..817604ec13b 100644 --- a/addons/import_base/import_framework.py +++ b/addons/import_base/import_framework.py @@ -78,6 +78,13 @@ class import_framework(Thread): """ return [{}] + def get_link(self, from_table, ids, to_table): + """ + @return: a dictionaries that contains the association between the id (from_table) + and the list (to table) of id linked + """ + return {} + def get_mapping(self): """ @return: { TABLE_NAME : { @@ -387,7 +394,7 @@ class import_framework(Thread): if not self.email: return tools.email_send( - 'import_sugarcrm@module.openerp', + 'import@module.openerp', self.email, self.get_email_subject(result), self.get_email_body(result), diff --git a/addons/import_sugarcrm/doc/Installation Guidline For SugarCRM.doc b/addons/import_sugarcrm/doc/Installation Guidline For SugarCRM.doc new file mode 100644 index 00000000000..448f2291cf6 Binary files /dev/null and b/addons/import_sugarcrm/doc/Installation Guidline For SugarCRM.doc differ diff --git a/addons/import_sugarcrm/import_sugarcrm.py b/addons/import_sugarcrm/import_sugarcrm.py index 0e20deb4663..3ed2d14b78d 100644 --- a/addons/import_sugarcrm/import_sugarcrm.py +++ b/addons/import_sugarcrm/import_sugarcrm.py @@ -60,6 +60,7 @@ class sugar_import(import_framework): TABLE_NOTE = 'Notes' TABLE_EMAIL = 'Emails' TABLE_COMPAIGN = 'Campaigns' + TABLE_DOCUMENT = 'DocumentRevisions' TABLE_HISTORY_ATTACHMNET = 'history_attachment' def initialize(self): @@ -71,11 +72,11 @@ class sugar_import(import_framework): self.context['session_id'] = sessionid def get_data(self, table): - return sugar.search(self.context.get('port'), self.context.get('session_id'), table) + return sugar.search(self.context.get('port'), self.context.get('session_id'), table, 0, 500) + """ Common import method """ - def get_category(self, val, model, name): fields = ['name', 'object_id'] data = [name, model] @@ -111,6 +112,29 @@ class sugar_import(import_framework): min = int(min) * 100 / 60 return "%s.%i" % (hour, min) + """ + import Documents + """ + + def import_document(self, val): + File,Filename = sugar.get_document_revision_search(self.context.get('port'), self.context.get('session_id'), val.get('id')) + val['datas'] = base64.encodestring(File) + val['datas_fname'] = 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 """ @@ -126,16 +150,18 @@ class sugar_import(import_framework): return attach_xml_id def import_email(self, val): + vals = sugar.email_search(self.context.get('port'), self.context.get('session_id'), self.TABLE_EMAIL, val.get('id')) 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 + for val in vals: + 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_email_mapping(self): @@ -147,7 +173,7 @@ class sugar_import(import_framework): 'history' : const("1"), 'date':'date_sent', 'email_from': 'from_addr_name', - 'email_to': 'reply_to_addr', + 'email_to': 'to_addrs_names', 'email_cc': 'cc_addrs_names', 'email_bcc': 'bcc_addrs_names', 'message_id': 'message_id', @@ -248,6 +274,7 @@ class sugar_import(import_framework): 'description': ppconcat('description', 'resolution', 'work_log'), 'partner_id/id': ref(self.TABLE_ACCOUNT, 'account_id'), 'partner_address_id/.id': 'partner_address_id/.id', + 'categ_id/id': call(self.get_category, 'crm.claim', value('type')), 'partner_phone': 'partner_phone', 'email_from': 'email_from', 'priority': self.get_claim_priority, @@ -593,7 +620,6 @@ class sugar_import(import_framework): 'Dead': 'done', 'Converted': 'done', } - def import_lead(self, val): if val.get('opportunity_id'): #if lead is converted into opp, don't import as lead @@ -640,6 +666,12 @@ class sugar_import(import_framework): """ import contact """ + + def get_email(self, val): + 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')) @@ -665,7 +697,7 @@ class sugar_import(import_framework): 'city': 'primary_address_city', 'country_id/id': 'country_id/id', 'state_id/id': 'state_id/id', - 'email': concat('email1', 'email2', delimiter=','), + 'email': self.get_email, 'type': const('contact') } } @@ -673,37 +705,46 @@ class sugar_import(import_framework): """ import Account """ + def get_address_type(self, val, type): if type == 'invoice': type_address = 'billing' else: - type_address = 'shipping' - - map_partner_address = { + type_address = 'shipping' + + if type == 'default': + map_partner_address = { 'name': 'name', - 'phone': 'phone_office', - 'mobile': 'phone_mobile', - 'fax': 'phone_fax', - 'type': 'type', - 'street': type_address + '_address_street', - 'zip': type_address +'_address_postalcode', - 'city': type_address +'_address_city', - 'country_id/id': 'country_id/id', - 'type': 'type', + 'type': const('default'), + 'email': 'email1' } - + else: + map_partner_address = { + 'name': 'name', + 'phone': 'phone_office', + 'mobile': 'phone_mobile', + 'fax': 'phone_fax', + 'type': 'type', + 'street': type_address + '_address_street', + 'zip': type_address +'_address_postalcode', + 'city': type_address +'_address_city', + 'country_id/id': 'country_id/id', + '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) val['country_id/id'] = country_id val['state_id/id'] = state + val['type'] = type val['id_new'] = val['id'] + '_address_' + type return self.import_object_mapping(map_partner_address, val, 'res.partner.address', self.TABLE_CONTACT, val['id_new'], self.DO_NOT_FIND_DOMAIN) - + def get_partner_address(self, val): address_id=[] - type_dict = {'billing_address_street' : 'invoice', 'shipping_address_street' : 'delivery'} + type_dict = {'billing_address_street' : 'invoice', 'shipping_address_street' : 'delivery', 'type': 'default'} for key, type_value in type_dict.items(): if val.get(key): id = self.get_address_type(val, type_value) @@ -838,6 +879,7 @@ class sugar_import(import_framework): 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() } @@ -873,6 +915,7 @@ class import_sugarcrm(osv.osv): '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"), + 'document': fields.boolean('Documents', help="If Documents is checked, SugarCRM Documents data imported in OpenERP Document Form"), '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."), @@ -889,6 +932,7 @@ class import_sugarcrm(osv.osv): 'project' : False, 'project_task': False, 'bug': False, + 'document': False, 'instance_name': 'sugarcrm', 'email_from': 'tfr@openerp.com', 'username' : 'tfr', @@ -963,6 +1007,8 @@ class import_sugarcrm(osv.osv): key_list.append('ProjectTask') if current.bug: key_list.append('Bugs') + if current.document: + key_list.append('DocumentRevisions') return key_list @@ -994,7 +1040,6 @@ class import_sugarcrm(osv.osv): } - def import_all(self, cr, uid, ids, context=None): # """Import all sugarcrm data into openerp module""" diff --git a/addons/import_sugarcrm/import_sugarcrm_view.xml b/addons/import_sugarcrm/import_sugarcrm_view.xml index d9dad626b1c..e5e70d3b7eb 100644 --- a/addons/import_sugarcrm/import_sugarcrm_view.xml +++ b/addons/import_sugarcrm/import_sugarcrm_view.xml @@ -9,59 +9,72 @@ form
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -