5

I'm using Odoo8

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.

Is it possible to change the filename of the file?

And second the filters attribute in fields does not work.

Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
Black and White
  • 452
  • 1
  • 9
  • 32

2 Answers2

3

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'

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>
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
Black and White
  • 452
  • 1
  • 9
  • 32
1

I had the same problem and the following solution sovled it:

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

Andromida
  • 1,095
  • 1
  • 11
  • 28