Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
5 Antwoorden
18711 Weergaven

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.

Avatar
Annuleer

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

Beste antwoord

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.

Avatar
Annuleer

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

Thanks for this. It helped me with my missing invoice attachments. :)

Auteur Beste antwoord

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)

Avatar
Annuleer

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

Beste antwoord

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

Avatar
Annuleer
Auteur

Can u explain in details

Beste antwoord

Hi,

You can refer the blog

https://www.cybrosys.com/blog/how-to-add-email-attachments-pdf-excel-in-odoo-16

This blog provides a step-by-step guide on how to add email attachments (PDF/Excel) in Odoo 16. It includes creating a new module, defining methods to generate and return the PDF report, and sending the email with the PDF report .

Regards

Avatar
Annuleer
Beste antwoord

The answers provided here is for odoo 10 or below;

Here is a sample code done to generate Pdf and save to attachment using render_qweb_pdf for sending mail: 

def generate_report_file(selfid):
        pdf = self.env.ref('mymodule.action_report_labtest').render_qweb_pdf(id)[0]
        pdf = base64.b64encode(pdf)
        return pdf
So, you can return pdf as a binary to any binary field as this;
self.binary_field = self.generate_report_file(idoftherecord.id)

You can attach it to an attachment like this;
report_binary = self.generate_report_file(LabObj.id)
attachmentObj = self.env['ir.attachment'].create({
                'name': attachment_name,
                'type''binary',
                'datas': report_binary,
                'datas_fname': attachment_name + '.pdf',
                'store_fname': attachment_name,
                'res_model'self._name,
                'res_id'self.id,
                'mimetype''application/x-pdf'
            })

@Maduka Sopulu Chris 

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
mei 15
5600
2
dec. 23
59646
3
dec. 23
19986
1
mrt. 16
15402
1
sep. 15
4121