diff --git a/upgrade_analysis/compare.py b/upgrade_analysis/compare.py index 864277310..0a6f9ebb9 100644 --- a/upgrade_analysis/compare.py +++ b/upgrade_analysis/compare.py @@ -387,14 +387,22 @@ def compare_xml_sets(old_records, new_records): and found["domain"] is False ) column["domain"] = False + found["definition"] = ( + column["definition"] + and column["definition"] != found["definition"] + and "is now '{}' ('{}')".format( + found["definition"], column["definition"] + ) + ) + column["definition"] = False column["noupdate_switched"] = False found["noupdate_switched"] = column["noupdate"] != found["noupdate"] if match_type != "direct": matched_records.append(column) matched_records.append(found) - elif (match_type == "direct" and found["domain"]) or found[ - "noupdate_switched" - ]: + elif ( + match_type == "direct" and (found["domain"] or found["definition"]) + ) or found["noupdate_switched"]: matched_records.append(found) return matched_records @@ -413,10 +421,12 @@ def compare_xml_sets(old_records, new_records): for record in old_records: record["old"] = True record["domain"] = False + record["definition"] = False record["noupdate_switched"] = False for record in new_records: record["new"] = True record["domain"] = False + record["definition"] = False record["noupdate_switched"] = False sorted_records = sorted( @@ -441,6 +451,8 @@ def compare_xml_sets(old_records, new_records): content = "%(model)s: %(name)s" % entry if entry["domain"]: content += " (deleted domain)" + if entry["definition"]: + content += " (changed definition: %(definition)s)" % entry if entry["noupdate"]: content += " (noupdate)" if entry["noupdate_switched"]: diff --git a/upgrade_analysis/models/upgrade_analysis.py b/upgrade_analysis/models/upgrade_analysis.py index dc52d4761..8d0e53aa5 100644 --- a/upgrade_analysis/models/upgrade_analysis.py +++ b/upgrade_analysis/models/upgrade_analysis.py @@ -144,6 +144,7 @@ class UpgradeAnalysis(models.Model): "prefix", "suffix", "domain", + "definition", ] local_xml_records = [ {field: record[field] for field in flds} diff --git a/upgrade_analysis/models/upgrade_record.py b/upgrade_analysis/models/upgrade_record.py index 2f0db3827..b8886fc61 100644 --- a/upgrade_analysis/models/upgrade_record.py +++ b/upgrade_analysis/models/upgrade_record.py @@ -49,6 +49,8 @@ class UpgradeRecord(models.Model): domain = fields.Char(readonly=True) + definition = fields.Char(readonly=True) + prefix = fields.Char(compute="_compute_prefix_and_suffix") suffix = fields.Char(compute="_compute_prefix_and_suffix") diff --git a/upgrade_analysis/odoo_patch/odoo/__init__.py b/upgrade_analysis/odoo_patch/odoo/__init__.py index 4541924d9..42c35ff23 100644 --- a/upgrade_analysis/odoo_patch/odoo/__init__.py +++ b/upgrade_analysis/odoo_patch/odoo/__init__.py @@ -1,3 +1,4 @@ +from . import addons from . import models from . import modules from . import tools diff --git a/upgrade_analysis/odoo_patch/odoo/addons/__init__.py b/upgrade_analysis/odoo_patch/odoo/addons/__init__.py new file mode 100644 index 000000000..0e4444933 --- /dev/null +++ b/upgrade_analysis/odoo_patch/odoo/addons/__init__.py @@ -0,0 +1 @@ +from . import base diff --git a/upgrade_analysis/odoo_patch/odoo/addons/base/__init__.py b/upgrade_analysis/odoo_patch/odoo/addons/base/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/upgrade_analysis/odoo_patch/odoo/addons/base/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/upgrade_analysis/odoo_patch/odoo/addons/base/models/__init__.py b/upgrade_analysis/odoo_patch/odoo/addons/base/models/__init__.py new file mode 100644 index 000000000..413bb2380 --- /dev/null +++ b/upgrade_analysis/odoo_patch/odoo/addons/base/models/__init__.py @@ -0,0 +1 @@ +from . import ir_model diff --git a/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py b/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py new file mode 100644 index 000000000..68cab246a --- /dev/null +++ b/upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py @@ -0,0 +1,40 @@ +from odoo.addons.base.models import ir_model + +from ...... import upgrade_log +from .....odoo_patch import OdooPatch + + +class IrModelConstraintPatch(OdooPatch): + target = ir_model.IrModelConstraint + method_names = ["_reflect_model"] + + def _reflect_model(self, model): + """Reflect the _sql_constraints of the given model.""" + + def cons_text(txt): + return txt.lower().replace(", ", ",").replace(" (", "(") + + # map each constraint on the name of the module where it is defined + constraint_module = { + constraint[0]: cls._module + for cls in reversed(type(model).mro()) + if not getattr(cls, "pool", None) + for constraint in getattr(cls, "_local_sql_constraints", ()) + } + + data_list = [] + for (key, definition, message) in model._sql_constraints: + conname = "%s_%s" % (model._table, key) + module = constraint_module.get(key) + record = self._reflect_constraint( + model, conname, "u", cons_text(definition), module, message + ) + if record: + xml_id = "%s.constraint_%s" % (module, conname) + data_list.append(dict(xml_id=xml_id, record=record)) + + self.env["ir.model.data"]._update_xmlids(data_list) + for data in data_list: + xml_id = data.get("xml_id") + module = xml_id.split(".")[0] + upgrade_log.log_xml_id(self.env.cr, module, xml_id) diff --git a/upgrade_analysis/upgrade_log.py b/upgrade_analysis/upgrade_log.py index 3a8d13127..bfab4e55b 100644 --- a/upgrade_analysis/upgrade_log.py +++ b/upgrade_analysis/upgrade_log.py @@ -165,7 +165,10 @@ def log_model(model, local_registry): def log_xml_id(cr, module, xml_id): """ Log xml_ids at load time in the records table. - Called from tools/convert.py:xml_import._test_xml_id() + Called from: + - tools/convert.py:xml_import._test_xml_id() + - odoo/models.py:BaseModel._convert_records() + - odoo/addons/base/models/ir_model.py:IrModelConstraint._reflect_model() # Catcha's - The module needs to be loaded with 'init', or the calling method diff --git a/upgrade_analysis/wizards/upgrade_generate_record_wizard.py b/upgrade_analysis/wizards/upgrade_generate_record_wizard.py index 3a766b1b1..0fd0464d6 100644 --- a/upgrade_analysis/wizards/upgrade_generate_record_wizard.py +++ b/upgrade_analysis/wizards/upgrade_generate_record_wizard.py @@ -72,6 +72,24 @@ class GenerateWizard(models.TransientModel): ] ) + # Set constraint definition + self.env.cr.execute( + """ UPDATE upgrade_record our + SET definition = btrim(replace(replace(replace(replace( + imc.definition, chr(9), ' '), chr(10), ' '), ' ', ' '), ' ', ' ')) + FROM ir_model_data imd + JOIN ir_model_constraint imc ON imd.res_id = imc.id + WHERE our.type = 'xmlid' + AND imd.model = 'ir.model.constraint' + AND our.model = imd.model + AND our.name = imd.module || '.' || imd.name""" + ) + self.env.cache.invalidate( + [ + (self.env["upgrade.record"]._fields["definition"], None), + ] + ) + # Set noupdate property from ir_model_data self.env.cr.execute( """ UPDATE upgrade_record our