Changing the file name of a downloaded binary file

I am using Odoo8

My question is, I used fields.binaryto upload the / s file to Odoo. But when I try to download it, the filenamedownloaded file is the model name.

Can I change the file of a filenamefile?

And the second filter attribute in the fields does not work.

+4
source share
2 answers

My solution to this problem / problem, first create a calculation 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'

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

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

I had the same problem and the following solution resolved this:

class MyModel(models.Model):
    _name = 'my.model'

    name = fields.Char(string='Name')
    image = fields.Binary(string='Image', required=True)
    image_filename = fields.Char(string='Image Filename')

in xml:

<field name="name" />
<field name="image_filename" invisible="1"/>
<field widget="binary" height="64" name="image" filename="image_filename" />

And here is the result:

enter image description here

0

Source: https://habr.com/ru/post/1609409/


All Articles