etq_exam_share.py
2.19 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
45
46
47
48
49
50
51
52
53
54
55
56
57
from odoo import models, fields, api
import logging
from odoo.http import request
# #
# import requests
# # from datetime import datetime
# # from openerp.tools import html_escape as escape, ustr, image_resize_and_sharpen, \
# # image_save_for_web
# # import unicodedata
# # import re
#
_logger = logging.getLogger(__name__)
class EtqExamShare(models.Model):
_name = "etq.exam.share"
_description = "etq.exam.share"
exam_id = fields.Many2one('etq.exam', string="Exam")
share_type = fields.Selection((('existing_contacts', 'Existing Contacts'),
('new_contacts', 'New Contacts')),
string="Share Option", required=True,
default="existing_contacts")
partner_ids = fields.Many2many('res.partner', string="Existing Contacts")
email_list = fields.Text(string="Email List")
# placeholder="Comma seperated emails")
email_subject = fields.Char(string="Email Subject", required=True)
email_content = fields.Html(string="Email Content", required=True,
sanitize=False)
@api.onchange('exam_id')
def _change_share(self):
notification_template = self.env['ir.model.data'].get_object(
'exam_test_quiz', 'exam_share_email')
for rec in self:
rec.email_subject = notification_template.subject
temp_content = notification_template.body_html
temp_content = temp_content.replace('__URL__',
request.httprequest.host_url + "exam/" + rec.exam_id.slug)
temp_content = temp_content.replace('__EXAM__', rec.exam_id.name)
rec.email_content = temp_content
# request.httprequest.host_url + "form/myinsert"
# @api.one
def share_exam(self):
for rec in self:
notification_template = self.env['ir.model.data'].get_object(
'exam_test_quiz', 'exam_share_email')
for cust in rec.partner_ids:
notification_template.subject = rec.email_subject
notification_template.body_html = rec.email_content
notification_template.send_mail(cust.id, True)