← Back to team overview

c2c-oerpscenario team mailing list archive

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

 

import and export have been completly rewritten in trunk. The import
compatible option is now very clean and useful.

The new syntax:
  id               (xml_id)
  .id              (database id)
  address/id (xml_id)
  address.id (database id)

I think :id is also working (address:id) to remain compatible with old
versions in import.

** Changed in: openobject-server/5.0
       Status: Triaged => Won't Fix

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

-- 
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:
  Fix Released
Status in OpenObject Server 5.0 series:
  Won't Fix
Status in OpenObject Server trunk series:
  Fix Released

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