forked from grap/openupgrade-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
33 lines (27 loc) · 1.11 KB
/
models.py
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
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from uuid import uuid4
from odoo.models import BaseModel
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
_logger = logging.getLogger(__name__)
def unlink(self):
""" Don't break on unlink of obsolete records
when called from ir.model::_process_end()
This only adapts the base unlink method. If overrides of this method
on individual models give problems, add patches for those as well.
"""
if not self.env.context.get(MODULE_UNINSTALL_FLAG):
return BaseModel.unlink._original_method(self)
savepoint = str(uuid4)
try:
self.env.cr.execute('SAVEPOINT "%s"' % savepoint)
return BaseModel.unlink._original_method(self)
except Exception as e:
self.env.cr.execute('ROLLBACK TO SAVEPOINT "%s"' % savepoint)
_logger.warning(
"Could not delete obsolete record with ids %s of model %s: %s",
self.ids, self._name, e)
return False
unlink._original_method = BaseModel.unlink
BaseModel.unlink = unlink