For example, there is a sale order report and it's id = "action_report_saleorder",consequently REPORT_ID in example = sale.action_report_saleorder (Example odoo v11)def action_generate_attachment(self):""" this method called from button action in view xml """# generate pdf from report, use report's id as referenceREPORT_ID = 'some_report_id'pdf = self.env.ref(REPORT_ID).render_qweb_pdf(self.ids)# pdf result is a listb64_pdf = base64.b64encode(pdf[0])# save pdf as attachmentATTACHMENT_NAME = "My Attachment Name"return self.env['ir.attachment'].create({'name': ATTACHMENT_NAME,'type': 'binary','datas': b64_pdf,'datas_fname': ATTACHMENT_NAME + '.pdf','store_fname': ATTACHMENT_NAME,'res_model': self._name,'res_id': self.id,'mimetype': 'application/x-pdf'})Why when I perform a similar action, nothing works for me? | |
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
Hi,
While you doing this operation, a pdf report will be stored under ir_attachment table. Here the res_model and res_id will be the reference for attachment for relating with a record. Here let's take sale.order of id 20, here you need to attach the pdf report with the current sale order then we will give res_model as sale.order and res_id as 20.
here the self._name will the current model name.
Update:-
render_qweb_pdf render the HTML content defined in the report template and returns a pdf file. If you call the function with the param res_ids then it will automatically save the attachment with pdf content.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
5
thg 5 23
|
15211 | ||
|
2
thg 12 23
|
5166 | ||
|
1
thg 5 22
|
2405 | ||
|
0
thg 4 22
|
1873 | ||
|
2
thg 9 17
|
4332 |
Look into odoo tips, may be its helpful: https://learnopenerp.tumblr.com/