Openerp - 如何设置fields.binary的默认值?

时间:2016-07-19 10:23:10

标签: openerp

现在有人如何为fields.binary设置默认值?

我成功使用default_get()方法将数据放入fields.binary中,但是当我尝试打开文件时(通过单击&#39;另存为&#39;按钮),我收到以下错误消息:< / p>

  

Firefox无法在地址http://172.17.0.2:8061/openerp/form/save_binary_data?_terp_field=template_file&_terp_model=import_batch_number&_terp_id=F

找到该文件

2 个答案:

答案 0 :(得分:2)

尝试使用此代码

import base64

binary_field=fields.Binary(string='Image',default='get_default_image')

def get_default_image(self):
   with open("yourfile_path.ext", "rb") as image_file:
      self.binary_field = base64.b64encode(image_file.read())

希望这有帮助。

答案 1 :(得分:0)

存在一个问题,因为显示的记录尚未保存在DB中,因此OpenERP无法将文档存储在fields.binary中。

我在打开视图之前创建了文档,但它运行良好。