Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Odoo auto attach pdf in email

By
Ashish Singh
on 3/20/15, 2:06 PM 2,768 views

Hello Guys,

I am working on timesheet module odoo of some report generation,

In Timesheet Activity Tree view  once we select any record More option will display, in More option i had put one button that call one wizard. In that wizard i had put two button one is generating report(RML Report) (list of all timesheet line based on Analytical Account).

and other button send a mail to a client of Analytical Account , Now here i get stuck that how can i automatically attach a pdf report which i had generated or it automatically generate new pdf and attach automatically in email.

Hi,do you use a template to send email ? Secondly, does your pdf is store in attachment or dynamically from where and how? bye

Cyril Gaspard (GEM)
on 3/20/15, 3:58 PM
1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/21/15, 4:38 AM

Hi,

in function you call by pushing your button, when you call method send_mail of model email_template ((module email_template), add in context all informations you need to build your pdf and id of the email in a list with key 'add_pdf': [email_id, 'file_name.pdf', ....]. for function parameter 'force_send'  set value True, then the method send of mail_mail model module mail) will be called by inheriting the context.

In this function, variable attachments contains files to send with code:


# load attachment binary data with a separate read(), as prefetching all

# `datas` (binary field) could bloat the browse cache, triggerring

# soft/hard mem limits with temporary data.

attachment_ids = [a.id for a in mail.attachment_ids]

attachments = [(a['datas_fname'], base64.b64decode(a['datas']))

for a in ir_attachment.read(cr, SUPERUSER_ID, attachment_ids,

     ['datas_fname', 'datas'])]


you should override after this code in your module by overriding method send:

+ test if key 'add_pdf' is in the context

+ if yes test email_id of the key 'add_pdf' with current email_id of function send of the for loop.

+ if yes, call your function which genarates your pdf using informations you have in key 'add_pdf' and had tuple ('file_name.pdf', file) to the variable attachments list

bye

Can u explain in details

Ashish Singh
on 3/21/15, 5:32 AM
0
Ashish Singh
On 3/21/15, 12:51 AM

I had made one email template for sending mail, and initially my pdf is not store in attachment, i want to add dynamically.

Means once i click a button called send email , one function call that  internally call my email template and send msg to client, but in that mail i want to also attach my pdf which  automatically( its call generate pff method and attach in email)

I have tried that in Qweb report pls try this.............. https://www.odoo.com/forum/help-1/question/how-to-send-email-76125#answer-76136

Umashankar Subramani
on 3/23/15, 1:45 AM
0
Umashankar Subramani
On 3/21/15, 2:47 AM

Hi kumar,

   First you need to create a template for your email ,settings->email->template-> create -> Name-(User defined), Applies to- description to model, model- model for creating email, and you can give acces rights, on the content tab you need create the template. In email configuration you need to configure your email address for sender and receiver. And in advanced setting you have an option that you can add a attachment automatically by giving the optional report to print or attach and save the template.

Hi, with your solution, an ir_attachment is created, but Kumar do not want this. Bye

Cyril Gaspard (GEM)
on 3/21/15, 4:13 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/20/15, 2:06 PM
Seen: 2768 times
Last updated: 9/16/15, 7:45 AM