Skip to Content
Menu
This question has been flagged

Actually I made it. But I have a problem . When I press Send An E-Mail Button first of all it was sending an email without attachment. After that the window opened and If I wish i can change the e mail template or something whatever you want.

Here is my .py code:

class ClassName(models.Model):
 _inherit = "project.task"
 def def_name(self):     
 self.ensure_one() 
 ir_model_data = self.env['ir.model.data']  
 try:     
 template_id = ir_model_data.get_object_reference('my_module_name', 'my_template_id')[1]
 except ValueError:     
 template_id = False      
 try:       
 compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1] 
 except ValueError:   
 compose_form_id = False  
 template = template_id and self.env['mail.template'].browse(template_id)    
 ctx = {      
 'default_model': 'project.task',  
 'default_res_id': self.ids[0],   
 'default_use_template': bool(template_id), 
 'default_template_id': template_id,       
 'default_composition_mode': 'comment',  
 'mark_so_as_sent': True,       
 'custom_layout': "mail.mail_notification_paynow",    
 'force_mail': True        }      
return {      
 'type': 'ir.actions.act_window',  
 'view_type': 'form',          
 'view_mode': 'form',       
 'res_model': 'mail.compose.message',   
 'views': [(compose_form_id, 'form')],   
 'view_id': compose_form_id,        
 'target': 'new',          
 'context': ctx,    
 }

Here is my view.xml

   <field name="model">project.task</field>   
 <field name="inherit_id" ref="project.view_task_form2"/>  
 <field name="arch" type="xml">          
 <!--Create Email-Send Button-->        
 <xpath expr ="//field[@name='stage_id']" position="before"> 
 <button name="def_name" type="object" string="Send An E-Mail"  class="oe_highlight"/>            </xpath>        </field>


And also I have template.xml there is a ref="attachment_id" in it. I think there is no problem in template.xml. My problem is I press the button it sends emails two times. One is with attachment one is not. Can someone help me ? By the way my code is similar to Sale order send mail. Thanks guys.

Avatar
Discard
Author Best Answer

I solved the problem. Odoo created another template and the action sends two mail each templates I deleted the other template. 

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 15
15787
0
Mar 15
2882
2
May 23
7715
0
Oct 24
2
1
May 24
332