diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 848652a587a..203c331460d 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -20,6 +20,8 @@ ############################################################################## import copy +from urllib import urlencode +from urlparse import urljoin from datetime import datetime from openerp.osv import fields, osv from openerp.tools.translate import _ @@ -64,6 +66,23 @@ class survey(osv.osv): res[id] = sur_res_obj.search(cr, uid, [('survey_id', '=', id), ('state', '=', 'done')], context=context, count=True) return res + def _get_public_url(self, cr, uid, ids, name, arg, context=None): + """ Compute if the message is unread by the current user. """ + res = dict((id, 0) for id in ids) + + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') + model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'survey', 'action_complete') + for id in ids: + query = { + 'db': cr.dbname + } + fragment = { + 'active_id': id, + 'action': model_id[1], + } + res[id] = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment))) + return res + _columns = { 'title': fields.char('Survey Title', size=128, required=1), 'page_ids': fields.one2many('survey.page', 'survey_id', 'Page'), @@ -81,6 +100,7 @@ class survey(osv.osv): 'type': fields.many2one('survey.type', 'Type'), 'color': fields.integer('Color Index'), 'response_ids': fields.one2many('survey.response', 'survey_id', 'Responses', readonly=1), + 'public_url': fields.function(_get_public_url, string="Public url", type="char"), } _defaults = { 'state': "draft", diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index d4283b4194e..5281a1bac38 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -47,7 +47,10 @@ - + + + + @@ -273,6 +276,8 @@ + +
diff --git a/addons/survey/wizard/survey_answer.xml b/addons/survey/wizard/survey_answer.xml index a0f5fa10482..fc29fa6563b 100644 --- a/addons/survey/wizard/survey_answer.xml +++ b/addons/survey/wizard/survey_answer.xml @@ -33,7 +33,7 @@ new - + ir.actions.act_window survey.question.wiz form diff --git a/addons/survey/wizard/survey_email_compose_message.py b/addons/survey/wizard/survey_email_compose_message.py index 3037cd7284b..26af901c2d7 100644 --- a/addons/survey/wizard/survey_email_compose_message.py +++ b/addons/survey/wizard/survey_email_compose_message.py @@ -20,8 +20,6 @@ ############################################################################## import re -from urllib import urlencode -from urlparse import urljoin from openerp.osv import osv from openerp.osv import fields from datetime import datetime @@ -57,12 +55,12 @@ class survey_mail_compose_message(osv.TransientModel): emails_split = re.compile(r"[;,\n\r]+") survey_response_obj = self.pool.get('survey.response') + survey_obj = self.pool.get('survey') partner_obj = self.pool.get('res.partner') mail_mail_obj = self.pool.get('mail.mail') mail_message_obj = self.pool.get('mail.message') - base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') - def create_response_and_send_mail(wizard, token, partner_id, email): + def create_response_and_send_mail(wizard, token, partner_id, email, public_url): """ Create one mail by recipients and replace __URL__ by link with identification token """ # create response with token @@ -77,23 +75,12 @@ class survey_mail_compose_message(osv.TransientModel): 'email': email, }) - # create url - query = { - 'db': cr.dbname - } - fragment = { - 'active_id': wizard.res_id, - 'params': token, - 'action': 'survey.action_answer_survey', - } - url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment))) - # post the message values = { 'model': 'survey', 'res_id': wizard.res_id or False, 'subject': wizard.subject, - 'body': wizard.body.replace("__URL__", url), + 'body': wizard.body.replace("__URL__", "%s¶ms=%s" % (public_url, token)), 'parent_id': None, 'partner_ids': partner_id and [(4, partner_id)] or None, 'notified_partner_ids': partner_id and [(4, partner_id)] or None, @@ -134,13 +121,16 @@ class survey_mail_compose_message(osv.TransientModel): if not len(emails_checked) and not len(wizard.partner_ids): raise osv.except_osv(_('Warning!'), _("Please enter at least one recipient.")) + publi_url = survey_obj.browse(cr, uid, wizard.res_id, context=context).public_url + for email in emails_checked: partner_id = partner_obj.search(cr, uid, [('email', '=', email)], context=context) partner_id = partner_id and partner_id[0] or None - create_response_and_send_mail(wizard, token, partner_id, email) token = create_token(wizard, partner_id, email) + create_response_and_send_mail(wizard, token, partner_id, email, publi_url) + for partner in wizard.partner_ids: token = create_token(wizard, partner.id, partner.email) - create_response_and_send_mail(wizard, token, partner.id, partner.email) + create_response_and_send_mail(wizard, token, partner.id, partner.email, publi_url) return {'type': 'ir.actions.act_window_close'}