I need to create a custom code snippet that will duplicate the notes from pipelines to contracts. The following code works fine:
lead_notes = record.env['mail.message'].search([('res_id', '=', record.opportunity_id.id), ('model', '=', 'crm.lead')])
if lead_notes:
for lead_note in lead_notes:
record.message_post(body = lead_note.body)
I tried to recreate the ir_attachment record changing the mail_message reference, soon to understand that the attachments are stored in reference to the 'crm.lead" res_model and to the parent model id and not to the mail model.
Even though creating another mail.message attachment using the record.env['mail.message'].create() function with relation to another sale.order ID works, it's clearly not displayed on any post. I tried to go through all tables to find the relationship(s?) to create but I'm clearly missing something.
May anyone help?
Thanks in advance