This question has been flagged
5 Replies
20751 Views

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

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

Author

its the ID of the record to print

For Odoo 14 its working

comment for future ref

_render_qweb_pdf()

Thank Niyas for Helping

With this code we print the card of the ecocode or an invoice

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

Hello mate!
I'm doing this same in odoo15 to call payslip report of employee in webportal but can't be able to get. just getting an Keyerror: False . Please guide me little about this.

Best Answer

If you are using odoo 13 then this solution will work :

@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.ref('module_name.report_id').sudo().render_qweb_pdf([student_id.id])[0]
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)

Avatar
Discard