how to set a different message for an email template in odoo?

江枫思渺然 提交于 2019-12-22 17:54:31

问题


I created a custom module and had used the calendar object to create an event and the code is as follows

def create_calender_event(self,cr,uid,ids,context=None):
    calendar_obj = self.pool.get('calendar.event')      
    for rec in self.browse(cr,uid,ids,context=context):
        if rec.action:
            for rec_res in rec.action:
                calendar_obj.create(cr,uid,{'name' : rec_res.act_ion,
                    'user_id' : rec_res.asgnd_to.id,
                    'start_date' : rec_res.due_date,
                    'stop_date' : rec_res.due_date,
                    'allday' : True,
                    'partner_ids' : [(6,0, [rec_res.asgnd_to.partner_id.id])]
                },context=context)

This will create a event in respective user's calendar, but it uses default template message.

How can i replace the calendar invitation template message by custom message ?


回答1:


you can do like this from py file

1) get the template_id and browse the object
2) the template body will be stored in 'body_html' field
3) store the body_html field in one variable, lets say: old_body
4) then add your customized code to template's 'body_html' field and write the values into template using the above temlate_id
5) send the mail, using send method
6) then write back the old_body value back to the template.

just for idea, refer this....

template_id = template_pool.search(cr,uid,[('name','=ilike',template_name)])
if template_id:
template_obj = template_pool.browse(cr, uid, template_id)
body = template_obj.body_html
body_old = body
count = 0

body += "

For %s Study Notes PDF Click here

"%(url['subject'],url['url'])
template_pool.write(cr, uid, template_id, {'body_html':body})
template_pool.send_mail(cr, uid, template_id[0], record.id)
template_pool.write(cr, uid, template_id, {'body_html': body_old})



回答2:


It's email template with xml id "calendar_template_meeting_invitation" is used to send invitation. So find this template and change to whatever you want. Under template its called "Meeting Invitation" email template.

OLD===================

UPDATES================================

on calendar.event object create and write method calls the method create_attendees which create all attendee and send email invitation by calling method _send_mail_to_attendees code ref, so you need to overload that function and remvoe that statement so it doesn't send email when attendee is created rather send invitation when you want.

Bests



来源:https://stackoverflow.com/questions/31446205/how-to-set-a-different-message-for-an-email-template-in-odoo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!