跳至内容
菜单
此问题已终结
1251 查看

Hey guys, I made a form that when u tell to print, it downloads the pdf, but i want not to download it local, i want to send it by mail to a direction, but im not able to do that by the moment, i thought to make that when i create the a new form, when the users saves the info to generate it, and then when it says print, to send it by mail to the direction of the printer, the code i used to download it

def action_report(self):       

return self.env.ref('base_icg.action_report_op_ticket').report_action(self)

but i dont know how to store it i tried like this (ChatGPT) but it crashes code error pdf, any clues or other ways thanks a lot 
 
def action_report(self):    
        report_action = self.env.ref('base_icg.action_report_op_ticket').report_action(self)                  ​pdf_content = report_action['pdf'][0]

        return pdf_content

      @api.model    def create(self, vals):       

 if vals.get('orden_trabajo', _('New')) == _('New'):           

 if vals.get('bool_taller'):                sequence_code = 'fichas'            

else:                

sequence_code = 'parte'           

 sequence_number = self.env['ir.sequence'].next_by_code(sequence_code) or _('New')            vals['name'] = sequence_number        

result = super(Parte, self).create(vals)     

   pdf_content = result.action_report()       

 result.write({'pdf_field': pdf_content})        

return result

**UPDATE
Im able to store it in a field and preview it with this method
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
3月 23
5567
1
4月 25
3423
2
7月 24
4978
1
4月 24
1022
1
2月 24
3144