更改上传的二进制文件字段的文件名

更改上传的二进制文件字段的文件名

问题描述:

我正在使用 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>