Skip to Content
Menu
This question has been flagged
2 Replies
4659 Views

How to get the URL of the PDF report (qweb report), for example C:/Users/h/Downloads/test.pdf

Avatar
Discard
Best Answer

Hi,

If your report is linked directly with a record, like for example sale order print, you can access it as follows:

http://your_domain_or_ip/report/pdf/sale.report_saleorder/38  where 38 is the ID of the sale.order


Reports are web pages

Reports are dynamically generated by the report module and can be accessed directly via URL:

For example, you can access a Sale Order report in html mode by going to http://your_domain_or_ip/report/html/sale.report_saleorder/38

Or you can access the pdf version at http:///report/pdf/sale.report_saleorder/38

Documentation:  https://www.odoo.com/documentation/15.0/developer/reference/backend/reports.html


Thanks

Avatar
Discard
Best Answer

Hi,
Refer to this code

pdf = request.env.ref('account.account_invoices').sudo().render_qweb_pdf([res.id])[0]
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
attachment = request.env['ir.attachment'].sudo().create({
'name': res.name + ".pdf",
'type': 'binary',
'res_id': res.id,
'res_model': 'account.move',
'datas': base64.b64encode(pdf),
'mimetype': 'application/x-pdf'
})
url = '%s/web/invoice.pdf?model=ir.attachment&id=%s&name=inv.pdf&field=datas' % (
base_url, attachment.id
)

class BinaryAttachment(http.Controller):
""" taking url of attachment from ir.attachment"""

@http.route('/web/invoice.pdf', type='http', auth="none")
def image_get(self, xmlid=None, model='ir.attachment', id=None,
field='datas', filename_field='name', unique=None,
filename=None, mimetype=None, download=None, width=0,
height=0, crop=False, access_token=None, **kwargs):
return self._content_image(xmlid=xmlid, model=model,
id=id, field=field, unique=unique,
filename_field=filename_field, crop=crop,
filename=filename, mimetype=mimetype,
download=download, width=width,
height=height, access_token=access_token,
quality=int(kwargs.get('quality', 0)))

def _content_image(self, xmlid=None, model='ir.attachment', id=None,
field='datas', filename_field='name', unique=None,
filename=None, mimetype=None, download=None, width=0,
height=0, crop=False, quality=0, access_token=None,
placeholder='placeholder.png', **kwargs):
status, headers, image_base64 = request.env['ir.http'].with_user(
1).binary_content(
xmlid=xmlid, model=model, id=id, field=field, unique=unique,
filename=filename, filename_field=filename_field,
download=download, mimetype=mimetype, default_mimetype='image/png',
access_token=access_token)

if status in [301, 304] or (status != 200 and download):
return request.env['ir.http']._response_by_status(status, headers,
image_base64)
if not image_base64:
image_base64 = base64.b64encode(
self.placeholder(image=placeholder))
if not (width or height):
width, height = odoo.tools.image_guess_size_from_field_name(
field)
image_base64 = image_process(image_base64, size=(int(width),
int(height)),
crop=crop, quality=int(quality))
content = base64.b64decode(image_base64)
headers = http.set_safe_image_headers(headers, content)
response = request.make_response(content, headers)
response.status_code = status
return response


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 23
3186
1
Apr 23
4013
1
Nov 22
2820
1
Oct 21
11462
0
Oct 21
1586