Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
6984 Weergaven

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
Annuleer

in odoo 15 method is: _render_qweb_pdf

Auteur Beste antwoord

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
Annuleer
Beste antwoord
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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
aug. 23
1571
5
nov. 23
8227
1
feb. 23
1730
2
feb. 23
1816
1
mei 25
514