Hi,
Python – Your Custom Wizard
from odoo import models, fields, api
class CustomMailWizard (models.TransientModel):
_inherit = 'mail.compose.message'
customer_id = fields.Many2one( 'res.partner' , string= 'Customer' )
recipient_email = fields.Char(string= 'Recipient Email' )
@api.multi
def get_mail_values ( self, res_ids ):
mail_values = super (CustomMailWizard, self).get_mail_values(res_ids)
for res_id in res_ids:
mail_value = mail_values[res_id]
# Override recipients
if self.recipient_email:
mail_value.update({
'email_to' : self.recipient_email, # send to this email directly
'partner_ids' : [( 5 , 0 , 0 )], # clear partner_ids
})
elif self.customer_id:
mail_value.update({
'partner_ids' : [( 4 , self.customer_id. id )], # fallback to partner
})
mail_values[res_id] = mail_value
return mail_values
How to Open the Wizard with Context
In your button action or code that launches the wizard, pass the fields through context:
return {
'type' : 'ir.actions.act_window' ,
'view_type' : 'form' ,
'view_mode' : 'form' ,
'res_model' : 'mail.compose.message' ,
'target' : 'new' ,
'context' : {
'default_model' : 'your.model' ,
'default_res_id' : self id ,
'default_customer_id' : self.customer_id. id ,
'default_recipient_email' : self.recipient_email,
'default_composition_mode' : 'comment' ,
# Optional subject/body
}
}
i hope it is use full