[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) <nim@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user