Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade

from odoo import models
from odoo import api, models

from odoo.addons.base.models.ir_model import (
IrModel,
Expand All @@ -28,6 +28,23 @@ def _drop_table(self):
IrModel._drop_table = _drop_table


@api.ondelete(at_uninstall=False)
def _unlink_related_attachments(self):
"""Never delete attachments (incl. binary field data) of removed models"""
for model in self:
openupgrade.message(
self.env.cr,
"Unknown",
False,
False,
"Not deleting the attachments of model %s",
model.model,
)


IrModel._unlink_related_attachments = _unlink_related_attachments


def _drop_column(self):
"""Never drop columns"""
for field in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ def update_list(self):
"""
result = IrModuleModule.update_list._original_method(self)
new_auto_install_modules = self.browse([])
company_countries = self.env["res.company"].sudo().search([]).country_id
for module in self.env["ir.module.module"].search(
[
("auto_install", "=", True),
("state", "=", "uninstalled"),
("name", "not like", ("l10n_%")),
]
):
# same rule as button_install
if module.country_ids and not module.country_ids & company_countries:
continue
if all(
state in ("to upgrade", "to install", "installed")
for state in module.dependencies_id.mapped("state")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@ def _check_xml(self):
"""Don't raise or log exceptions in view validation unless explicitly
requested. Mute warnings about views which are common during migration."""
with mute_logger("odoo.addons.base.models.ir_ui_view"):
try:
return IrUiView._check_xml._original_method(self)
except ValidationError as e:
_logger.warning(
"Can't render custom view %s for model %s. "
"Assuming you are migrating between major versions of Odoo. "
"Please review the view contents manually after the migration.\n"
"Error: %s",
self.xml_id,
self.model,
e,
)
for view in self:
try:
IrUiView._check_xml._original_method(view)
# with _raise_view_error not raising, validation can fail later on
except (
ValidationError,
ValueError,
AttributeError,
KeyError,
NameError,
) as e:
_logger.warning(
"Can't render custom view %s for model %s. "
"Assuming you are migrating between major versions of Odoo. "
"Please review the view contents manually after the migration.\n"
"Error: %s",
view.xml_id,
view.model,
e,
)


def _raise_view_error(
Expand Down
11 changes: 2 additions & 9 deletions openupgrade_framework/odoo_patch/odoo/orm/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 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

Expand All @@ -19,16 +18,10 @@ def unlink(self):
"""
if not self.env.context.get(MODULE_UNINSTALL_FLAG):
return BaseModel.unlink._original_method(self)
savepoint = str(uuid4)
try:
self.env.cr.execute( # pylint: disable=sql-injection
f'SAVEPOINT "{savepoint}"'
)
return BaseModel.unlink._original_method(self)
with self.env.cr.savepoint():
return BaseModel.unlink._original_method(self)
except Exception as e:
self.env.cr.execute( # pylint: disable=sql-injection
f'ROLLBACK TO SAVEPOINT "{savepoint}"'
)
_logger.warning(
"Could not delete obsolete record with ids %s of model %s",
self.ids,
Expand Down