Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
8216 Lượt xem

I want to send RFQ to  vendor of purchase order by code my code is as below

    @api.multi    

    def send_mail(self,purchase_id):

        email_template_obj = self.env['mail.template']

        template_ids = email_template_obj.search([('name','=','RFQ - Send by Email'),('model_id.model', '=', 'purchase.order')])

        values={}

        if template_ids:

              email=self.env['mail.template'].browse(template_ids.id).send_mail(purchase_id)

              self.env['mail.mail'].browse(email).send()

        return True

This code send email to vendor  as like below attachment.

          

I want emai like as below image,when i send rfq by button "send RFQ by mail" of purchase order.I need email body should be like below image when i am sending email from code

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You should use exact template to send out the email. Use XML ID of the email template. You can find it in purchase/data/mail_template_data.xml:

Use following code:

@api.multi
def send_mail(self, purchase_id):
    template = self.env.ref('purchase.email_template_edi_purchase')
    template.send_mail(purchase_id, force_send=True) # force_send will immediately send the email
    return True

Hope this will help you.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Ảnh đại diện
Huỷ bỏ
Tác giả

hi,

sudhir firstly thanks for the your response.

I tried your code still its send email like my screenshot in question,i need email like 2nd screenshot of my question

It is same email template as shown in 2nd screenshot. Make sure you don't have any customization for that template.

Tác giả

i msure there is no customization for template

below is new code

@api.multi

def send_mail(self,purchase_id):

email_template_obj = self.env['mail.template']

# template_ids = email_template_obj.search([('name','=','RFQ - Send by Email'),('model_id.model', '=', 'purchase.order')])

template_ids = self.env.ref('purchase.email_template_edi_purchase')

values={}

if template_ids:

email=self.env['mail.template'].browse(template_ids.id).send_mail(purchase_id,force_send=True)

return True

Câu trả lời hay nhất

I have similar problem did u solve this?

Ảnh đại diện
Huỷ bỏ