Odoo Help


Attach PDF on quotation "send by mail" method

Jerome Guerriat
on 11/1/15, 9:22 AM 1,636 views

Hi everyone!

I would like to attach PDF (or whatever file type...) to the quotation sent by email..

For this, i'm trying to override the send_mail method from mail_compose_message class. I succeeded to create a new mail with hardcoded values and to attach my files to that email, but of course i would like to attach the files to the email created with the pop up view when "send by mail" is clicked.

How can i override that method? I think i should call super.send_mail() but i don't know how to add my attachment if i do that :/

Here is my code with hardcoded values:

class mail_compose_message(osv.Model):
_inherit = 'mail.compose.message'

def send_mail(self):
#retrieve order
order_id =self.env.context["active_id"]
order = self.env['sale.order'].browse([order_id])
attachment_ids = []
#create a new ir.attachment
ir_attachment = self.env['ir.attachment']
mail = self.env["mail.mail"].create({"email_from":"a@a.com","email_to":"b@b.com","subject":"subject","body_html":"d"})

#for each line, look for product fiches. Add fiches to attachment
for line in order.order_line:
for product_fiche in line.product_id.documents:
attachment_data = {'name': product_fiche.name,
'datas_fname': product_fiche.datas_fname,
'datas': product_fiche.datas,
'res_model': "mail.mail",
'res_id': mail.id,

        mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
return mail.send()

I suppose i shouldn't be creating the email myself, and only send the attachment_ids to the super method, but i don't know how to do that. Could someone help me?


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
Serpent Consulting Services Pvt. Ltd.
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 11/3/15, 2:19 AM

Hello Jerome,

You can create the attachments in "mail.compose.message" by overriding the send_mail method.


def send_mail(self):
# create the attachments same way you have created in your code
# and append attachment ID in a list
for attachment_id in attachment_ids:
self.write({'attachment_ids': [(4, attachment_id)]})
# super call
return super(mail_compose_message, self).send_mail()

Hope this helps you.

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/1/15, 9:22 AM
Seen: 1636 times
Last updated: 11/3/15, 2:19 AM