This question has been flagged
1 Reply
5952 Views

Hi,
In the process of loading big amount of data into tables, I noticed that when restarting the server updating my custom module, the data previously entered was deleted from the database automatically !

I use the load() method and for each record I specified an xml_id (external id) so that running the same import twice would only update records. When looking at the the external ids created, I noticed that the noupdate field was automatically set to False.

Those records are therefore deleted when updating the module, as part of the module update protocol.

Can anyone help on how to intruct the load() method to forcecreate / set no update = True on the xml_ids of my newly created records ?

Doc reference:

Avatar
Discard
Author Best Answer

As a temporary workaround I added the following to my import function: From the ids returned by the load() method, I search for corresponding ir_model_data entries, and update their 'noupdate' field to True.

res = partner_pool.load(cr, uid, field_names, partners, context=context)

if res['ids']:
    imd_pool = self.pool.get('ir.model.data')
    imd_ids  = imd_pool.search(cr, uid, [('res_id','in',res['ids']),('model','=','res.partner')], context=context)
    _logger.debug("Fixing external ids with no update = True on : %s" % imd_ids)
    if imd_ids:
        imd_pool.write(cr, uid, imd_ids, {'noupdate':True}, context=context)
Avatar
Discard