[FIX] base: allow to duplicate an External ID
Before this commit, the ir_model_data_module_name_uniq_index constraints avoid to duplicate an XML ID. Now on copy, we add a random suffix to allow the end user to update just the record id (and rename the name). closes odoo/odoo#92108 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import itertools
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
import psycopg2
|
||||
from ast import literal_eval
|
||||
@@ -1959,6 +1960,13 @@ class IrModelData(models.Model):
|
||||
raise AccessError(_('Not enough access rights on the external ID:') + ' %s.%s' % (module, xml_id))
|
||||
return model, False
|
||||
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
self.ensure_one()
|
||||
rand = "%04x" % random.getrandbits(16)
|
||||
default = dict(default or {}, name="%s_%s" % (self.name, rand))
|
||||
return super().copy(default)
|
||||
|
||||
def unlink(self):
|
||||
""" Regular unlink method, but make sure to clear the caches. """
|
||||
self.clear_caches()
|
||||
|
||||
Reference in New Issue
Block a user