how to set a different message for an email templa

2019-05-24 12:36发布

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 ?

2条回答
贪生不怕死
2楼-- · 2019-05-24 12:42

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

查看更多
淡お忘
3楼-- · 2019-05-24 12:51

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})

查看更多
登录 后发表回答