更改上传的二进制文件字段的文件名 [英] Changing the Filename of a Uploaded Binary File Field

查看:251
本文介绍了更改上传的二进制文件字段的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Odoo8

我有一个问题,我使用fields.binary在Odoo中上传文件.但是,当我尝试下载它时,上载文件的filename是型号名称.

I have a question I used the fields.binary to upload a file/s in Odoo. But when I try to download it the filename of the uploaded file is the model name.

是否可以更改文件的filename?

Is it possible to change the filename of the file?

其次,字段中的filter属性不起作用.

And second the filters attribute in fields does not work.

推荐答案

我对此问题/问题的解决方案,首先创建一个计算字段及其功能

My Solution to this matter/problem, create first a compute field and its function

.py

filename = fields.Char('file name', readonly = True,store = False,compute ='legacy_doc1_getFilename')

@api.one
def legacy_doc1_getFilename(self):

    if len(self.employee_number) > 0:
        self.filename = str(self.employee_number) + '_ConfidentialReports.pdf'
    else:
        self.filename = 'filename_ConfidentialReports.pdf'

在XML文件中,只需添加属性文件和字段

and in XML file just add the attribute file and the field

<page string="Legacy Documents">
    <group>
        <field name="filename" readonly="1" invisible="1"/>
        <field name="legacy_doc_1" filename="filename"/>
    </group>
</page>

这篇关于更改上传的二进制文件字段的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆