Hi guys,
I was writing a small module on 18.0 EE essentially it goes to send an email with a custom receipt. The print function from the record creates the pdf correctly, but I can't create the ir.attachment in any way, I've tried several times creating the attachment first and adding it to the email with 6.0,receipt_attach_id but nothing. It always continues to give me an error when sending email on the lines of attachemnt id 259 user id 2 not found etc. If you could help me that would be perfect, thanks!
<record id="action_report_owner_receipt" model="ir.actions.report"> <field name="name">Ricevuta Soggiorno</field> <field name="model">pms.reservation</field> <field name="report_type">qweb-pdf</field> <field name="report_name">property_management.report_owner_receipt</field> <field name="report_file">property_management.report_owner_receipt</field> <field name="paperformat_id" ref="paperformat_owner_receipt"/> <field name="binding_model_id" ref="model_ciao_reservation"/> <field name="binding_type">report</field> <field name="print_report_name">'Ricevuta - %s' % (object.ota_res_id or object.pms_res_id or '')</field> </record>
report_action = self.env.ref('property_management.action_report_owner_receipt') pdf_content = report_action._render_qweb_pdf(self.id)[0] mail_values = { 'subject': subject, 'email_from': from_email, 'email_to': self.guest_partner_id.email, 'body_html': body_html, 'auto_delete': False, 'attachment_ids': [ (0, 0, { 'name': f'Ricevuta_{self.ota_res_id}.pdf', 'datas': base64.b64encode(pdf_content), 'mimetype': 'application/pdf', }) ] } mail = self.env['mail.mail'].sudo().create(mail_values) mail.send_mail(force_send=True, raise_exception=True)