[FIX] base: do not search for attachment for related fields in _binary_record_content
Use case: website_event_track(_online) ====================================== On sponsor model, image_128 field is defined in website_event_track module as computed stored Image field. It means that when this binary field is set, an attachment is created in ir.attachment model -> attachment is set to True. In website_event_track_online module this field is modified. It is set as a related (resized) version of image_512 and not stored anymore. However attachments still exist in ir.attachment table for sponsor records. This is not an issue when trying to access the image_128 field using the ORM as the compute (or related) is correctly called. However '/web/image' does checks if the field has an attachment and loads it. In our case old attachments still in database are therefore displayed instead of the new related image. Fix === When checking for an existing attachment in _binary_record_content we also check that the field is not a related. This fixes the current issue. It also makes _binary_record_content work as the ORM, aka using the computed value and not any stored information. DB Cleaning =========== In 14.0 a script will be added to clean existing attachments for sponsor model. Indeed there is no need to keep unused attachments. Especially in 14 website_event_track_online has been merged in website_event_track, meaning only existing db have to be cleaned. New DBs will never have this attachment issue as the field is always computed. Task ID: 2341108 closes odoo/odoo#60259 X-original-commit: ada1eab338c6cffb526b03377ec01962f9c26c4c Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
2a7f5e25f1
commit
f05f8ef647
@@ -377,7 +377,7 @@ class IrHttp(models.AbstractModel):
|
||||
filehash = 'checksum' in record and record['checksum'] or False
|
||||
|
||||
field_def = record._fields[field]
|
||||
if field_def.type == 'binary' and field_def.attachment:
|
||||
if field_def.type == 'binary' and field_def.attachment and not field_def.related:
|
||||
if model != 'ir.attachment':
|
||||
field_attachment = self.env['ir.attachment'].sudo().search_read(domain=[('res_model', '=', model), ('res_id', '=', record.id), ('res_field', '=', field)], fields=['datas', 'mimetype', 'checksum'], limit=1)
|
||||
if field_attachment:
|
||||
|
||||
Reference in New Issue
Block a user