[CLEAN] import accounté

bzr revid: tfr@openerp.com-20110504134322-5thxqred2rvzdl7w
This commit is contained in:
tfr@openerp.com 2011-05-04 15:43:22 +02:00
parent 3211a03568
commit e3a72eb273
2 changed files with 7 additions and 39 deletions

View File

@ -40,7 +40,6 @@ def xml_id_exist(obj, cr, uid, table, sugar_id, context=None):
id = obj.pool.get('ir.model.data')._get_id(cr, uid, MODULE_NAME, xml_id)
return id and xml_id or False
def mapped_id(obj, cr, uid, res_model, sugar_id, id, context=None):
"""
This function create the mapping between an already existing data and the similar data of sugarcrm
@ -58,9 +57,6 @@ def mapped_id(obj, cr, uid, res_model, sugar_id, id, context=None):
noupdate=True, res_id=id, context=context)
return sugar_id
def mapped_id_if_exist(sugar_obj, cr, uid, model, domain, xml_id, context=None):
"""
@param domain : search domain to find existing record, should return a unique record
@ -133,21 +129,6 @@ def import_object(sugar_obj, cr, uid, fields, data, model, table, name, domain_s
return xml_ref or xml_id
def add_m2o_data(data, fields, column, xml_ids):
"""
@param fields: list of fields
@param data: the list of the data, in the same order as the field
ex : fields = ['firstname', 'lastname'] ; data = ['John', 'Mc donalds']
@param column : name of the column that will contains the xml_id of o2m data
ex : contact_id/id
@param xml_ids : the list of xml id of the data
@return fields and data with the last column "column", "xml_id1,xml_id2,xml_id3,.."
"""
fields.append(column)
data.append(','.join(xml_ids))
return fields, data
#TODO for more then one field that need parent
def import_self_dependencies(obj, cr, uid, parent_field, datas, context):
"""

View File

@ -188,7 +188,8 @@ def import_partners(sugar_obj, cr, uid, context=None):
'ref': 'sic_code',
'comment': ['__prettyprint__', 'description', 'employees', 'ownership', 'annual_revenue', 'rating', 'industry', 'ticker_symbol'],
'customer': 'customer',
'supplier': 'supplier',
'supplier': 'supplier',
'address/id':'address/id',
}
def get_address_type(sugar_obj, cr, uid, val, type, context=None):
@ -219,8 +220,7 @@ def import_partners(sugar_obj, cr, uid, context=None):
val['state_id/id'] = state
val['type'] = type
val['id_new'] = val['id'] + '_address_' + type
fields, datas = sugarcrm_fields_mapp(val, map_partner_address)
return import_object(sugar_obj, cr, uid, fields, datas, 'res.partner.address', TABLE_CONTACT, val['id_new'], DO_NOT_FIND_DOMAIN, context=context)
return import_object_mapping(sugar_obj, cr, uid, map_partner_address, val, 'res.partner.address', TABLE_CONTACT, val['id_new'], DO_NOT_FIND_DOMAIN, context=context)
def get_address(sugar_obj, cr, uid, val, context=None):
address_id=[]
@ -232,30 +232,17 @@ def import_partners(sugar_obj, cr, uid, context=None):
return address_id
if not context:
context = {}
partner_obj = sugar_obj.pool.get('res.partner')
PortType, sessionid = sugar.login(context.get('username', ''), context.get('password', ''), context.get('url',''))
sugar_data = sugar.search(PortType, sessionid, 'Accounts')
sugar_data = get_sugar_data('Accounts', context)
for val in sugar_data:
add_id = get_address(sugar_obj, cr, uid, val, context)
val['customer'] = '1'
val['supplier'] = '0'
val['user_id/id'] = xml_id_exist(sugar_obj, cr, uid, TABLE_USER, val['assigned_user_id'])
val['id_new'] = generate_xml_id(val['id'], TABLE_ACCOUNT)
print "values of partner"
pp.pprint(val)
if val['parent_id']:
print 'parent_id', val['parent_id']
val['parent_id_new'] = generate_xml_id(val['parent_id'], TABLE_ACCOUNT)
val['parent_id_new'] = val['parent_id'] and generate_xml_id(val['parent_id'], TABLE_ACCOUNT) or ''
val['address/id'] = ','.join(add_id)
fields, data = sugarcrm_fields_mapp(val, map_partner)
fields, data = add_m2o_data(data, fields, 'address/id', add_id)
partner_obj.import_data(cr, uid, fields, [data], mode='update', current_module=MODULE_NAME, noupdate=True, context=context)
import_self_dependencies(partner_obj, cr, uid, 'parent_id', sugar_data, context)
import_module(sugar_obj, cr, uid, 'res.partner', map_partner, sugar_data, TABLE_ACCOUNT, context)
return True
def get_category(sugar_obj, cr, uid, model, name, context=None):