diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 7d17cd72345..d64eeea75c4 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -3232,18 +3232,21 @@ class orm(orm_template): for sub_ids in cr.split_for_in_conditions(ids): cr.execute('delete from ' + self._table + ' ' \ 'where id IN %s', (sub_ids,)) - # Removing the ir_model_data reference if the record being deleted is a record created by xml/csv file. - + + # Removing the ir_model_data reference if the record being deleted is a record created by xml/csv file, + # as these are not connected with real database foreign keys, and would be dangling references. # Step 1. Calling unlink of ir_model_data only for the affected IDS. referenced_ids = pool_model_data.search(cr, uid, [('res_id','in',list(sub_ids)),('model','=',self._name)], context=context) # Step 2. Marching towards the real deletion of referenced records pool_model_data.unlink(cr, uid, referenced_ids, context=context) - + # For the same reason, removing the record relevant to ir_values - ir_value_ids = pool_ir_values.search(cr, uid, [('res_id','in',list(sub_ids)),('model','=',self._name)], context=context) + ir_value_ids = pool_ir_values.search(cr, uid, + [('value','in',['%s,%s' % (self._name, sid) for sid in sub_ids])], + context=context) if ir_value_ids: pool_ir_values.unlink(cr, uid, ir_value_ids, context=context) - + for order, object, store_ids, fields in result_store: if object != self._name: obj = self.pool.get(object) @@ -3251,7 +3254,7 @@ class orm(orm_template): rids = map(lambda x: x[0], cr.fetchall()) if rids: obj._store_set_values(cr, uid, rids, fields, context) - + return True #