Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
24302 Lượt xem

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 .

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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('/')
Ảnh đại diện
Huỷ bỏ

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

Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 18
2742
2
thg 7 18
3119
2
thg 11 17
4639
3
thg 5 23
15885
1
thg 1 23
2026