wiz_send_email.py
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class MailTemplate(models.Model):
_inherit = "mail.template"
def generate_email(self, res_ids, fields=None):
'''Method to generate email.'''
ret = super(MailTemplate, self).generate_email(res_ids, fields=fields)
if (self._context.get('body_html', False) or
self._context.get('subject', False) or
self._context.get('email_to', False)):
ret['body_html'] = self._context['body_text']
ret['subject'] = self._context['subject']
ret['email_to'] = self._context['email_to']
return ret
#
#
class SendMail(models.TransientModel):
"""Defining TransientModel to send mail."""
_name = "send.email"
_description = "Send Mail"
note = fields.Text('Text')
def send_email(self):
'''Method to send email.'''
body = ''
email_template_obj = self.env['mail.template']
# search the model student.student
template_id = email_template_obj.search([
('model', '=', 'student.student')],
limit=1)
if template_id:
for i in self:
body += '\n' + i.note
email_template_obj.send_mail(template_id.id,
self._context.get('active_id'),
force_send=True)
return {'type': 'ir.actions.act_window_close'}