[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
This commit is contained in:
parent
63414bef54
commit
80b373f1e5
|
@ -1043,10 +1043,31 @@ class ir_model_data(osv.osv):
|
||||||
},context=context)
|
},context=context)
|
||||||
else:
|
else:
|
||||||
if mode=='init' or (mode=='update' and xml_id):
|
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)
|
res_id = model_obj.create(cr, uid, values, context=context)
|
||||||
if xml_id:
|
if xml_id:
|
||||||
if model_obj._inherits:
|
if model_obj._inherits:
|
||||||
for table in model_obj._inherits:
|
for table in model_obj._inherits:
|
||||||
|
if table in inherit_xml_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
inherit_id = model_obj.browse(cr, uid,
|
inherit_id = model_obj.browse(cr, uid,
|
||||||
res_id,context=context)[model_obj._inherits[table]]
|
res_id,context=context)[model_obj._inherits[table]]
|
||||||
self.create(cr, SUPERUSER_ID, {
|
self.create(cr, SUPERUSER_ID, {
|
||||||
|
|
Loading…
Reference in New Issue