From 2459cd5dd14282b485f9e6e39df857c3b8cfa636 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 10 Sep 2014 12:18:14 +0200 Subject: [PATCH] [FIX] ir_attachment: attachements removed on record unlink --- openerp/osv/orm.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index cd625bc2009..9bf10df39d6 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -4050,6 +4050,7 @@ class BaseModel(object): self.check_access_rights(cr, uid, 'unlink') ir_property = self.pool.get('ir.property') + ir_attachment_obj = self.pool.get('ir.attachment') # Check if the records are used as default properties. domain = [('res_id', '=', False), @@ -4088,6 +4089,13 @@ class BaseModel(object): if ir_value_ids: ir_values_obj.unlink(cr, uid, ir_value_ids, context=context) + # For the same reason, removing the record relevant to ir_attachment + # The search is performed with sql as the search method of ir_attachment is overridden to hide attachments of deleted records + cr.execute('select id from ir_attachment where res_model = %s and res_id in %s', (self._name, sub_ids)) + ir_attachment_ids = [ir_attachment[0] for ir_attachment in cr.fetchall()] + if ir_attachment_ids: + ir_attachment_obj.unlink(cr, uid, ir_attachment_ids, context=context) + for order, object, store_ids, fields in result_store: if object == self._name: effective_store_ids = list(set(store_ids) - set(ids))