Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
24131 Vizualizări

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 .

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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('/')
Imagine profil
Abandonează

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

Autor

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

Cel mai bun răspuns

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}">

Imagine profil
Abandonează

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.

Cel mai bun răspuns

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)

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
iul. 18
2632
2
iul. 18
3026
2
nov. 17
4520
3
mai 23
15628
1
ian. 23
1933