Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binary field download link use in treeview or listview inside one2many field in Odoo

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"

like image 814
Bhavesh Odedra Avatar asked May 15 '16 18:05

Bhavesh Odedra


2 Answers

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

like image 87
danidee Avatar answered Oct 15 '22 19:10

danidee


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>    
like image 39
Nilesh Sheliya Avatar answered Oct 15 '22 18:10

Nilesh Sheliya