Hi, I want to do how to attach wizard report's report automatically in mail, In that wizard i have two fields Date from and Date to, my concept is Date From to To Date to will send to particular user's mail, I have 2 buttons in wizard report one for Print another one for Send by mail, when click on the send to mail user can select the users and send, how to do it in OpenERP7. This is my following code.
def send_mail(self, cr, uid, ids, context=None):
email_template_obj = self.pool.get('email.template')
template_ids = email_template_obj.search(cr, uid, [('model_id.model', '=','quality.report.wizard')], context=context)
print template_ids,"%%%%%%%%%%%%%%%%%5"
if template_ids:
values = email_template_obj.generate_email(cr, uid, template_ids[0], ids, context=context)
print values,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`"
val = values.get('subject')
val1 = values.get('email_to')
val2 = values.get('body_html')
val3 = values.get('body_html')
val4 = values.get('attachments')
values['subject'] = val
values['email_to'] = val1
values['body_html'] = val2
values['body'] = val3
values['res_id'] = False
values['attachment_ids'] = val4
mail_mail_obj = self.pool.get('mail.mail')
print values,'$$$$$$$$$$$$$$$$$$$$$$$$'
msg_id = mail_mail_obj.create(cr, uid, values, context=context)
print msg_id,"/////////////////////////////////"
if msg_id:
mail_mail_obj.send(cr, uid, [msg_id], context=context)
return True
it is correct or need some changes, it make error.
Xml is
<record id="email_template_edi_quality" model="email.template">
<field name="name">Quality Report - Send by Email (Portalsssssss)</field>
<field name="email_from">sridharopenerptest@gmail.com</field>
<field name="subject">${(object.name or 'Sridhar')}</field>
<field name="email_recipients"></field>
<field name="model_id" ref="vv_quality.model_quality_control"/>
<field name="auto_delete" eval="True"/>
<field name="report_template" ref="quality_control_report"/>
<field name="report_name">${(object.name or 'NNNNNN')}</field>
<field name="lang"></field>
<field name="body_html"> Successs</field>
</record>
when i open this wizard or value only coming, object.name is not calling or empty why.
Related topic: http://help.openerp.com/question/16946/openerp-7-using-wizard-how-to-send-email-with-attachment/
In the wizard send email button to add in the code will send email with attachment.
In the above code have you received email?.. In your case the attachment document Is it available in the ir_attachment table?...
save your record in the ir_attachment and pass the attachment ID in the mail obj. (already the above code is working in the way). For example in the above code ir_attachment.create(cursor, uid, attachment_data, context=context) # Create date in ir_attachment with document
sorry currently i have not code. Your code looking correct make sure attachment table created. or testing purpose pass the attachment_ids directly into attachment_ids: [(6, 0, [1])]
when i composing mail there is no attachment then only send_mail function will call is it correct.
In the wizard send mail button clicked the send_mail function call. If attachment ids find it will send email with attachment otherwise send email without attachment
Prakash, i attached the report successfully, but when i click on the send_mail method it make error, how to fix it. result[message['id']] = self.pool.get(message['model']).name_get(cr, SUPERUSER_ID, [message['res_id']], context=context)[0][1] IndexError: list index out of range.
For testing purpose you add recipients details and other details manually and check have u receive email with attachment?...