How to get the URL of the PDF report (qweb report), for example C:/Users/h/Downloads/test.pdf
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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 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
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jun 23
|
3186 | ||
|
1
Apr 23
|
4013 | ||
|
1
Nov 22
|
2820 | ||
|
1
Oct 21
|
11462 | ||
|
0
Oct 21
|
1586 |