Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_xmlid should check that xmlid does not exist on another model #33

Open
guewen opened this issue Dec 22, 2017 · 0 comments
Open

add_xmlid should check that xmlid does not exist on another model #33

guewen opened this issue Dec 22, 2017 · 0 comments

Comments

@guewen
Copy link
Contributor

guewen commented Dec 22, 2017

The add_xmlid method currently skips the creation of the xmlid if it already exists on a different record. It should fail instead.

def add_xmlid(ctx, record, xmlid, noupdate=False):
""" Add a XMLID on an existing record """
try:
ref_id, __, __ = ctx.env['ir.model.data'].xmlid_lookup(xmlid)
except ValueError:
pass # does not exist, we'll create a new one
else:
return ctx.env['ir.model.data'].browse(ref_id)
if '.' in xmlid:
module, name = xmlid.split('.')
else:
module = ''
name = xmlid
return ctx.env['ir.model.data'].create({
'name': name,
'module': module,
'model': record._name,
'res_id': record.id,
'noupdate': noupdate,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant