From dbd87ec4648a18ebf3eb79e11214cf0ee5d1f5d2 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Wed, 13 May 2020 06:32:00 +0000 Subject: [PATCH] [FIX] base: fix import of studio customizations - Activate Studio from dashboard of database A - Export studio customizations - Activate Studio from dashboard of database B - Import studio customizations previously exported The imported data don't have the boolean studio field set to True. Since v12, when loading a module, a query is executed to create or update XML ids. The create and write methods are not called anymore. Therefore the overridden create and write methods of "ir.model.data" defined in Studio module are not called and thus cannot set the studio field to True. The generation of the query creating XML ids has been moved to a private method allowing another module like Studio to override it. opw-2245578 closes odoo/odoo#51203 X-original-commit: 198ab837e466f3155ea1c3b35811b981b1c1e537 Related: odoo/enterprise#10586 Signed-off-by: Nicolas Martinelli (nim) --- odoo/addons/base/models/ir_model.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 76f0d9b7c55..76b25c1dde0 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -1958,8 +1958,6 @@ class IrModelData(models.Model): if not data_list: return - # rows to insert - rowf = "(%s, %s, %s, %s, %s, now() at time zone 'UTC', now() at time zone 'UTC')" rows = tools.OrderedSet() for data in data_list: prefix, suffix = data['xml_id'].split('.', 1) @@ -1977,15 +1975,7 @@ class IrModelData(models.Model): for sub_rows in self.env.cr.split_for_in_conditions(rows): # insert rows or update them - query = """ - INSERT INTO ir_model_data (module, name, model, res_id, noupdate, date_init, date_update) - VALUES {rows} - ON CONFLICT (module, name) - DO UPDATE SET date_update=(now() at time zone 'UTC') {where} - """.format( - rows=", ".join([rowf] * len(sub_rows)), - where="WHERE NOT ir_model_data.noupdate" if update else "", - ) + query = self._build_update_xmlids_query(sub_rows, update) try: self.env.cr.execute(query, [arg for row in sub_rows for arg in row]) except Exception: @@ -1995,6 +1985,20 @@ class IrModelData(models.Model): # update loaded_xmlids self.pool.loaded_xmlids.update("%s.%s" % row[:2] for row in rows) + # NOTE: this method is overriden in web_studio; if you need to make another + # override, make sure it is compatible with the one that is there. + def _build_update_xmlids_query(self, sub_rows, update): + rowf = "(%s, %s, %s, %s, %s, now() at time zone 'UTC', now() at time zone 'UTC')" + return """ + INSERT INTO ir_model_data (module, name, model, res_id, noupdate, date_init, date_update) + VALUES {rows} + ON CONFLICT (module, name) + DO UPDATE SET date_update=(now() at time zone 'UTC') {where} + """.format( + rows=", ".join([rowf] * len(sub_rows)), + where="WHERE NOT ir_model_data.noupdate" if update else "", + ) + @api.model def _load_xmlid(self, xml_id): """ Simply mark the given XML id as being loaded, and return the