Odoo 发送邮件不起作用
Odoo Sending mail is not working
这是我的 Python 代码。单击按钮时会出现错误。帮我解决这个问题。
def send_quot_mail(self, cr, uid, ids,vals, context=None):
cur_obj=self.browse(cr, uid, ids, context=context)
stage = self.pool.get('crm.case.stage').browse(cr, uid, cur_obj.stage_id.id,context=context)
no_of_days=stage.days_to_move
end_date =datetime.datetime.now()+ relativedelta(days=no_of_days)
print end_date
mail_date=end_date.strftime('%d/%m/%Y')
vals.update({'qout_mail_date':mail_date})
mail_ids=[]
mail_pool = self.pool.get('mail.mail')
template_pool = self.pool.get('email.template')
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'email_template_crm_lead')[1]
mail_id = template_pool.send_mail(cr, uid, template_id, cur_obj.partner_id.id, context=context)
template_obj=self.pool.get('email.template').browse(cr, uid, template_id, context=context)
message_to_sent=template_obj.body_html
cur_obj=self.pool.get('res.users').browse(cr, uid, cur_obj.partner_id.id, context=context)
mail_pool.write(cr, uid, mail_id, {'email_to':cur_obj.partner_id.email,'body_html':message_to_sent}, context=context)
mail_ids.append(mail_id)
if mail_ids:
mail_pool.send(cr, uid, mail_ids, context=context)
return super(crm_lead, self).write(cr, uid, ids,vals, context=None)
这是我的邮件模板XML代码
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="email_template_crm_lead" model="email.template">
<field name="name">CRM Lead Opportunity Stage</field>
<field name="email_from">noreply@localhost</field>
<field name="subject">CRM Lead Opportunity Stage</field>
<field name="email_to"></field>
<field name="partner_to"></field>
<field name="model_id" ref="custom_crm.model_crm_lead"/>
<field name="body_html">
<![CDATA[
<div style="font-family: Verdana, Geneva, sans-serif; font-size: 13px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p></p>
</div>
]]>
</field>
</record>
</data>
</openerp>
当我点击按钮时出现错误
MissingError One of the documents you are trying to access has been
deleted, please try again after refreshing.
您试图通过引用获取错误的模板:
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'model_crm_lead')[1]
您的记录由 id(外部 id,xml id,...)email_template_crm_lead
定义。所以你必须得到这个id的模板:
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'email_template_crm_lead')[1]
编辑:
cur_obj=self.pool.get('res.users').browse(cr, uid, cur_obj.partner_id.id, context=context)
似乎是错误的,因为您正在尝试查找 ID 为合作伙伴 (res.partner) 的用户 (res.users)。这可能会产生一个匹配项(例如管理员的 id 3),但也可能在您报告的 MissingError 中结束。
实际上您经常使用 cur_obj.partner_id.id
。 cur_obj
从哪里来???
我通过从代码中删除以下行来做对了。我现在可以发邮件了。
cur_obj=self.pool.get('res.users').browse(cr, uid,
cur_obj.partner_id.id, context=context)
现在我没有收到错误
MissingError One of the documents you are trying to access has been
deleted, please try again after refreshing.
这是我的 Python 代码。单击按钮时会出现错误。帮我解决这个问题。
def send_quot_mail(self, cr, uid, ids,vals, context=None):
cur_obj=self.browse(cr, uid, ids, context=context)
stage = self.pool.get('crm.case.stage').browse(cr, uid, cur_obj.stage_id.id,context=context)
no_of_days=stage.days_to_move
end_date =datetime.datetime.now()+ relativedelta(days=no_of_days)
print end_date
mail_date=end_date.strftime('%d/%m/%Y')
vals.update({'qout_mail_date':mail_date})
mail_ids=[]
mail_pool = self.pool.get('mail.mail')
template_pool = self.pool.get('email.template')
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'email_template_crm_lead')[1]
mail_id = template_pool.send_mail(cr, uid, template_id, cur_obj.partner_id.id, context=context)
template_obj=self.pool.get('email.template').browse(cr, uid, template_id, context=context)
message_to_sent=template_obj.body_html
cur_obj=self.pool.get('res.users').browse(cr, uid, cur_obj.partner_id.id, context=context)
mail_pool.write(cr, uid, mail_id, {'email_to':cur_obj.partner_id.email,'body_html':message_to_sent}, context=context)
mail_ids.append(mail_id)
if mail_ids:
mail_pool.send(cr, uid, mail_ids, context=context)
return super(crm_lead, self).write(cr, uid, ids,vals, context=None)
这是我的邮件模板XML代码
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="email_template_crm_lead" model="email.template">
<field name="name">CRM Lead Opportunity Stage</field>
<field name="email_from">noreply@localhost</field>
<field name="subject">CRM Lead Opportunity Stage</field>
<field name="email_to"></field>
<field name="partner_to"></field>
<field name="model_id" ref="custom_crm.model_crm_lead"/>
<field name="body_html">
<![CDATA[
<div style="font-family: Verdana, Geneva, sans-serif; font-size: 13px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p></p>
</div>
]]>
</field>
</record>
</data>
</openerp>
当我点击按钮时出现错误
MissingError One of the documents you are trying to access has been deleted, please try again after refreshing.
您试图通过引用获取错误的模板:
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'model_crm_lead')[1]
您的记录由 id(外部 id,xml id,...)email_template_crm_lead
定义。所以你必须得到这个id的模板:
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'custom_crm', 'email_template_crm_lead')[1]
编辑:
cur_obj=self.pool.get('res.users').browse(cr, uid, cur_obj.partner_id.id, context=context)
似乎是错误的,因为您正在尝试查找 ID 为合作伙伴 (res.partner) 的用户 (res.users)。这可能会产生一个匹配项(例如管理员的 id 3),但也可能在您报告的 MissingError 中结束。
实际上您经常使用 cur_obj.partner_id.id
。 cur_obj
从哪里来???
我通过从代码中删除以下行来做对了。我现在可以发邮件了。
cur_obj=self.pool.get('res.users').browse(cr, uid, cur_obj.partner_id.id, context=context)
现在我没有收到错误
MissingError One of the documents you are trying to access has been deleted, please try again after refreshing.