Skip to Content
Menu
This question has been flagged
1 Reply
1751 Views

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) 



The problem is we have a lot of image and data attachments and can't reprocuce them inside the newly created note.

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

Avatar
Discard
Author Best Answer

For future reference, this was extremely easy: adding the many to many relationship in the 'message_attachment_rel' table. The whole thing worked.

Avatar
Discard
Related Posts Replies Views Activity
0
Dec 24
33
4
Jan 24
11040
1
Mar 23
4563
2
Apr 22
2292
0
Oct 21
1647