Help

6

How to print report from website ?

Avatar
Niyas Raphy

Hi,

I have a button in the website and i have the invoice id in the same page, what i want to get is that , on clicking the button, i want to get the invoice print .

Avatar
Discard
3 Answers
5
Avatar
Niyas Raphy
Best Answer

Got the solution,

Printed the report by giving a href to the button like this,

<a t-attf-href="'/report/pdf/account.report_invoice/%s' % i.id">
<button type="button" class="btn btn-primary btn-md o_website_form_send">Print Invoice</button>
</a>

In the i.id i have the id of the invoice.
This is the format,
report/type_of_the_report/module_name.template_name/id

To print the report from the  controller,


@http.route('/school/card', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True)
def print_id(self, **kw):
student_id = kw['stud_id']
if student_id:
pdf = request.env['report'].sudo().get_pdf([student_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('/')
2 Comments
Avatar
Discard
Avatar
Abdullah
-

sir i didnt get this "i.id" part. can you please help. I have given my template id and module name before that but i dont understand what to put in i.id

Avatar
Niyas Raphy
-

its the ID of the record to print

2
Best Answer

Or in another way by directly calling the id in #{record.id} like this:

<a t-attf-href="/report/pdf/account.report_invoice/#{i.id}">

Avatar
Discard
0
Avatar
Mehul Jadav
Best Answer

How to print report in chatterbox??

Avatar
Discard