Skip to Content
Menu
This question has been flagged
7 Replies
8625 Views

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
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)



Avatar
Discard
Author

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

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('/')
Avatar
Discard
Author

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!

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/

Author

ok thanks :)

Author

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'

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

Related Posts Replies Views Activity
1
Nov 19
2383
2
Oct 17
12707
1
Aug 22
5449
2
Sep 21
5710
0
Dec 23
909