Skip to content

Commit

Permalink
Merge PR #289 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Feb 24, 2024
2 parents b999f29 + da34432 commit 5b6482c
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 5b6482c

Please sign in to comment.