Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
upgrade_analysis/odoo_patch/__init__.py
Executable file
3
upgrade_analysis/odoo_patch/__init__.py
Executable file
@@ -0,0 +1,3 @@
|
||||
from . import addons
|
||||
from . import odoo
|
||||
from . import odoo_patch
|
||||
2
upgrade_analysis/odoo_patch/addons/__init__.py
Executable file
2
upgrade_analysis/odoo_patch/addons/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import mrp
|
||||
from . import stock
|
||||
11
upgrade_analysis/odoo_patch/addons/mrp/__init__.py
Executable file
11
upgrade_analysis/odoo_patch/addons/mrp/__init__.py
Executable file
@@ -0,0 +1,11 @@
|
||||
# flake8: noqa: B902
|
||||
from odoo.addons import mrp
|
||||
from ...odoo_patch import OdooPatch
|
||||
|
||||
|
||||
class PreInitHookPatch(OdooPatch):
|
||||
target = mrp
|
||||
method_names = ["_pre_init_mrp"]
|
||||
|
||||
def _pre_init_mrp(cr):
|
||||
"""Don't try to create an existing column on reinstall"""
|
||||
11
upgrade_analysis/odoo_patch/addons/stock/__init__.py
Executable file
11
upgrade_analysis/odoo_patch/addons/stock/__init__.py
Executable file
@@ -0,0 +1,11 @@
|
||||
# flake8: noqa: B902
|
||||
from odoo.addons import stock
|
||||
from ...odoo_patch import OdooPatch
|
||||
|
||||
|
||||
class PreInitHookPatch(OdooPatch):
|
||||
target = stock
|
||||
method_names = ["pre_init_hook"]
|
||||
|
||||
def pre_init_hook(cr):
|
||||
"""Don't unlink stock data on reinstall"""
|
||||
4
upgrade_analysis/odoo_patch/odoo/__init__.py
Executable file
4
upgrade_analysis/odoo_patch/odoo/__init__.py
Executable file
@@ -0,0 +1,4 @@
|
||||
from . import addons
|
||||
from . import models
|
||||
from . import modules
|
||||
from . import tools
|
||||
1
upgrade_analysis/odoo_patch/odoo/addons/__init__.py
Executable file
1
upgrade_analysis/odoo_patch/odoo/addons/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import base
|
||||
1
upgrade_analysis/odoo_patch/odoo/addons/base/__init__.py
Executable file
1
upgrade_analysis/odoo_patch/odoo/addons/base/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
1
upgrade_analysis/odoo_patch/odoo/addons/base/models/__init__.py
Executable file
1
upgrade_analysis/odoo_patch/odoo/addons/base/models/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import ir_model
|
||||
43
upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py
Executable file
43
upgrade_analysis/odoo_patch/odoo/addons/base/models/ir_model.py
Executable file
@@ -0,0 +1,43 @@
|
||||
from odoo import models
|
||||
|
||||
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(self.env.registry[model._name].mro())
|
||||
if models.is_definition_class(cls)
|
||||
for constraint in getattr(cls, "_local_sql_constraints", ())
|
||||
}
|
||||
|
||||
data_list = []
|
||||
for key, definition, message in model._sql_constraints:
|
||||
conname = f"{model._table}_{key}"
|
||||
module = constraint_module.get(key)
|
||||
record = self._reflect_constraint(
|
||||
model, conname, "u", cons_text(definition), module, message
|
||||
)
|
||||
xml_id = f"{module}.constraint_{conname}"
|
||||
if record:
|
||||
data_list.append(dict(xml_id=xml_id, record=record))
|
||||
else:
|
||||
self.env["ir.model.data"]._load_xmlid(xml_id)
|
||||
# Begin OpenUpgrade addition
|
||||
upgrade_log.log_xml_id(self.env.cr, module, xml_id)
|
||||
# End OpenUpgrade addition
|
||||
if data_list:
|
||||
self.env["ir.model.data"]._update_xmlids(data_list)
|
||||
23
upgrade_analysis/odoo_patch/odoo/models.py
Executable file
23
upgrade_analysis/odoo_patch/odoo/models.py
Executable file
@@ -0,0 +1,23 @@
|
||||
from odoo import api, models
|
||||
|
||||
from ... import upgrade_log
|
||||
from ..odoo_patch import OdooPatch
|
||||
|
||||
|
||||
class BaseModelPatch(OdooPatch):
|
||||
target = models.BaseModel
|
||||
method_names = ["_convert_records"]
|
||||
|
||||
@api.model
|
||||
def _convert_records(self, records, log=lambda a: None):
|
||||
"""Log data ids that are imported with `load`"""
|
||||
current_module = self.env.context["module"]
|
||||
for res in BaseModelPatch._convert_records._original_method(
|
||||
self, records, log=log
|
||||
):
|
||||
_id, xid, _record, _info = res
|
||||
if xid:
|
||||
xid = xid if "." in xid else f"{current_module}.{xid}"
|
||||
upgrade_log.log_xml_id(self.env.cr, current_module, xid)
|
||||
|
||||
yield res
|
||||
1
upgrade_analysis/odoo_patch/odoo/modules/__init__.py
Executable file
1
upgrade_analysis/odoo_patch/odoo/modules/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import registry
|
||||
34
upgrade_analysis/odoo_patch/odoo/modules/registry.py
Executable file
34
upgrade_analysis/odoo_patch/odoo/modules/registry.py
Executable file
@@ -0,0 +1,34 @@
|
||||
import logging
|
||||
from threading import current_thread
|
||||
|
||||
from odoo import SUPERUSER_ID, api
|
||||
from odoo.modules.registry import Registry
|
||||
|
||||
from .... import upgrade_log
|
||||
from ...odoo_patch import OdooPatch
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RegistryPatch(OdooPatch):
|
||||
target = Registry
|
||||
method_names = ["init_models"]
|
||||
|
||||
def init_models(self, cr, model_names, context, install=True):
|
||||
if "module" in context:
|
||||
module_name = context["module"]
|
||||
_logger.debug("Logging models of module %s", module_name)
|
||||
upg_registry = current_thread()._upgrade_registry
|
||||
local_registry = {}
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
for model in env.values():
|
||||
if not model._auto:
|
||||
continue
|
||||
upgrade_log.log_model(model, local_registry)
|
||||
upgrade_log.compare_registries(
|
||||
cr, context["module"], upg_registry, local_registry
|
||||
)
|
||||
|
||||
return RegistryPatch.init_models._original_method(
|
||||
self, cr, model_names, context, install=install
|
||||
)
|
||||
1
upgrade_analysis/odoo_patch/odoo/tools/__init__.py
Executable file
1
upgrade_analysis/odoo_patch/odoo/tools/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import convert
|
||||
14
upgrade_analysis/odoo_patch/odoo/tools/convert.py
Executable file
14
upgrade_analysis/odoo_patch/odoo/tools/convert.py
Executable file
@@ -0,0 +1,14 @@
|
||||
from odoo.tools.convert import xml_import
|
||||
|
||||
from .... import upgrade_log
|
||||
from ...odoo_patch import OdooPatch
|
||||
|
||||
|
||||
class XMLImportPatch(OdooPatch):
|
||||
target = xml_import
|
||||
method_names = ["_test_xml_id"]
|
||||
|
||||
def _test_xml_id(self, xml_id):
|
||||
res = XMLImportPatch._test_xml_id._original_method(self, xml_id)
|
||||
upgrade_log.log_xml_id(self.env.cr, self.module, xml_id)
|
||||
return res
|
||||
61
upgrade_analysis/odoo_patch/odoo_patch.py
Executable file
61
upgrade_analysis/odoo_patch/odoo_patch.py
Executable file
@@ -0,0 +1,61 @@
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class OdooPatch:
|
||||
"""Simple mechanism to apply a collection of monkeypatches using a
|
||||
context manager.
|
||||
|
||||
Classes can register their monkeypatches by inheriting from this class.
|
||||
They need to define a `target` member, referring to the object or module
|
||||
that needs to be patched, and a list `method_names`. They also need to
|
||||
redefine those methods under the same name.
|
||||
|
||||
The original method is made available on the new method as
|
||||
`_original_method`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
from odoo import api
|
||||
from odoo.addons.some_module.models.my_model import MyModel
|
||||
|
||||
class MyModelPatch(OdooPatch):
|
||||
target = MyModel
|
||||
method_names = ['do_something']
|
||||
|
||||
@api.model
|
||||
def do_something(self):
|
||||
res = MyModelPatch.do_something._original_method()
|
||||
...
|
||||
return res
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```
|
||||
with OdooPatch():
|
||||
do_something()
|
||||
```
|
||||
"""
|
||||
|
||||
def __enter__(self):
|
||||
for cls in OdooPatch.__subclasses__():
|
||||
for method_name in cls.method_names:
|
||||
method = getattr(cls, method_name)
|
||||
method._original_method = getattr(cls.target, method_name)
|
||||
setattr(cls.target, method_name, method)
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
for cls in OdooPatch.__subclasses__():
|
||||
for method_name in cls.method_names:
|
||||
method = getattr(cls.target, method_name)
|
||||
if hasattr(method, "_original_method"):
|
||||
setattr(cls.target, method_name, method._original_method)
|
||||
else:
|
||||
_logger.warning(
|
||||
"_original_method not found on method %s of class %s",
|
||||
method_name,
|
||||
cls.target,
|
||||
)
|
||||
Reference in New Issue
Block a user