Skip to content

Commit

Permalink
[FIX] dms: Improve the unlink method in base to avoid errors
Browse files Browse the repository at this point in the history
In the uninstall process of dms, checks were made that prevented the
removal of fields and models being deleted, also causing the dms_file
and dms_directory tables to continue to exist.
  • Loading branch information
victoralmau committed Jan 29, 2024
1 parent df31f7d commit da34432
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 da34432

Please sign in to comment.