跳至內容
選單
此問題已被標幟
2 回覆
7135 瀏覽次數

Please help to get a python function to attach Qweb Report (PDF file) in a binary field 

v15c


report_file = fields.Many2one('ir.attachment', string='PDF')
def generate_report_file(self):
report_template_id = self.env.ref('id_card_by_fas.id_card_template_report').render_qweb_pdf(self.id)
data_record = base64.b64encode(report_template_id[0])
ir_values = {
'name': "ID Card",
'type': 'binary',
'datas': data_record,
'store_fname': data_record,
'mimetype': 'application/x-pdf',
}
data_id = self.env['ir.attachment'].create(ir_values)
self.report_file = data_id.id
return True

Tried above method, but showing the error "AttributeError: 'ir.actions.report' object has no attribute 'render_qweb_pdf'"


頭像
捨棄

in odoo 15 method is: _render_qweb_pdf

作者 最佳答案

Thank you.. Niyas Raphy

It was _render_qweb_pdf()


def generate_report_file(self):
report_template_id = self.env.ref('id_card_by_fas.id_card_template_report')._render_qweb_pdf(self.id)
data_record = base64.b64encode(report_template_id[0])
ir_values = {
'name': "ID Card",
'type': 'binary',
'datas': data_record,
'store_fname': data_record,
'mimetype': 'application/x-pdf',
}
data_id = self.env['ir.attachment'].create(ir_values)
self.report_file = data_id.id
return True


頭像
捨棄
最佳答案
If anyone still has problems with this, id did it this way
pdf_content = fields.Binary(string='PDF generado')   
def action_report(self):       
report_template_id = self.env.ref('base_icg.action_report_op_ticket')._render_qweb_pdf(self.ids)        report_data = report_template_id[0]           
# Convertir los datos del informe a bytes       
report_bytes = base64.b64encode(report_data)               
# Crear el registro de ir.attachment       
attachment_values = {
​'name': "Informe.pdf",           
​'type': 'binary',           
​'datas': report_bytes,           
​ 'store_fname': "Informe.pdf",           
​'mimetype': 'application/x-pdf',       
​ }       
​attachment = self.env['ir.attachment'].create(attachment_values)             
  # Almacenar el ID del archivo adjunto en el campo pdf_content     
self.pdf_content = attachment.datas               
return True
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
8月 23
1648
5
11月 23
8358
1
2月 23
1845
2
2月 23
1872
3
5月 25
2231