-
-
Notifications
You must be signed in to change notification settings - Fork 810
Expand file tree
/
Copy pathapi.py
More file actions
43 lines (32 loc) · 1.2 KB
/
api.py
File metadata and controls
43 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 x: 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__