Skip to content

Commit

Permalink
Merge PR #2649 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Apr 13, 2021
2 parents 60d2ac1 + f3c668c commit 645c5b8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion openupgrade_framework/odoo_patch/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import addons, models, modules
from . import addons, api, models, modules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from odoo import api, models
from odoo.tools import mute_logger

from odoo.addons.base.models.ir_model import IrModel, IrModelData, IrModelRelation
from odoo.addons.base.models.ir_model import (
IrModel,
IrModelData,
IrModelFields,
IrModelRelation,
)


def _drop_table(self):
Expand All @@ -22,6 +27,9 @@ def _drop_table(self):
)


IrModel._drop_table = _drop_table


def _drop_column(self):
""" Never drop columns """
for field in self:
Expand All @@ -39,14 +47,26 @@ def _drop_column(self):
continue


IrModel._drop_column = _drop_column
IrModel._drop_table = _drop_table
IrModelFields._drop_column = _drop_column


@api.model
def _module_data_uninstall(self, modules_to_remove):
"""To pass context, that the patch in __getitem__ of api.Environment uses"""
patched_self = self.with_context(**{"missing_model": True})
return IrModelData._module_data_uninstall._original_method(
patched_self, modules_to_remove
)


_module_data_uninstall._original_method = IrModelData._module_data_uninstall
IrModelData._module_data_uninstall = _module_data_uninstall


@api.model
def _process_end(self, modules):
"""Don't warn about upgrade conventions from Odoo
('fields should be explicitely removed by an upgrade script')
('fields should be explicitly removed by an upgrade script')
"""
with mute_logger("odoo.addons.base.models.ir_model"):
return IrModelData._process_end._original_method(self, modules)
Expand Down
43 changes: 43 additions & 0 deletions openupgrade_framework/odoo_patch/odoo/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from odoo.api import Environment

_logger = logging.getLogger(__name__)


class FakeRecord:
"""Artificial construct to handle delete(records) submethod """

def __new__(cls):
return object.__new__(cls)

def __init__(self):
self._name = "ir.model.data"
self.ids = []
self.browse = lambda l: None

def __isub__(self, other):
return None


def __getitem__(self, model_name):
"""This is used to bypass the call self.env[model]
(and other posterior calls) from _module_data_uninstall method of ir.model.data
"""
if (
hasattr(self, "context")
and isinstance(model_name, str)
and self.context.get("missing_model", False)
):
if not self.registry.models.get(model_name, False):
new_env = lambda: None # noqa: E731
new_env._fields = {}
new_env.browse = lambda i: FakeRecord()
return new_env
return Environment.__getitem__._original_method(self, model_name)


__getitem__._original_method = Environment.__getitem__
Environment.__getitem__ = __getitem__
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# copy pasted from openupgrade project
# TODO: explain why odoorpc is pinned
odoorpc==0.7.0

# We allways want to have the latest version of openupgradelib
# more information : https://github.com/OCA/OpenUpgrade/pull/2194
git+https://github.com/OCA/openupgradelib.git@master

0 comments on commit 645c5b8

Please sign in to comment.