From 79d7d78b75f27ee74ac81583313edf6f8e7accc1 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Mon, 23 May 2022 11:45:05 +0000 Subject: [PATCH] [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) --- odoo/addons/base/models/ir_model.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 7fac3817b0a..f39f2481944 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -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()