mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 14:52:01 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
from . import models
|
||||
|
|
@ -0,0 +1 @@
|
|||
from . import ir_model
|
||||
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue