Import CSV with existing db_id-fields fails

Bug #646738 reported by debaetsr
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Won't Fix
Undecided
Unassigned
Trunk
Fix Released
Low
OpenERP's Framework R&D

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

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Ruben,

   Would you please describe the exact steps that you followed to produce the error because I tried to import with existing db_ids and I was able to import the records.

Thanks.

Revision history for this message
debaetsr (rubendebaets) wrote :

Hello Anup,

I used V6.

1. Basic install
2. Installation of Belgian Dutch accounting scheme with other modules
3. manual transfer of partners with common import/export functions in openerp-client

4. Extracting to CSV from V5.0.14 database to spreadsheet of following tables as specified in the docs:
hr.attendance
account.move
account.move.line
account.invoice
account.invoice.line
account.invoice.tax
account.analytic.line

a. renaming fields adding :db_id where necessary
b. manual matching of the existing db_ids with the values in the csv-files (double checked)

5. create module for import in the above sequence

Problems encountered :
db_id not found (while existant).
Debugging with eclipse & pydev, showing the code above is never executed

Other problems encountered :
the csv_file account_move has an unique ID move_1, move_2 etc.
the import of account_move_line fails to find the previously imported move_ids. This can be solved by manually traversing the cache while debugging.
Afterwards, all move_lines are linked to the last move_id. Same thing for invoices and analytic.

I hope this helps.
Kind regards,
Ruben

Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

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.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.