This question has been flagged
2449 Views

How to send an email by clicking a reject reason with the reject reason?

I want to send an email ,I have  a reject button by clicking that need a wizard for typing the reason and send email with the reason.

I have done like this, below shows the code :

@api.one
def reject_leave_manager(self):
if self.state == 'confirm':
       
context = {
'user_id': self.id
}
form_view = self.env.ref('leave_management_ft.view_message_form_leave_request')
return {'name': _('Reject Reason'),
'context': context,
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.mail',
# 'res_id': mail_id.id,
'views': [(form_view.id, 'form'), ],
'target': 'new'}

class MailToLeaveReject(models.Model):
_inherit = 'mail.mail'

body_msg = fields.Html()

def mail_leave_reject_reason(self):
context = self.env.context
asset_id = context['user_id']
asset_obj = self.env['hr.holidays'].browse(asset_id)
mail_values_refuse = {
# 'email_from': self.employee_id.work_email,
'email_to': asset_obj.employee_id.work_email,
'subject': 'Leave rejected ' ,
'body_html': 'Dear '+asset_obj.employee_id.name+',<br><br>Your request for '+ asset_obj.holiday_status_id.name+' from '
+asset_obj.from_date+' to '
+asset_obj.to_date+' has been rejected due to '
'the reason:'
+self.body_msg+'<br> Regards',
# 'notification': True,
}
mail = self.env['mail.mail'].create(mail_values_refuse)
mail.send()



This is the code I have written for getting the solution,but there there only changes the state to rejected,
Avatar
Discard

Is the reject_leave_manager function executed while submitting the reason? Inside the function there seems nothing other than changing the state. Please see this blog, which will show how to send email in button click: http://learnopenerp.blogspot.com/2017/08/odoo-how-to-send-email-on-button-click.html