如何下载保存在Ir_attachment中的xls文件或打开保存在本地的xls文件?

How to Download xls file stored in Ir_attachment or open an xls file saved in local?

我暂时使用旧版 api 的 odoo8。 我创建了一个 xls 文件并将其存储在 ir_attachment 中。 现在我需要下载它,以便客户端用户可以选择在选定的本地位置下载它或使用 Microsoft excel 或任何可以打开 xls 文件的应用程序打开 xls 文件。 我可以看到 Odoo 正在使用 saveas 和 saveas_ajax,但我无法做到这一点(没有太多关于将数据传递给这些方法的细节)。 所以问题是:

或者如何在客户端用户选择的位置将 xls 文件本地写入客户端?

非常感谢!

已找到答案。

在 ir.attachment 中创建记录后,您可以 return:

new_attach = attachment_obj.create(cr, uid, attachment_data)

return {

'type' : 'ir.actions.act_url',

'url': '/web/binary/saveas?model=ir.attachment&field=datas&    filename_field=name&id=%s' % ( new_attach, ),

'target': 'self',

}

其中new_attach是在ir.attachment中新建记录的id。

结果是 open/save 文件 windows 对话框。

非常感谢!