Created
November 24, 2022 20:07
-
-
Save bfritscher/55fc85d81694b644faba964cb69a1f86 to your computer and use it in GitHub Desktop.
odoo15 init mail composer with multiple attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template_id = 11 # lookup not working with env.ref('mail.template.Envoi dem. collocation, CV et CC (SRH)').id | |
compose_form_id = env.ref('mail.email_compose_message_wizard_form').id | |
attachment = { | |
'name': str(record.x_studio_cv_filename), | |
'datas': record.x_studio_cv, | |
'res_model': 'mail.compose.message', | |
'type': 'binary' | |
} | |
cv = env['ir.attachment'].sudo().create(attachment) | |
cdc_record_id = record.x_studio_contrat.x_studio_many2one_field_KdGBT.id | |
# studio_customization.studio_report_docume_f5a65386-780e-43d0-b161-8a7e54ebcc8a | |
cdc_report = env.ref('studio_customization.cahier_des_charges_r_7fd43d12-8c21-42f0-a93b-ed8e6a84e543') | |
cdc_pdf = cdc_report._render_qweb_pdf(cdc_record_id) | |
# cdc_pdf = env['report'].sudo().get_pdf([cdc_record_id], 'studio_customization.studio_report_docume_f5a65386-780e-43d0-b161-8a7e54ebcc8a') | |
cdc = env['ir.attachment'].create({ | |
'name': 'Cahier des charges.pdf', | |
'type': 'binary', | |
'raw': cdc_pdf[0], | |
'res_model': 'x_cahier_des_charges', | |
'res_id': cdc_record_id, | |
'mimetype': 'application/x-pdf' | |
}) | |
ctx = { | |
'default_model': 'x_engagement_chercheur', | |
'default_res_id': record.id, | |
'default_use_template': bool(template_id), | |
'default_template_id': template_id, | |
'default_composition_mode': 'mass_mail', | |
'default_attachment_ids': [cv.id, cdc.id] | |
} | |
action = { | |
'type': 'ir.actions.act_window', | |
'view_type': 'form', | |
'view_mode': 'form', | |
'res_model': 'mail.compose.message', | |
'views': [(compose_form_id, 'form')], | |
'views_id': compose_form_id, | |
'target': 'new', | |
'context': ctx, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment