Odoo Missing Error While Running A Cron Job For Sending Scheduled Mail
I have the following code. When the scheduler runs I am getting the error message. Some one help me to resolve the error in the code MissingError One of the documents you ar
Solution 1:
First of all write code using new api.
For getting template use obj = self.env.ref('template_record_id')
then send obj.send_mail(model.obj.id, force_send=True)
, if you want to set mail then before send obj.email_to = 'test@example.com'
Final code:
Somewhere in xml:
<recordid="email_template_record_id"model="email.template"><fieldname="name">Name</field><fieldname="email_from">noreply@example.com</field><fieldname="subject">Subject</field><fieldname="email_to">False</field><fieldname="auto_delete"eval="True"/><fieldname="model_id"ref="model_model_name"/><fieldname="body_html">
<![CDATA[
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Custom title</title>
</head>
<body>
<p>Dear Sir,</p>
<p>Text body.</p>
<p>This is automated mail, don't reply.</p>
</body>
</html>
]]>
</field></record>
in python code:
template = self.env.ref('email_template_record_id')
template.email_to = some_obj.obj_related_field.email
try:
template.send_mail(ombject_id, force_send=True)
except Exception:
_logger.error("Custom Error Message")
template.email_to = False
Solution 2:
This is the modified code and works fine
defsend_followup_mail(self, cr, uid, context=None):
quot_ids=self.search(cr, uid, [('state','=','amend_quote')])
for quot_id in quot_ids:
if quot_id:
quot_obj=self.browse(cr, uid, quot_id ,context=context)
quotation_since=quot_obj.quotation_since
for email_template_line in quot_obj.temp_tag_id.crm_campaign_id.email_template_ids:
if quotation_since==email_template_line.delay_days:
mail_pool = self.pool.get('mail.mail')
template_id = email_template_line.id
template_pool = self.pool.get('email.template')
sale_id=self.pool.get('sale.order').search(cr, uid, [], limit=1, context=context)
mail_id = template_pool.send_mail(cr, uid, template_id, sale_id[0], force_send=True, context=context)
if email_template_line.send_mail_to=='to_client':
mail_pool.write(cr, uid, mail_id, {'email_to':quot_obj.email_from}, context=context)
elif email_template_line.send_mail_to=='to_sale_rep':
mail_pool.write(cr, uid, mail_id, {'email_to':quot_obj.sale_rep_id.email}, context=context)
if mail_id:
mail_pool.send(cr, uid, mail_id, context=context)
self.write(cr, uid, quot_id,{'quotation_since':quotation_since+1}, context=None)
returnTrue
Post a Comment for "Odoo Missing Error While Running A Cron Job For Sending Scheduled Mail"