8

I'm using Odoo 8 version.

I have created a new model called enquiry_customer_date

In that model, I have set following four fields.

  • partner_id (many2one),
  • enquiry_date (date),
  • file_name (char) and
  • excel_file (binary)

I have given mention model one2many relationship with res.partner model

I have used below code for display records.

<field name="enquiry_from_customer_ids">
    <tree string="Enquiry Lines">
        <field name="enquiry_date"/>
        <field name="file_name" invisible="1"/>
        <field name="excel_file" filename="file_name"/>
    </tree>    
</field>

This will display correct file name in list view.

Face Problem:

When I download link, it stores with file name = base64 with .bin extension.

Question:

How to get working download link same as uploaded file name with extension in one2many field?

UPDATED

I have tried with @danidee answer.

System configuration parameter:

System configuration parameter

Treeview/Listview one2many field

Treeview/Listview one2many field

OUTPUT:

enter image description here

Expected Output:

File should be downloaded with "Openerp_Customization_Needed.txt"

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58

2 Answers2

1

By default files and attachements are stored in the db as binary files, but you can change that behaviour by setting the ir_attachement.location parameter

Got to Settings/Parameters/System Parameters, look for ir_attachment.location it should be set to db change it to

file:///filestore

Note that the existing attachments and files will still be stored in the database, but any new attachment or file uploaded will be stored in the file system, which should enable you to download the file in it's original form like you wanted

danidee
  • 9,298
  • 2
  • 35
  • 55
  • Thanks for your answer. I have checked into my server. I don't have value as you describe. I have created manually as per your suggestion. And it's not working. Still I'm getting something *base64* name with *.bin* extension. – Bhavesh Odedra May 16 '16 at 12:14
  • have you checked your server path(where odoo is installed), if the `filestore` folder was generated? and did you upload a new file to test it again...because existing one's won't be automatically converted to their original form. as for the name of the file 'Openerp_Customization_Needed.txt' you can't automatically get that as odoo uses `SHA1` to generate unique file names so as to avoid duplicates – danidee May 16 '16 at 20:08
  • it's not working. Is there any other trick of using python code? – Bhavesh Odedra May 23 '16 at 15:09
1

Yes, you can export file as like you have uploaded via adding button in tree view instead of directly giving binary field name in treeview. Please add below code in enquiry_customer_date model

@api.multi
def export_file( self ):
    return {
        'type' : 'ir.actions.act_url',
        'url':   '/web/binary/saveas?model=ir.attachment&field=datas&filename_field=self.file_name&id=%s' % ( self.excel_file.id ),
        'target': 'self',
        }

Add the below code in your xml file,

<field name="enquiry_from_customer_ids">
    <tree string="Enquiry Lines">
        <field name="enquiry_date"/>
        <field name="file_name" invisible="1"/>
        <field name="excel_file" filename="file_name"/>
        <button name="export_file" string="Download" type="object" icon="gtk-ok" class="oe_highlight" />  
    </tree>    
</field>    
Nilesh Sheliya
  • 591
  • 2
  • 10
  • Thanks @Niliesh for your answer. Yes we can do it from adding new button. Please read my question carefully. It about *"Donwload link"* Open ir.attachment form. In form view you may see file as *"Donwload File_name"* If you click on it, it will save in your local machine. That behavior is not same with *one2many* field – Bhavesh Odedra May 24 '16 at 15:52