class hystory_sent_inventory(osv.osv):
_name = "hystory.sent.inventory"
def _get_file(self, cr, uid, ids, field_name, field_value, arg, context=None):
full_filename = ""
data = ""
records = self.browse(cr, uid, ids)
result = {}
for r in records:
full_filename = str(os.path.join(r.path_to_file, r.filename))
if not os.path.exists(full_filename):
result[r.id] = base64.b64encode("file not exists!")
else:
data = open(full_filename, 'r').read()
result[r.id] = base64.b64encode(data)
return result
_columns = {
'create_date': fields.datetime('Sent date', readonly=True, ),
'type_api_id': fields.many2one('sale.integration', 'Type API', readonly=True, ),
'create_uid': fields.many2one('res.users', 'User', readonly=True, ),
'path_to_file': fields.char('Path to file', size=128, readonly=True, ),
'filename': fields.char('File name', size=128, readonly=True, ),
'download': fields.function(_get_file, type='binary', method=True, string='Download', readonly=True),
}
hystory_sent_inventory()