From da34432ef4c779aee0972502d158e1822eb6be94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 25 Jan 2024 13:44:43 +0100 Subject: [PATCH] [FIX] dms: Improve the unlink method in base to avoid errors 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. --- dms/models/base.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dms/models/base.py b/dms/models/base.py index a62898b88..c2ba7e42e 100644 --- a/dms/models/base.py +++ b/dms/models/base.py @@ -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 @@ -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