From 6923e2e880ea3d9d389dcf741a0ee6025d03b4c2 Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Mon, 2 May 2011 17:43:59 +0530 Subject: [PATCH] [FIX]: Fix datetime issue, contacts by emails issue. bzr revid: atp@tinyerp.com-20110502121359-i107e95eqxf4ojvs --- addons/import_sugarcrm/import_sugarcrm.py | 11 ++++++++--- addons/import_sugarcrm/sugar.py | 12 ------------ addons/import_sugarcrm/sugarcrm_fields_mapping.py | 8 +++++--- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/addons/import_sugarcrm/import_sugarcrm.py b/addons/import_sugarcrm/import_sugarcrm.py index bedfeaae8fd..5b1adfc8e29 100644 --- a/addons/import_sugarcrm/import_sugarcrm.py +++ b/addons/import_sugarcrm/import_sugarcrm.py @@ -159,7 +159,7 @@ def import_partner_address(sugar_obj, cr, uid, context=None): map_partner_address = { 'id': 'id', 'name': ['first_name', 'last_name'], - 'partner_id/id': 'account_id', + 'partner_id/id': 'partner_id/id', 'phone': 'phone_work', 'mobile': 'phone_mobile', 'fax': 'phone_fax', @@ -172,13 +172,18 @@ def import_partner_address(sugar_obj, cr, uid, context=None): 'email': 'email', 'type': 'type' } + model_obj = sugar_obj.pool.get('ir.model.data') 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: + account_xml_id = model_obj.search(cr, uid, [('model', '=', 'res.partner'), ('name', 'like', val.get('account_id'))]) + if not account_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')) + else: + val['partner_id/id'] = val.get('account_id') val['type'] = 'contact' - contact_emails = sugar.contact_emails_search(PortType, context.get('username', ''), context.get('password', ''), email_address=val.get('email1')) - val['email'] = (','.join(map(lambda x : x, contact_emails))) + val['email'] = val.get('email1') + ','+ val.get('email2') 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) diff --git a/addons/import_sugarcrm/sugar.py b/addons/import_sugarcrm/sugar.py index 6987071f443..ada2253e548 100644 --- a/addons/import_sugarcrm/sugar.py +++ b/addons/import_sugarcrm/sugar.py @@ -93,18 +93,6 @@ def user_get_attendee_list(portType, sessionid, module_name=None, module_id=None attendee_list.append(attendee_dict) return attendee_list -def contact_emails_search(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 - se_resp = portType.contact_by_email(se_req) - ans_list = [] - for list in se_resp._return: - if list.Email_address and list.Email_address not in ans_list: - ans_list.append(list.Email_address) - return ans_list - def search(portType, sessionid, module_name=None): se_req = get_entry_listRequest() se_req._session = sessionid diff --git a/addons/import_sugarcrm/sugarcrm_fields_mapping.py b/addons/import_sugarcrm/sugarcrm_fields_mapping.py index 46f7a038670..0a94740ccad 100644 --- a/addons/import_sugarcrm/sugarcrm_fields_mapping.py +++ b/addons/import_sugarcrm/sugarcrm_fields_mapping.py @@ -43,15 +43,17 @@ def sugarcrm_fields_mapp(dict_sugar, openerp_dict, context=None): if len(val) >= 1 and val[0] == "__prettyprint__": val = val[1:] data_lst.append('\n\n'.join(map(lambda x : x + ": " + dict_sugar.get(x,''), val))) - elif val[0] == '__datetime__' and dict_sugar.get(val[1]): + elif val[0] == '__datetime__': val = val[1] if dict_sugar.get(val) and len(dict_sugar.get(val))<=10: - updated_dt = date.fromtimestamp(time.mktime(time.strptime(dict_sugar.get(val), '%Y-%m-%d'))) - else: + updated_dt = date.fromtimestamp(time.mktime(time.strptime(dict_sugar.get(val), '%Y-%m-%d'))) or False + elif dict_sugar.get(val): convert_date = datetime.strptime(dict_sugar.get(val), '%Y-%m-%d %H:%M:%S') edate = convert_date.replace(tzinfo=au_tz) au_dt = au_tz.normalize(edate.astimezone(au_tz)) updated_dt = datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S') + else: + updated_dt = False data_lst.append(updated_dt) else: if key == 'duration':