when clicking on button in tree view i am getting blank. please somebody help me.
<record model = "ir.ui.view" id = "view_order_form_dbt_task" >
<field name = "name" > sale.order.inherit </field>
<field name = "model" > sale.order </field>
< field name = "inherit_id" ref = "sale.view_order_form" />
<field name = "arch" type = "xml" >
<field name = "payment_term_id"position = "after" >
<field name ="attachment_ids" />
</field>
</field>
</record>
<record id = "view_order_tree_dbt_task" model = "ir.ui.view" >
<field name = "name" > sale.order.tree </field>
<field name = "model" > sale.order </field>
<field name = "inherit_id" ref = "sale.view_order_tree" />
<field name = "arch" type = "xml" >
<field name = "invoice_status " position = " after " >
<button name = "action_attachment_down" type = "object" string = "Download" />
</field>
</field>
</record>
in python fileclass dbt_task (models.Model):
_inherit = 'sale.order'
attachment_ids = fields.Binary ( 'Attachment' , attachment = True )
@ api.multi
def action_attachment_down ( self ):
for rec in self :
with io.BytesIO (base64 .b64decode (rec.attachment_ids)) as output:
result = output.read ()
base_url = self .env [ 'ir.config_parameter' ] .get_param ( 'web.base.url' )
attachment_obj = self .env [ 'ir.attachment' ]
attachment_id = attachment_obj.sudo (). create ({ 'name' : "name" , 'datas_fname' : 'name.file_ext' , 'datas' : result})
download_url = '/ web / content /' + str (attachment_id.id) + '? download = true '
return {'name' : 'Report' ,
'type': 'ir.actions.act_url',
"url": str(base_url) + str(download_url),
'target': 'new',
}
Get an idea to download file: https://learnopenerp.blogspot.com/2020/06/write-binary-data-nto-zip-file-and-downlaod-it-on-button-click-in-odoo.html