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

Attach PDF on quotation "send by mail" method

By
Jerome Guerriat
on 11/1/15, 9:22 AM 641 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'

@api.multi
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,
}
 
attachment_ids.append(ir_attachment.create(attachment_data).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?

0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 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.

Ex:

@api.multi
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.

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: 11/1/15, 9:22 AM
Seen: 641 times
Last updated: 11/3/15, 2:19 AM