Hello,
I am trying to select multiple pickings and download into a single pdf they're attachments
( shipping labels )
Bellow is my code which will download only one attachment.
Working on Odoo 13 CE.
def generate_awb_pdf(self):
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
pickings = self.env['stock.picking'].search([('origin', 'in', [o.name for o in sale_orders])])
attachment_ids = self.env['ir.attachment'].search(
[('res_model', '=', 'stock.picking'), ('res_id', 'in', [p.id for p in pickings])])
result = b''
for rec in attachment_ids:
result += rec.datas
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", 'store_fname': 'awb.pdf', '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': 'self',
}
Thank you !
Hello Jainesh,
I've changed the code as you suggested (makes sense..) , however, nothing is getting downloaded.