← Back to team overview

c2c-oerpscenario team mailing list archive

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

 

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

-- 
Import CSV with existing  db_id-fields fails  
https://bugs.launchpad.net/bugs/646738
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to OpenERP OpenObject.

Status in OpenObject Server: New

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