The 'download' button should download *all* the attachments linked to the move. Depending on the localization, an xml might be needed in addition to the PDF (e.g. the CFDI and the signed PDF in Mexico). To do that, we open a headless Send & Print wizard with only the `download` checkbox set to True. Secondly, do not show the 'Download' button in the portal view if no official attachment is linked to the move (the print button still appears). task-3542881 Part-of: odoo/odoo#138206
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http, _
|
|
from odoo.http import request, content_disposition
|
|
|
|
|
|
def _get_zip_headers(content, filename):
|
|
return [
|
|
('Content-Type', 'zip'),
|
|
('X-Content-Type-Options', 'nosniff'),
|
|
('Content-Length', len(content)),
|
|
('Content-Disposition', content_disposition(filename)),
|
|
]
|
|
|
|
|
|
class AccountDocumentDownloadController(http.Controller):
|
|
@http.route('/account/export_zip_documents', type='http', auth='user')
|
|
def export_zip_documents(self, **args):
|
|
""" Download zipped attachments. """
|
|
ids = list(map(int, request.httprequest.args.getlist('ids')))
|
|
filename = request.httprequest.args.get('filename')
|
|
attachments = request.env['ir.attachment'].browse(ids)
|
|
attachments.check_access_rights('read')
|
|
attachments.check_access_rule('read')
|
|
content = attachments._build_zip_from_attachments()
|
|
headers = _get_zip_headers(content, filename)
|
|
return request.make_response(content, headers)
|