Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] dms: Improve the unlink method in base to avoid errors #289

Merged
merged 1 commit into from
Feb 24, 2024
Merged
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
19 changes: 12 additions & 7 deletions dms/models/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 Tecnativa - Jairo Llopis
# Copyright 2024 Tecnativa - Víctor Martínez
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import models
Expand All @@ -8,12 +9,16 @@ class Base(models.AbstractModel):
_inherit = "base"

def unlink(self):
"""Cascade DMS related resources removal."""
"""Cascade DMS related resources removal.
Avoid executing in ir.* models (ir.mode, ir.model.fields, etc), in transient
models and in the models we want to check."""
result = super().unlink()
self.env["dms.file"].sudo().search(
[("res_model", "=", self._name), ("res_id", "in", self.ids)]
).unlink()
self.env["dms.directory"].sudo().search(
[("res_model", "=", self._name), ("res_id", "in", self.ids)]
).unlink()
if (
not self._name.startswith("ir.")
and not self.is_transient()
and self._name not in ("dms.file", "dms.directory")
):
domain = [("res_model", "=", self._name), ("res_id", "in", self.ids)]
self.env["dms.file"].sudo().search(domain).unlink()
self.env["dms.directory"].sudo().search(domain).unlink()
return result
Loading