Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,3 @@
from . import addons
from . import odoo
from . import odoo_patch

View file

@ -0,0 +1,4 @@
from . import mrp
from . import point_of_sale
from . import sale_quotation_builder
from . import stock

View 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"""

View file

@ -0,0 +1,13 @@
# flake8: noqa: B902
from odoo import api
from odoo.addons.point_of_sale.models import pos_config
from ...odoo_patch import OdooPatch
class PreInitHookPatch(OdooPatch):
target = pos_config.PosConfig
method_names = ["post_install_pos_localisation"]
@api.model
def post_install_pos_localisation(cr):
"""Do not configure twice pos_localisation"""

View file

@ -0,0 +1,11 @@
# flake8: noqa: B902
from odoo.addons import sale_quotation_builder
from ...odoo_patch import OdooPatch
class PreInitHookPatch(OdooPatch):
target = sale_quotation_builder
method_names = ["_pre_init_sale_quotation_builder"]
def _pre_init_sale_quotation_builder(cr):
"""Don't pre-create existing columns on reinstall"""

View 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"""

View file

@ -0,0 +1,4 @@
from . import addons
from . import models
from . import modules
from . import tools

View file

@ -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)

View 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 "{}.{}".format(current_module, xid)
upgrade_log.log_xml_id(self.env.cr, current_module, xid)
yield res

View 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
)

View 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

View file

@ -0,0 +1,61 @@
import logging
_logger = logging.getLogger(__name__)
class OdooPatch(object):
"""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,
)