【问题标题】:how to set a different message for an email template in odoo?如何在odoo中为电子邮件模板设置不同的消息?
【发布时间】:2015-08-24 15:39:06
【问题描述】:

我创建了一个自定义模块,并使用日历对象创建了一个事件,代码如下

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)

这将在相应用户的日历中创建一个事件,但它使用默认模板消息。

如何用自定义消息替换日历邀请模板消息?

【问题讨论】:

  • 如何在不影响用于日历活动邀请的原始电子邮件模板的情况下,仅为我的自定义模块替换模板消息?
  • 不错,没有人知道答案...大声笑

标签: odoo odoo-8 openerp-8


【解决方案1】:

你可以从 py 文件中这样做

1) 获取 template_id 并浏览对象
2) 模板正文将存储在“body_html”字段中
3) 将 body_html 字段存储在一个变量中,比如说:old_body
4)然后将您的自定义代码添加到模板的“body_html”字段,并使用上面的 temlate_id 将值写入模板
5) 发送邮件,使用 send 方法
6) 然后将 old_body 值写回模板。

仅供参考,参考这个....

template_id = template_pool.search(cr,uid,[('name','=ilike',template_name)])
如果模板 ID:
template_obj = template_pool.browse(cr, uid, template_id)
正文 = 模板_obj.body_html
body_old = 身体
计数 = 0

正文 += "

对于 %s 学习笔记 PDF 点击这里

"%(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': 身体旧})

【讨论】:

  • 谢谢 shravan,我也会尽快尝试你的想法……我正在处理另一个问题
  • Shravan 我需要传递任何模板 xml id 作为参数吗?函数头的外观以及函数的调用方式?
  • include template_pool = self.pool.get('email.template') 并且模板名称不是xml-id,只需传递模板名称
  • 是的 shravan,在它之前包含它,但错误是一样的
  • Shravan 我需要把它写在上面的函数中,对吧?
【解决方案2】:

它是带有 xml id "calendar_template_meeting_invitation" 的电子邮件模板,用于发送邀请。所以找到这个模板并更改为您想要的任何内容。在模板下,它被称为“会议邀请”电子邮件模板。

旧====================

更新================================

calendar.event 对象createwrite 方法上调用create_attendees 方法创建所有与会者并通过调用方法_send_mail_to_attendees code ref 发送电子邮件邀请,因此您需要重载该函数并删除它声明,因此它不会在创建与会者时发送电子邮件,而是在您需要时发送邀请。

最佳

【讨论】:

  • 谢谢萤火虫,是的,这样做会改变原始模板本身,我希望仅在执行上述代码时更改该模板..
  • 检查回复正文添加了更多详细信息
  • 感谢 Firebug 的回答,我会尝试的。
猜你喜欢
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多