[FIX] import: import new records without xml_ids
This is related to revision 80b373f
.
The above revision leads to the inability
to import new records without any `xml_id` set
Technically speaking, this is because
you cannot concatenate `False` with `'_'`, in
`xml_id + '_'`
opw-668962
This commit is contained in:
parent
3ff4dae5b0
commit
ff915dd96e
|
@ -1044,22 +1044,23 @@ class ir_model_data(osv.osv):
|
||||||
else:
|
else:
|
||||||
if mode=='init' or (mode=='update' and xml_id):
|
if mode=='init' or (mode=='update' and xml_id):
|
||||||
inherit_xml_ids = []
|
inherit_xml_ids = []
|
||||||
for table, field_name in model_obj._inherits.items():
|
if xml_id:
|
||||||
xml_ids = self.pool['ir.model.data'].search(cr, uid, [
|
for table, field_name in model_obj._inherits.items():
|
||||||
('module', '=', module),
|
xml_ids = self.pool['ir.model.data'].search(cr, uid, [
|
||||||
('name', '=', xml_id + '_' + table.replace('.', '_')),
|
('module', '=', module),
|
||||||
], context=context)
|
('name', '=', xml_id + '_' + table.replace('.', '_')),
|
||||||
# XML ID found in the database, try to recover an existing record
|
], context=context)
|
||||||
if xml_ids:
|
# XML ID found in the database, try to recover an existing record
|
||||||
found_xml_id = self.pool['ir.model.data'].browse(cr, uid, xml_ids[0], context=context)
|
if xml_ids:
|
||||||
record = self.pool[found_xml_id.model].browse(cr, uid, [found_xml_id.res_id], context=context)[0]
|
found_xml_id = self.pool['ir.model.data'].browse(cr, uid, xml_ids[0], context=context)
|
||||||
# The record exists, store the id and don't recreate the XML ID
|
record = self.pool[found_xml_id.model].browse(cr, uid, [found_xml_id.res_id], context=context)[0]
|
||||||
if record.exists():
|
# The record exists, store the id and don't recreate the XML ID
|
||||||
inherit_xml_ids.append(found_xml_id.model)
|
if record.exists():
|
||||||
values[field_name] = found_xml_id.res_id
|
inherit_xml_ids.append(found_xml_id.model)
|
||||||
# Orphan XML ID, delete it
|
values[field_name] = found_xml_id.res_id
|
||||||
else:
|
# Orphan XML ID, delete it
|
||||||
found_xml_id.unlink()
|
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:
|
||||||
|
|
Loading…
Reference in New Issue