Help

0

(Odoo v11) Print button on website to print the report in pdf.

Avatar
Abdullah

i have a purchase comparison chart which matches the Bids amount . It shows the comparison in odoo website but client also want to save that report. I find no way of downloading that report. I am thinking of a button on the website screen which can the download the report. I need some guidance Please help  

Avatar
Discard
2 Answers
3
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Follow the steps below

create a button:(xml)

<a t-attf-href="'/report/type_of_the_report/module_name.template_name/%s' % id">
    <button type="button" class="btn btn-primary btn-md o_website_form_send">Print Report</button>
</a>

in controller:(py)

@http.route('your custom route', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
record_id = kw['rec_id']
if record_id:
pdf = request.env['report'].sudo().get_pdf([record_id], 'module_name.report_name', data=None)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
else:
return request.redirect('/')
5 Comments
Avatar
Discard
Avatar
Abdullah
-

Thank you so much for replying!

when i follow the above line of code and press the button it takes me to another page and says "404 page not found".

I have 3 confusions if you can please help

1) should i create another class in the controller for the above http.route?As i already have a class with a route which displays my report.

2)For web reports , do we have to set it up same like pdf reports? like the following

<report

id="account_invoices"

model="account.invoice"

string="Invoices"

report_type="qweb-pdf"

name="account.report_invoice"

file="account.report_invoice"

attachment_use="True"

attachment="(object.state in ('open','paid')) and

('INV'+(object.number or '').replace('/','')+'.pdf')"

/>

3) On what basis we define a route? shoould it be same of the button path?

It will be very helpful if you could just explain as its my first time working with controller. i'll be very thankful!

Avatar
Cybrosys Techno Solutions Pvt.Ltd
-

You can refer the following module for the clarification in which we are added the option for printing the pdf catalogue of a product from the website

https://www.odoo.com/apps/modules/12.0/product_catalogue/

Avatar
Abdullah
-

ok thanks :)

Avatar
Abdullah
-

That download catelogue button in your module is not working giving internal server error and this is what i have in the log

AttributeError: 'report.product_catalogue.report_product_catalog' object has no attribute 'get_report_values'

Avatar
Cybrosys Techno Solutions Pvt.Ltd
-

This module is available for odoo 12, i think you are trying to install this module on odoo v11

0
Avatar
Nikhil kushwaha
Best Answer

XML 

<a t-att-href="/report/new/">
  <button type="button" class="btn btn-primary btn-md ">Print Report</button>
</a>

Python 


@http.route('/report/new/', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
    pdf, _ = request.env.ref('Model_Name.Action_Name')\.sudo().render_qweb_pdf([int(purchase_id)])
    pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)),('Content-Disposition', 'catalogue' + '.pdf;')]
    return request.make_response(pdf, headers=pdfhttpheaders)



1 Comment
Avatar
Discard
Avatar
Abdullah
-

hey thanks for replying. one question, you are using purchase_id for?