summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortfr@openerp.com <>2011-04-21 14:40:47 +0200
committertfr@openerp.com <>2011-04-21 14:40:47 +0200
commit0e950f71a959cb5e6c2dfcd178671ed91c8c06cb (patch)
treed2866df3625c40a75eb39cd2f8552d2664c5724a
parente0dd0a77a03c9ca0057d49e535c9b2e24d9dfc7d (diff)
[FIX] category of task + simple map field
bzr revid: tfr@openerp.com-20110421124047-xcwdxqka3t4f31y1
-rw-r--r--addons/import_sugarcrm/import_sugarcrm.py50
-rw-r--r--addons/import_sugarcrm/sugarcrm_fields_mapping.py21
2 files changed, 37 insertions, 34 deletions
diff --git a/addons/import_sugarcrm/import_sugarcrm.py b/addons/import_sugarcrm/import_sugarcrm.py
index fcaedaaa4c5..34a58197872 100644
--- a/addons/import_sugarcrm/import_sugarcrm.py
+++ b/addons/import_sugarcrm/import_sugarcrm.py
@@ -306,7 +306,9 @@ def get_category(sugar_obj, cr, uid, model, name, context=None):
if categ_ids:
categ_id = categ_ids[0]
else:
- categ_id = categ_obj.create(cr, uid, {'name': name, 'object_id.model': model})
+ model_ids = sugar_obj.pool.get('ir.model').search(cr, uid, [('model', '=', model)], context=context)
+ model = model_ids and model_ids[0] or False
+ categ_id = categ_obj.create(cr, uid, {'name': name, 'object_id': model})
return categ_id
def get_alarm_id(sugar_obj, cr, uid, val, context=None):
@@ -424,7 +426,8 @@ def import_tasks(sugar_obj, cr, uid, context=None):
context = {}
map_task = {'id' : 'id',
'name': 'name',
- 'date': 'date_entered',
+ 'date': 'date_start',
+ 'date_deadline' : 'date_due',
'user_id/id': 'assigned_user_id',
'categ_id/.id': 'categ_id/.id',
'partner_id/.id': 'partner_id/.id',
@@ -523,7 +526,7 @@ def import_calls(sugar_obj, cr, uid, context=None):
'partner_id/.id': 'partner_id/.id',
'partner_address_id/.id': 'partner_address_id/.id',
'categ_id/.id': 'categ_id/.id',
- 'state': 'state',
+ 'state': 'state',
}
phonecall_obj = sugar_obj.pool.get('crm.phonecall')
PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
@@ -641,7 +644,7 @@ def get_attachment(sugar_obj, cr, uid, val, model, File, context=None):
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)]})
+ 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):
@@ -654,20 +657,21 @@ def import_history(sugar_obj, cr, uid, context=None):
'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 = 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):
+ 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)
+ 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):
@@ -991,19 +995,19 @@ class import_sugarcrm(osv.osv):
'username': fields.char('User Name', size=64),
'password': fields.char('Password', size=24),
}
- _defaults = {
- 'lead': True,
- 'opportunity': True,
- 'user' : True,
- 'contact' : True,
- 'account' : True,
- 'employee' : True,
- 'meeting' : True,
- 'call' : True,
- 'email' : True,
- 'project' : True,
- 'project_task': True,
- 'bug': True,
+ _defaults = { #to be set to true, but easier for debugging
+ 'lead': False,
+ 'opportunity': False,
+ 'user' : False,
+ 'contact' : False,
+ 'account' : False,
+ 'employee' : False,
+ 'meeting' : False,
+ 'call' : False,
+ 'email' : False,
+ 'project' : False,
+ 'project_task': False,
+ 'bug': False,
}
def get_key(self, cr, uid, ids, context=None):
diff --git a/addons/import_sugarcrm/sugarcrm_fields_mapping.py b/addons/import_sugarcrm/sugarcrm_fields_mapping.py
index aedd88346ee..d6f9c28732c 100644
--- a/addons/import_sugarcrm/sugarcrm_fields_mapping.py
+++ b/addons/import_sugarcrm/sugarcrm_fields_mapping.py
@@ -25,16 +25,15 @@ def sugarcrm_fields_mapp(dict_sugar, openerp_dict):
for key,val in openerp_dict.items():
if key not in fields and dict_sugar:
fields.append(key)
- if isinstance(val, list) and val:
- #Allow to print a bit more pretty way long list of data in the same field
- if len(val) >= 1 and val[0] == "__prettyprint__":
- val = val[1:]
- data_lst.append('\n\n'.join(map(lambda x : x + ": " + dict_sugar[x], val)))
- else:
- 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)))
+ if not isinstance(val, list):
+ val = [val]
+ #Allow to print a bit more pretty way long list of data in the same field
+ if len(val) >= 1 and val[0] == "__prettyprint__":
+ val = val[1:]
+ data_lst.append('\n\n'.join(map(lambda x : x + ": " + str(dict_sugar[x]), val)))
else:
- data_lst.append(dict_sugar.get(val,''))
+ if key == 'duration':
+ data_lst.append('.'.join(map(lambda x : str(dict_sugar[x]), val)))
+ else:
+ data_lst.append(' '.join(map(lambda x : str(dict_sugar[x]), val)))
return fields,data_lst