From d7f66c0ddd1dc3115ccf428872a34466a85c9fbe Mon Sep 17 00:00:00 2001 From: "Jay Vora (OpenERP)" Date: Tue, 22 Mar 2011 20:13:33 +0530 Subject: [PATCH] [FIX] Deletion : Deletion of the records which are referring to any xml/csv record,should delete the relevant reference of ir_model_data and ir_values (Ref : Case 4630) bzr revid: jvo@tinyerp.com-20110322144333-ic5hn3kexkoytgmo --- bin/addons/base/ir/ir_model.py | 2 ++ bin/osv/orm.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 5ce50370c77..033b010290d 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -608,6 +608,8 @@ class ir_model_data(osv.osv): """Returns (model, res_id) corresponding to a given module and xml_id (cached) or raise ValueError if not found""" data_id = self._get_id(cr, uid, module, xml_id) res = self.read(cr, uid, data_id, ['model', 'res_id']) + if not res['res_id']: + raise ValueError('No references to %s.%s' % (module, xml_id)) return (res['model'], res['res_id']) def get_object(self, cr, uid, module, xml_id, context=None): diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 952982742df..beb62f088ae 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -3227,9 +3227,23 @@ class orm(orm_template): self.check_access_rule(cr, uid, ids, 'unlink', context=context) + pool_model_data = self.pool.get('ir.model.data') + pool_ir_values = self.pool.get('ir.values') 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. + + # 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, self._model,referenced_ids) + + # 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)]) + if ir_value_ids: + pool_ir_values.unlink(cr, uid, ir_value_ids) + for order, object, store_ids, fields in result_store: if object != self._name: obj = self.pool.get(object) @@ -3237,6 +3251,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 #