From 80b373f1e5b6eb1f9b9d1a476bf0801989029c43 Mon Sep 17 00:00:00 2001 From: Sylvain GARANCHER Date: Thu, 8 Oct 2015 16:34:16 +0200 Subject: [PATCH] [FIX] ir_model: Fixed XML data recreation when inherited part are not deleted Description: When updating the product module, if the "Service" product.product has been deleted, but not the corresponding "product.template" part, the update will crash on a "duplicate xml id" error. This commit fixes the bug by : - Adding the link to existing inherited model xml id in values - Avoid creating the duplicated XML ID If the XML ID is found, but orphan, it's simply deleted. Closes #8966 opw-658454 --- openerp/addons/base/ir/ir_model.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index 3a9f030b895..5c1847aa567 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -1043,10 +1043,31 @@ class ir_model_data(osv.osv): },context=context) else: if mode=='init' or (mode=='update' and xml_id): + inherit_xml_ids = [] + for table, field_name in model_obj._inherits.items(): + xml_ids = self.pool['ir.model.data'].search(cr, uid, [ + ('module', '=', module), + ('name', '=', xml_id + '_' + table.replace('.', '_')), + ], context=context) + # XML ID found in the database, try to recover an existing record + if xml_ids: + found_xml_id = self.pool['ir.model.data'].browse(cr, uid, xml_ids[0], context=context) + record = self.pool[found_xml_id.model].browse(cr, uid, [found_xml_id.res_id], context=context)[0] + # The record exists, store the id and don't recreate the XML ID + if record.exists(): + inherit_xml_ids.append(found_xml_id.model) + values[field_name] = found_xml_id.res_id + # Orphan XML ID, delete it + else: + found_xml_id.unlink() + res_id = model_obj.create(cr, uid, values, context=context) if xml_id: if model_obj._inherits: for table in model_obj._inherits: + if table in inherit_xml_ids: + continue + inherit_id = model_obj.browse(cr, uid, res_id,context=context)[model_obj._inherits[table]] self.create(cr, SUPERUSER_ID, {