Files
enterprise-addons/documents/models/documents_unlink_mixin.py
T

25 lines
819 B
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class DocumentsUnlinkMixin(models.AbstractModel):
"""Send the related documents to trash when the record is deleted."""
_name = 'documents.unlink.mixin'
_description = "Documents unlink mixin"
def unlink(self):
"""Prevent deletion of the attachments / documents and send them to the trash instead."""
documents = self.env['documents.document'].search([
('res_model', '=', self._name),
('res_id', 'in', self.ids),
('active', '=', True),
])
if documents:
documents.write({
'res_model': False,
'res_id': False,
'active': False,
})
return super().unlink()