diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index d5e4c3af10c..2545dc484c1 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -47,7 +47,7 @@ user name and password for the invitation of the survey. 'wizard/survey_print_answer.xml', 'wizard/survey_browse_answer.xml', 'wizard/survey_print.xml', - 'wizard/survey_send_invitation.xml' + 'survey_send_invitation.xml' ], 'demo': ['survey_demo.xml'], 'test': [ @@ -59,6 +59,6 @@ user name and password for the invitation of the survey. 'installable': True, 'auto_install': False, 'images': ['images/survey_answers.jpeg','images/survey_pages.jpeg','images/surveys.jpeg'], - 'css': ['static/src/css/survey.css','static/css/survey.css'], + 'css': ['static/src/css/survey.css'], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/survey.py b/addons/survey/survey.py index be9003c805d..f0f20b54d2a 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -28,6 +28,7 @@ import os from openerp import netsvc, tools from openerp.osv import fields, osv from openerp.tools.translate import _ +import uuid # token = uuid.uuid4() class survey_type(osv.osv): _name = 'survey.type' @@ -151,12 +152,12 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) context.update({'active':False,'survey_id': ids[0]}) + return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', 'name': name, 'context': context } @@ -168,6 +169,8 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no pages defined. Please define pages first.')) context.update({'active':False,'survey_id': ids[0]}) + + context.update({'ir_actions_act_window_target': 'new'}) return { 'view_type': 'form', 'view_mode': 'form', @@ -186,6 +189,8 @@ class survey(osv.osv): if not pages: raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) context.update({'survey_id': ids[0]}) + + context.update({'ir_actions_act_window_target': 'new'}) return { 'view_type': 'form', 'view_mode': 'form', @@ -196,6 +201,41 @@ class survey(osv.osv): 'context': context } + def action_survey_sent(self, cr, uid, ids, context=None): + ''' + This function opens a window to compose an email, with the survey template message loaded by default + ''' + assert len(ids) == 1, 'This option should only be used for a single id at a time.' + ir_model_data = self.pool.get('ir.model.data') + try: + template_id = ir_model_data.get_object_reference(cr, uid, 'survey', 'email_template_survey')[1] + except ValueError: + template_id = False + try: + compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1] + except ValueError: + compose_form_id = False + ctx = dict(context) + + ctx.update({ + 'default_model': 'survey', + 'default_res_id': ids[0], + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_composition_mode': 'comment', + 'mark_invoice_as_sent': True, + }) + return { + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mail.compose.message', + 'views': [(compose_form_id, 'form')], + 'view_id': compose_form_id, + 'target': 'new', + 'context': ctx, + } + survey() class survey_history(osv.osv): @@ -249,7 +289,7 @@ class survey_page(osv.osv): 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - 'search_view_id': search_id[0], + #'search_view_id': search_id[0], 'context': context } @@ -526,7 +566,7 @@ class survey_question(osv.osv): 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'new', - 'search_view_id': search_id[0], + #'search_view_id': search_id[0], 'context': context } diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 53900b31df5..14d894335e5 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -321,7 +321,7 @@
diff --git a/addons/survey/wizard/__init__.py b/addons/survey/wizard/__init__.py index 0ea0e5cd424..2da1bfa616f 100644 --- a/addons/survey/wizard/__init__.py +++ b/addons/survey/wizard/__init__.py @@ -19,7 +19,6 @@ # ############################################################################## -import survey_send_invitation import survey_print_statistics import survey_print_answer import survey_browse_answer diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 6c3604e22c3..19b151e4999 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -41,10 +41,20 @@ class survey_question_wiz(osv.osv_memory): """ Fields View Get method :- generate the new view and display the survey pages of selected survey. """ + + print "" + print "" + print view_id, view_type, context, toolbar, submenu + print "" + print "" + + if not view_id and not context.get('survey_id', None) and context.get('default_survey_id', None): + context['survey_id'] = context['active_id'] = context.get('default_survey_id') + + if context is None: context = {} - result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \ - view_type, context, toolbar,submenu) + result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) surv_name_wiz = self.pool.get('survey.name.wiz') survey_obj = self.pool.get('survey') @@ -213,6 +223,7 @@ class survey_question_wiz(osv.osv_memory): ans_ids = que_rec.answer_choice_ids xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) + # TODO convert selection field into radio input if que_rec.type == 'multiple_choice_only_one_ans': selection = [] for ans in ans_ids: @@ -373,8 +384,9 @@ class survey_question_wiz(osv.osv_memory): else: etree.SubElement(xml_footer, 'label', {'string': ""}) etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"}) - etree.SubElement(xml_footer, 'label', {'string': "or"}) - etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) + if context.get('ir_actions_act_window_target', None): + etree.SubElement(xml_footer, 'label', {'string': "or"}) + etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':"Exit",'class':"oe_link"}) etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"}) root = xml_form.getroottree() @@ -1211,7 +1223,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', + 'target': context.get('ir_actions_act_window_target', None), 'search_view_id': search_id[0], 'context': context } @@ -1232,7 +1244,7 @@ class survey_question_wiz(osv.osv_memory): "view_mode": 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', - 'target': 'new', + 'target': context.get('ir_actions_act_window_target', None), 'search_view_id': search_id[0], 'context': context } diff --git a/addons/survey/wizard/survey_answer.xml b/addons/survey/wizard/survey_answer.xml index b02f9fb2be5..27d91d12642 100644 --- a/addons/survey/wizard/survey_answer.xml +++ b/addons/survey/wizard/survey_answer.xml @@ -33,5 +33,14 @@%s' % mail, - 'email_to': partner.email, - 'email_from': record['mail_from'], - } - self.pool.get('mail.mail').create(cr, uid, vals, context=context) - existing+= "- %s (Login: %s, Password: %s)\n" % (user.name, partner.email, \ - user.password) - continue - - passwd= self.genpasswd() - out+= partner.email + ',' + passwd + '\n' - mail= record['mail'] % {'login' : partner.email, 'passwd' : passwd, 'name' : partner.name} - if record['send_mail']: - vals = { - 'state': 'outgoing', - 'subject': record['mail_subject'], - 'body_html': '
%s' % mail, - 'email_to': partner.email, - 'email_from': record['mail_from'], - } - if attachments: - vals['attachment_ids'] = [(0,0,{'name': a_name, - 'datas_fname': a_name, - 'datas': str(a_content).encode('base64')}) - for a_name, a_content in attachments.items()] - ans = self.pool.get('mail.mail').create(cr, uid, vals, context=context) - if ans: - res_data = {'name': partner.name or _('Unknown'), - 'login': partner.email, - 'password': passwd, - 'address_id': partner.id, - 'groups_id': [[6, 0, [group_id]]], - 'action_id': act_id[0], - 'survey_id': [[6, 0, survey_ids]] - } - user = user_ref.create(cr, uid, res_data) - if user not in new_user: - new_user.append(user) - created+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ - partner.email, passwd) - else: - error+= "- %s (Login: %s, Password: %s)\n" % (partner.name or _('Unknown'),\ - partner.email, passwd) - - new_vals = {} - new_vals.update({'invited_user_ids':[[6,0,new_user]]}) - survey_ref.write(cr, uid, context.get('active_id'),new_vals) - note= "" - if created: - note += 'Created users:\n%s\n\n' % (created) - if existing: - note +='Already existing users:\n%s\n\n' % (existing) - if skipped: - note += "%d contacts where ignored (an email address is missing).\n\n" % (skipped) - if error: - note += 'Email not send successfully:\n====================\n%s\n' % (error) - context.update({'note' : note}) - return { - 'view_type': 'form', - "view_mode": 'form', - 'res_model': 'survey.send.invitation.log', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'context': context - } -survey_send_invitation() - -class survey_send_invitation_log(osv.osv_memory): - _name = 'survey.send.invitation.log' - _columns = { - 'note' : fields.text('Log', readonly=1) - } - - def default_get(self, cr, uid, fields_list, context=None): - if context is None: - context = {} - data = super(survey_send_invitation_log, self).default_get(cr, uid, fields_list, context) - data['note'] = context.get('note', '') - return data - -survey_send_invitation_log() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/wizard/survey_send_invitation.xml b/addons/survey/wizard/survey_send_invitation.xml index a611973d772..f2879990b9c 100644 --- a/addons/survey/wizard/survey_send_invitation.xml +++ b/addons/survey/wizard/survey_send_invitation.xml @@ -1,74 +1,28 @@
Hello,
++ Would you please spent some of your time to fill-in our survey: + ${object.title} +
+ % if object.responsible_id: +Thank you for choosing ${object.responsible_id.company_id.name or 'us'}!
+ % endif +