Having added some logging to orm.py (code piece below) you can see how it 
retrieves for several rows the correct partner_id (322998) for a given csv id 
(74).
Then for the same csv partner id (74) it retrieves 204047 as a partner_id. 
Which is incorrect and results in the error.


Logging of correct processed row


[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:IdField :['partner_id:id']
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:idValue 74
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:res_id 322998
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:EndIfField res_id 322998


Logging of incorrect processed row.

[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:IdField :['partner_id:id']
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:idValue 74
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:res_id 204047
[Tue Jan 20 2009 11:29:48] 
DEBUG:proccess_lines_method_NormalField_IDField:EndIfField res_id 204047
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[01]: Exception in call: 
Traceback (most recent call last):
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[02]:   File 
"wizard\__init__.pyo", line 73, in execute_cr
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[03]:   File "C:\Program 
Files\OpenERP 
AllInOne\Server\addons\base\module\wizard\wizard_module_upgrade.py", line 92, 
in _upgrade_module
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[04]:   File "pooler.pyo", line 
55, in restart_pool
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[05]:   File "pooler.pyo", line 
38, in get_db_and_pool
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[06]:   File 
"addons\__init__.pyo", line 638, in load_modules
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[07]:   File 
"addons\__init__.pyo", line 539, in load_module_graph
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[08]:   File "tools\convert.pyo", 
line 837, in convert_csv_import
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[09]:   File "C:\Program 
Files\OpenERP AllInOne\Server\library.zip\osv\orm.py", line 647, in import_data
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[10]:   File "C:\Program 
Files\OpenERP AllInOne\Server\addons\base\ir\ir_model.py", line 488, in _update
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[11]:   File "C:\Program 
Files\OpenERP AllInOne\Server\library.zip\osv\orm.py", line 2416, in create
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[12]:   File "C:\Program 
Files\OpenERP AllInOne\Server\library.zip\sql_db.py", line 76, in wrapper
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[13]:   File "C:\Program 
Files\OpenERP AllInOne\Server\library.zip\sql_db.py", line 128, in execute
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[14]: IntegrityError: insert or 
update on table "order_history" violates foreign key constraint 
"order_history_partner_id_fkey"
[Tue Jan 20 2009 11:29:48] ERROR:web-services:[15]: DETAIL:  Key 
(partner_id)=(204047) is not present in table "res_partner".

modified code orm.py process_lines

         #
            # Import normal fields
            #
            for i in 
range(len(fields)):
                if i >= 
len(line):
                    raise 
Exception(_('Please check that all your lines have %d columns.') % 
(len(fields),))
                field = 
fields[i]
                if field == 
["id"]:
                    data_id = 
line[i]
                    continue
                if 
(len(field)==len(prefix)+1) and 
field[len(prefix)].endswith(':id'):
               #Added Logging
                    
logger.notifyChannel('proccess_lines_method_NormalField_IDField', 
netsvc.LOG_DEBUG, 'IdField :'+str(field))      
 
                    res_id = 
False
                    if 
line[i]:
                 
 #Added Logging
                      
  logger.notifyChannel('proccess_lines_method_NormalField_IDField', 
netsvc.LOG_DEBUG, 'idValue '+str(line[i]))    
   
                      
  if 
fields_def[field[len(prefix)][:-3]]['type']=='many2many':
                 
    #Added Logging
                      
      
logger.notifyChannel('proccess_lines_method_NormalField_IDField', 
netsvc.LOG_DEBUG, 'many2many '+str(field))      
 
                      
      res_id = []
                      
      for word in line[i].split(','):
                      
          if '.' in word:
                      
              module, xml_id = 
word.rsplit('.', 1)
                      
          else:
                      
              module, xml_id = 
current_module, word
                      
          ir_model_data_obj = 
self.pool.get('ir.model.data')
                      
          id = ir_model_data_obj._get_id(cr, uid, 
module,
                      
                  xml_id)
                      
          res_id2 = ir_model_data_obj.read(cr, 
uid, [id],
                      
                  
['res_id'])[0]['res_id']
                      
          if res_id2:
                      
              res_id.append(res_id2)
                      
      if len(res_id):
                      
          res_id = [(6, 0, res_id)]
                      
  else:                  
          
                      
      if '.' in line[i]:
                      
          module, xml_id = 
line[i].rsplit('.', 1)
                      
      else:
                      
          module, xml_id = current_module, 
line[i]
                      
      ir_model_data_obj = self.pool.get('ir.model.data')
                      
      id = ir_model_data_obj._get_id(cr, uid, module, 
xml_id)
                      
      res_id = ir_model_data_obj.read(cr, uid, [id],
                      
              
['res_id'])[0]['res_id']
                 
    #Added Logging
                      
      
logger.notifyChannel('proccess_lines_method_NormalField_IDField', 
netsvc.LOG_DEBUG, 'res_id '+str(res_id))       
                    
row[field[0][:-3]] = res_id or False
               #Added Logging
                    
logger.notifyChannel('proccess_lines_method_NormalField_IDField', 
netsvc.LOG_DEBUG, 'EndIfField res_id'+str(res_id))    
   
                    continue

> 

> 





-------------------- m2f --------------------

--
http://www.openerp.com/forum/viewtopic.php?p=28711#28711

-------------------- m2f --------------------


_______________________________________________
Tinyerp-users mailing list
http://tiny.be/mailman/listinfo/tinyerp-users

Reply via email to