[FIX] base: fetch mimetype on ir.attachment for binary fields

This commit is contained in:
Damien Bouvy
2016-04-25 17:20:57 +02:00
parent e680f29560
commit e248882053
+4
View File
@@ -300,6 +300,10 @@ class ir_http(osv.AbstractModel):
mimetype = obj.mimetype
elif filename:
mimetype = mimetypes.guess_type(filename)[0]
elif getattr(env[model]._fields[field], 'attachment', False):
# for binary fields, fetch the ir_attachement for mimetype check
attach_mimetype = env['ir.attachment'].search_read(domain=[('res_model', '=', model), ('res_id', '=', id), ('res_field', '=', field)], fields=['mimetype'], limit=1)
mimetype = attach_mimetype and attach_mimetype[0]['mimetype']
if not mimetype:
mimetype = default_mimetype
headers.append(('Content-Type', mimetype))