← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 646738] Re: Import CSV with existing db_id-fields fails

 

** Also affects: openobject-server/5.0
   Importance: Undecided
       Status: New

** Also affects: openobject-server/trunk
   Importance: Undecided
       Status: New

** Changed in: openobject-server/5.0
       Status: New => Triaged

** Changed in: openobject-server/trunk
   Importance: Undecided => Low

** Changed in: openobject-server/trunk
       Status: New => Confirmed

** Changed in: openobject-server/trunk
     Assignee: (unassigned) => OpenERP's Framework R&D (openerp-dev-framework)

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/646738

Title:
  Import CSV with existing  db_id-fields fails  

Status in OpenObject Server:
  Confirmed
Status in OpenObject Server 5.0 series:
  Triaged
Status in OpenObject Server trunk series:
  Confirmed

Bug description:
  Importing a csv-file which references an existing ID in the database (eg. period_id:db_id), failes to find the correct database ID. 

I think this is due a mis-indentation in orm.py line 749-756. This  code is never reached, unless the indentation diminished by one:

Original starting line 730:

                if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'):
                        # Database ID
                    res = False
                    if line[i]:
                        field_name = field[0].split(':')[0]
                        model_rel = fields_def[field_name]['relation']

                        if fields_def[field[len(prefix)][:-6]]['type'] == 'many2many':
                            res_id = []
                            for db_id in line[i].split(config.get('csv_internal_sep')):
                                try:
                                    _check_db_id(self, model_rel, db_id)
                                    res_id.append(db_id)
                                except Exception, e:
                                    warning += [tools.exception_to_unicode(e)]
                                    logger.notifyChannel("import", netsvc.LOG_ERROR,
                                              tools.exception_to_unicode(e))
                            if len(res_id):
                                res = [(6, 0, res_id)]
                            else:
                                try:
                                    _check_db_id(self, model_rel, line[i])
                                    res = line[i]
                                except Exception, e:
                                    warning += [tools.exception_to_unicode(e)]
                                    logger.notifyChannel("import", netsvc.LOG_ERROR,
                                          tools.exception_to_unicode(e))
                        row[field_name] = res or False
                        continue


should be : 

 if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':db_id'):
                        # Database ID
                    res = False
                    if line[i]:
                        field_name = field[0].split(':')[0]
                        model_rel = fields_def[field_name]['relation']

                        if fields_def[field[len(prefix)][:-6]]['type'] == 'many2many':
                            res_id = []
                            for db_id in line[i].split(config.get('csv_internal_sep')):
                                try:
                                    _check_db_id(self, model_rel, db_id)
                                    res_id.append(db_id)
                                except Exception, e:
                                    warning += [tools.exception_to_unicode(e)]
                                    logger.notifyChannel("import", netsvc.LOG_ERROR,
                                              tools.exception_to_unicode(e))
                            if len(res_id):
                                res = [(6, 0, res_id)]
                     # remove one indendation of the following else: block. It would never by accessed otherwhise.
                        else:
                               try:
                                   _check_db_id(self, model_rel, line[i])
                                   res = line[i]
                               except Exception, e:
                                warning += [tools.exception_to_unicode(e)]
                                logger.notifyChannel("import", netsvc.LOG_ERROR,
                                          tools.exception_to_unicode(e))
                        row[field_name] = res or False
                        continue


Kind regards,
Ruben