Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
6992 Visualizzazioni

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


Avatar
Abbandona

in odoo 15 method is: _render_qweb_pdf

Autore Risposta migliore

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


Avatar
Abbandona
Risposta migliore
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
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 23
1571
5
nov 23
8233
1
feb 23
1730
2
feb 23
1819
1
mag 25
519