跳至内容
菜单
此问题已终结
5 回复
24054 查看

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 .

形象
丢弃
编写者 最佳答案

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('/')
形象
丢弃

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

编写者

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

最佳答案

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

形象
丢弃

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.

最佳答案

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)

形象
丢弃
相关帖文 回复 查看 活动
0
7月 18
2609
2
7月 18
3015
2
11月 17
4507
3
5月 23
15576
1
1月 23
1912