[attachment]

- implement a field function res_name that call the name_get for res_model, res_id
- remove preview field

bzr revid: hmo@tinyerp.com-20100527124311-snyrw2ja53xa8o5u
This commit is contained in:
KSA (OpenERP) 2010-05-27 18:13:11 +05:30 committed by Harry (Open ERP)
parent d573e7fe72
commit 8eb28e74b9
2 changed files with 27 additions and 36 deletions

View File

@ -674,16 +674,8 @@
<separator string="Attached To" colspan="2"/>
<field name="res_model" select="2"/>
<field name="res_id"/>
<field name="res_name"/>
</group>
<separator string="Preview" colspan="4"/>
<field
name="preview"
widget="picture"
readonly="1"
nolabel="1"
colspan="4"
img_height="400"
img_width="800"/>
</page>
<page string="Notes">
<field colspan="4" name="description" nolabel="1"/>

View File

@ -86,35 +86,34 @@ class ir_attachment(osv.osv):
res_id = dataobj.browse(cr, uid, data_id, context).res_id
return self.pool.get('ir.actions.act_window').read(cr, uid, res_id, [], context)
def _get_preview(self, cr, uid, ids, name, arg, context=None):
result = {}
if context is None:
context = {}
ctx = context.copy()
ctx['bin_size'] = False
for i in self.browse(cr, uid, ids, context=ctx):
result[i.id] = False
for format in ('png','jpg','jpeg','gif','bmp'):
if (i.datas_fname and i.datas_fname.lower() or '').endswith(format):
result[i.id]= i.datas
break
return result
def _name_get_resname(self, cr, uid, ids, object,method, context):
data = {}
for attachment in self.browse(cr, uid, ids, context=context):
model_object = attachment.res_model
res_id = attachment.res_id
if model_object and res_id:
model_pool = self.pool.get(model_object)
res = model_pool.name_get(cr,uid,[res_id],context)
data[attachment.id] = res[0][1]
else:
data[attachment.id] = False
return data
_name = 'ir.attachment'
_columns = {
'name': fields.char('Attachment Name',size=64, required=True),
'datas': fields.binary('Data'),
'preview': fields.function(_get_preview, type='binary', string='Image Preview', method=True),
'datas_fname': fields.char('Filename',size=64),
'description': fields.text('Description'),
# Not required due to the document module !
'res_name': fields.function(_name_get_resname, type='char', string='Resource Name', method=True),
'res_model': fields.char('Resource Object',size=64, readonly=True),
'res_id': fields.integer('Resource ID', readonly=True),
'link': fields.char('Link', size=256),
'create_date': fields.datetime('Date Created', readonly=True),
'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
}
ir_attachment()