Hello,
I want to send an attachment PDF with email using scheduling action my function work well, but the report was messed
here is my function:
for record in invoices:
recipient_lists =[]
if record.partner_id:
recipient_lists.append(record\.partner_id\.id\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ template\ =\ self\.env\.ref\('account\.email_template_edi_invoice',\ False\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mail_template\ =\ self\.env\['mail\.template'\]\.browse\(template\.id\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ values\ =\ mail_template\.generate_email\(record\.id,\ fields=None\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ values\['recipient_ids'\]\ =\ \[\(6,0,\[recipient_lists\]\)\]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ values\['res_id'\]\ =\ record\.id
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ attachment_ids\ =\ values\.pop\('attachment_ids',\ \[\]\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ attachments\ =\ values\.pop\('attachments',\ \[\]\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ mail_create\ =\ self\.env\['mail\.mail'\]\.create\(values\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Attachment\ =\ self\.env\['ir\.attachment'\]
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ for\ attachment\ in\ attachments:
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ attachment_data\ =\ \{
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'name':\ attachment\[0\],
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'datas_fname':\ attachment\[0\],
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'datas':\ attachment\[1\],
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'type':\ 'binary',
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'res_model':\ 'mail\.message',
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 'res_id':\ mail_create.mail_message_id.id,
}
attachment_ids.append(Attachment.create(attachment_data).id)
values['attachment_ids'] = [(6, 0, attachment_ids)]
mail_create.write({'email_from':record.company_id.subscription_email,'attachment_ids': [(6, 0, attachment_ids)]})
if mail_create:
mail_create.send()
record.the_main_sent = True