
Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn
由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解
本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!
开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号
如果您登录系统碰到问题,请在微信公众号留言:
EO中处理用户提交excel,返回结果
-
功能:用户上传excel,系统按照业务逻辑处理excel文件,结果文件返回给用户
非常感谢mrshelly帮助,已完成功能主线,总结如下,有问题请大家多多指点
1.上传文件在_columns里面使用fields.binary实现
'excel': fields.binary('File', filters='*.xls'),
2.在form view中使用button调用py中的方法,name属性对应方法名称
<button name="import_file" string="上传" type="object" class="oe_highlight" />
3.在py的import_file方法中获取上传的excel文件
this = self.browse(cr, uid, ids[0])
data=base64.decodestring(this.excel)
4.传递给xlrd,结合xlwt,xlutils进行自己的业务逻辑处理
rb = open_workbook(file_contents=data, formatting_info=True, on_demand=True)
wb = copy(rb)
...
s= StringIO.StringIO()
wb.save(s)
return s
5.保存处理结果到库中
out = base64.encodestring(s.getvalue())
self.write(cr, uid, ids, {'excel': out,...}, context=context)
6.返回到view中的指定视图
obj_model = self.pool.get('ir.model.data')
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','your_view_id')])
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']
return {
'type': 'ir.actions.act_window',
'res_model': 'your_model',
'view_mode': 'form',
'view_type': 'form',
'views': [(resource_id,'form')],
'res_id': this.id,
'target': 'new',
}
7.在view中提供下载链接给用户
<p>打开分析结果<field name="excel" readonly="1" filename="name"/></p> -
不错的方法,谢谢楼主分享。