[MERGE] Merging previous work in survey from trunk-surveyweb-rim \n (this new branch was created in order to solve merge problems from trunk-website-al)

bzr revid: rim@openerp.com-20140121084846-ftxpztroh6vqqcrm
This commit is contained in:
Richard Mathot (OpenERP)
2014-01-21 09:48:46 +01:00
90 changed files with 2899 additions and 73154 deletions
-1
View File
@@ -40,7 +40,6 @@ If you need to manage your meetings, you should install the CRM module.
'website': 'http://www.openerp.com',
'demo': ['calendar_demo.xml'],
'data': [
'security/calendar_security.xml',
'security/ir.model.access.csv',
'calendar_view.xml',
'contacts_view.xml',
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record model="res.groups" id="base.group_survey_user">
<field name="name">Survey / User</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>
@@ -1,7 +1,6 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_calendar_attendee,calendar.attendee,model_calendar_attendee,,1,1,1,1
access_calendar_alarm,calendar.alarm,model_calendar_alarm,base.group_user,1,1,1,1
access_calendar_attendee_survey_user,calendar.attendee,model_calendar_attendee,base.group_survey_user,1,0,0,0
access_calendar_event_manager,calendar.event.manager,model_calendar_event,base.group_sale_manager,1,1,1,1
access_calendar_event,calendar.event,model_calendar_event,base.group_sale_salesman,1,1,1,0
access_calendar_event_all,calendar.event_all,model_calendar_event,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_calendar_attendee calendar.attendee model_calendar_attendee 1 1 1 1
3 access_calendar_alarm calendar.alarm model_calendar_alarm base.group_user 1 1 1 1
access_calendar_attendee_survey_user calendar.attendee model_calendar_attendee base.group_survey_user 1 0 0 0
4 access_calendar_event_manager calendar.event.manager model_calendar_event base.group_sale_manager 1 1 1 1
5 access_calendar_event calendar.event model_calendar_event base.group_sale_salesman 1 1 1 0
6 access_calendar_event_all calendar.event_all model_calendar_event base.group_user 1 1 1 1
+1 -1
View File
@@ -20,7 +20,7 @@
##############################################################################
import survey
import controllers
import wizard
import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+28 -28
View File
@@ -21,44 +21,44 @@
{
'name': 'Survey',
'version': '1.0',
'category': 'Tools',
'version': '2.0',
'category': 'Marketing',
'description': """
This module is used for surveying.
==================================
Create beautiful web surveys and visualize answers
==================================================
It depends on the answers or reviews of some questions by different users. A
survey may have multiple pages. Each page may contain multiple questions and each
question may have multiple answers. Different users may give different answers of
question and according to that survey is done. Partners are also sent mails with
user name and password for the invitation of the survey.
survey may have multiple pages. Each page may contain multiple questions and
each question may have multiple answers. Different users may give different
answers of question and according to that survey is done. Partners are also
sent mails with personal token for the invitation of the survey.
""",
'summary': 'Create surveys, collect answers and print statistics',
'author': 'OpenERP SA',
'depends': ['mail'],
'website': 'https://www.openerp.com/apps/survey/',
'depends': ['email_template', 'mail', 'website'],
'data': [
'survey_report.xml',
'survey_data.xml',
'wizard/survey_selection.xml',
'wizard/survey_answer.xml',
'security/survey_security.xml',
'security/ir.model.access.csv',
'survey_view.xml',
'wizard/survey_print_statistics.xml',
'wizard/survey_print_answer.xml',
'wizard/survey_browse_answer.xml',
'wizard/survey_print.xml',
'wizard/survey_send_invitation.xml'
],
'demo': ['survey_demo.xml'],
'test': [
'test/draft2open2close_survey.yml',
'test/draft2open2close_request.yml',
'test/survey_question_type.yml',
'test/survey_report.yml',
'views/survey_views.xml',
'views/survey_templates.xml',
'wizard/survey_email_compose_message.xml',
'data/survey_cron.xml'
],
'demo': ['data/survey_demo_user.xml',
'data/survey_demo_recruitment.xml',
'data/survey_demo_feedback.xml',
'data/survey_demo_appraisal.xml'],
#'test': [
# 'test/survey_test.py',
#],
'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'],
'application': True,
'sequence': 10,
'images': [],
'css': ['static/src/css/survey.css'],
'js': ['static/src/js/survey.js'],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -2,13 +2,12 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,8 +19,6 @@
#
##############################################################################
import survey_analysis_report
import survey_form
import survey_browse_response
import main
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:
+298
View File
@@ -0,0 +1,298 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import SUPERUSER_ID
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT as DTF
from datetime import datetime
import werkzeug
import json
import logging
from openerp.addons.web import http
from openerp.addons.web.http import request
#from openerp.addons.website.models import website
from openerp.addons.website.controllers.main import Website as controllers
controllers = controllers()
_logger = logging.getLogger(__name__)
class WebsiteSurvey(http.Controller):
## HELPER METHODS ##
def _check_bad_cases(self, cr, uid, request, survey_obj, survey, user_input_obj, context=None):
# In case of bad survey, redirect to surveys list
if survey_obj.exists(cr, SUPERUSER_ID, survey.id, context=context) == []:
return werkzeug.utils.redirect("/survey/")
# In case of auth required, block public user
if survey.auth_required and uid == request.registry['website'].get_public_user(cr, uid, context):
return request.website.render("website.401")
# In case of non open surveys
if survey.state != 'open':
return request.website.render("survey.notopen")
# If enough surveys completed
if survey.user_input_limit > 0:
completed = user_input_obj.search(cr, uid, [('state', '=', 'done')], count=True)
if completed >= survey.user_input_limit:
return request.website.render("survey.notopen")
# Everything seems to be ok
return None
def _check_deadline(self, cr, uid, user_input, context=None):
'''Prevent opening of the survey if the deadline has turned out
! This will NOT disallow access to users who have already partially filled the survey !'''
if user_input.deadline:
dt_deadline = datetime.strptime(user_input.deadline, DTF)
dt_now = datetime.now()
if dt_now > dt_deadline: # survey is not open anymore
return request.website.render("survey.notopen")
return None
## ROUTES HANDLERS ##
# Survey list
@http.route(['/survey/',
'/survey/list/'],
type='http', auth='public', multilang=True, website=True)
def list_surveys(self, **post):
'''Lists all the public surveys'''
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
survey_ids = survey_obj.search(cr, uid, [('state', '=', 'open'),
('page_ids', '!=', 'None')],
context=context)
surveys = survey_obj.browse(cr, uid, survey_ids, context=context)
return request.website.render('survey.list', {'surveys': surveys})
# Survey start
@http.route(['/survey/start/<model("survey.survey"):survey>',
'/survey/start/<model("survey.survey"):survey>/<string:token>'],
type='http', auth='public', multilang=True, website=True)
def start_survey(self, survey, token=None, **post):
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
user_input_obj = request.registry['survey.user_input']
# Controls if the survey can be displayed
errpage = self._check_bad_cases(cr, uid, request, survey_obj, survey, user_input_obj, context=context)
if errpage:
return errpage
# Manual surveying
if not token:
if survey.visible_to_user:
user_input_id = user_input_obj.create(cr, uid, {'survey_id': survey.id})
user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
else: # An user cannot open hidden surveys without token
return request.website.render("website.403")
else:
try:
user_input_id = user_input_obj.search(cr, uid, [('token', '=', token)])[0]
except IndexError: # Invalid token
return request.website.render("website.403")
else:
user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
# Do not open expired survey
errpage = self._check_deadline(cr, uid, user_input, context=context)
if errpage:
return errpage
# Select the right page
if user_input.state == 'new': # Intro page
data = {'survey': survey, 'page': None, 'token': user_input.token}
return request.website.render('survey.survey_init', data)
else:
return request.redirect('/survey/fill/%s/%s' % (survey.id, user_input.token))
# Survey displaying
@http.route(['/survey/fill/<model("survey.survey"):survey>/<string:token>',
'/survey/fill/<model("survey.survey"):survey>/<string:token>/<string:prev>'],
type='http', auth='public', multilang=True, website=True)
def fill_survey(self, survey, token, prev=None, **post):
'''Display and validates a survey'''
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
user_input_obj = request.registry['survey.user_input']
# Controls if the survey can be displayed
errpage = self._check_bad_cases(cr, uid, request, survey_obj, survey, user_input_obj, context=context)
if errpage:
return errpage
# Load the user_input
try:
user_input_id = user_input_obj.search(cr, uid, [('token', '=', token)])[0]
except IndexError: # Invalid token
return request.website.render("website.403")
else:
user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0]
# Do not display expired survey (even if some pages have already been
# displayed -- There's a time for everything!)
errpage = self._check_deadline(cr, uid, user_input, context=context)
if errpage:
return errpage
# Select the right page
if user_input.state == 'new': # First page
page, page_nr, last = survey_obj.next_page(cr, uid, user_input, 0, go_back=False, context=context)
data = {'survey': survey, 'page': page, 'page_nr': page_nr, 'token': user_input.token}
if last:
data.update({'last': True})
return request.website.render('survey.survey', data)
elif user_input.state == 'done': # Display success message
return request.website.render('survey.sfinished', {'survey': survey,
'token': token})
elif user_input.state == 'skip':
flag = (True if prev and prev == 'prev' else False)
page, page_nr, last = survey_obj.next_page(cr, uid, user_input, user_input.last_displayed_page_id.id, go_back=flag, context=context)
data = {'survey': survey, 'page': page, 'page_nr': page_nr, 'token': user_input.token}
if last:
data.update({'last': True})
return request.website.render('survey.survey', data)
else:
return request.website.render("website.403")
# AJAX prefilling of a survey
@http.route(['/survey/prefill/<model("survey.survey"):survey>/<string:token>',
'/survey/prefill/<model("survey.survey"):survey>/<string:token>/<model("survey.page"):page>'],
type='http', auth='public', multilang=True, website=True)
def prefill(self, survey, token, page=None, **post):
cr, uid, context = request.cr, request.uid, request.context
user_input_line_obj = request.registry['survey.user_input_line']
ret = {}
# Fetch previous answers
if page:
ids = user_input_line_obj.search(cr, uid, [('user_input_id.token', '=', token), ('page_id', '=', page.id)], context=context)
else:
ids = user_input_line_obj.search(cr, uid, [('user_input_id.token', '=', token)], context=context)
previous_answers = user_input_line_obj.browse(cr, uid, ids, context=context)
# Return non empty answers in a JSON compatible format
for answer in previous_answers:
if not answer.skipped:
answer_tag = '%s_%s_%s' % (answer.survey_id.id, answer.page_id.id, answer.question_id.id)
answer_value = None
if answer.answer_type == 'free_text':
answer_value = answer.value_free_text
elif answer.answer_type == 'text':
answer_value = answer.value_text
elif answer.answer_type == 'number':
answer_value = answer.value_number.__str__()
elif answer.answer_type == 'date':
answer_value = answer.value_date
elif answer.answer_type == 'suggestion' and not answer.value_suggested_row:
answer_value = answer.value_suggested.id
elif answer.answer_type == 'suggestion' and answer.value_suggested_row:
answer_tag = "%s_%s" % (answer_tag, answer.value_suggested_row.id)
answer_value = answer.value_suggested.id
if answer_value:
dict_soft_update(ret, answer_tag, answer_value)
else:
_logger.warning("[survey] No answer has been found for question %s marked as non skipped" % answer_tag)
return json.dumps(ret)
# AJAX validation of some questions
# @http.route(['/survey/validate/<model("survey.survey"):survey>'],
# type='http', auth='public', multilang=True)
# def validate(self, survey, **post):
# AJAX submission of a page
@http.route(['/survey/submit/<model("survey.survey"):survey>'],
type='http', auth='public', multilang=True, website=True)
def submit(self, survey, **post):
_logger.debug('Incoming data: %s', post)
page_id = int(post['page_id'])
cr, uid, context = request.cr, request.uid, request.context
survey_obj = request.registry['survey.survey']
questions_obj = request.registry['survey.question']
questions_ids = questions_obj.search(cr, uid, [('page_id', '=', page_id)], context=context)
questions = questions_obj.browse(cr, uid, questions_ids, context=context)
# Answer validation
errors = {}
for question in questions:
answer_tag = "%s_%s_%s" % (survey.id, page_id, question.id)
errors.update(questions_obj.validate_question(cr, uid, question, post, answer_tag, context=context))
ret = {}
if (len(errors) != 0):
# Return errors messages to webpage
ret['errors'] = errors
else:
# Store answers into database
user_input_obj = request.registry['survey.user_input']
user_input_line_obj = request.registry['survey.user_input_line']
try:
user_input_id = user_input_obj.search(cr, uid, [('token', '=', post['token'])], context=context)[0]
except KeyError: # Invalid token
return request.website.render("website.403")
for question in questions:
answer_tag = "%s_%s_%s" % (survey.id, page_id, question.id)
user_input_line_obj.save_lines(cr, uid, user_input_id, question, post, answer_tag, context=context)
user_input = user_input_obj.browse(cr, uid, user_input_id, context=context)
go_back = post['button_submit'] == 'previous'
next_page, _, last = survey_obj.next_page(cr, uid, user_input, page_id, go_back=go_back, context=context)
vals = {'last_displayed_page_id': page_id}
if next_page is None and not go_back:
vals.update({'state': 'done'})
else:
vals.update({'state': 'skip'})
user_input_obj.write(cr, uid, user_input_id, vals, context=context)
ret['redirect'] = '/survey/fill/%s/%s' % (survey.id, post['token'])
if go_back:
ret['redirect'] += '/prev'
return json.dumps(ret)
# Printing routes
@http.route(['/survey/print/<model("survey.survey"):survey>/',
'/survey/print/<model("survey.survey"):survey>/<string:token>/'],
type='http', auth='user', multilang=True, website=True)
def print_survey(self, survey, token=None, **post):
'''Display an survey in printable view; if <token> is set, it will
grab the answers of the user_input_id that has <token>.'''
return request.website.render('survey.survey_print',
{'survey': survey,
'token': token,
'page_nr': 0})
def dict_soft_update(dictionary, key, value):
''' Insert the pair <key>: <value> into the <dictionary>. If <key> is
already present, this function will append <value> to the list of
existing data (instead of erasing it) '''
if key in dictionary:
dictionary[key].append(value)
else:
dictionary.update({key: [value]})
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Attendre les data de pbo
+ faire un script qui les traduit en record survey/page/question/label -->
</data>
</openerp>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<!-- Remove unused user inputs -->
<record forcecreate="True" id="ir_cron_clean_empty_surveys"
model="ir.cron">
<field name="name">Run Clean empty surveys</field>
<field name="active" eval="True"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'survey.user_input'"/>
<field name="function" eval="'do_clean_emptys'"/>
<field name="args" eval="'()'"/>
</record>
</data>
</openerp>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Appraisal form -->
<record model="survey.survey" id="appraisal_form">
<field name="title">Self Appraisal Form</field>
<field name="state">draft</field>
<field name="visible_to_user" eval="False"/>
<field name="users_can_go_back" eval="True" />
<field name="color" eval="4" />
<field name="description"> </field>
<field name="thank_you_message"> </field>
</record>
<record model="survey.page" id="appraisal_1">
<field name="title">Page1</field>
<field name="survey_id" ref="appraisal_form" />
<field name="sequence">1</field>
<field name="description"></field>
</record>
</data>
</openerp>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- User Feedback Form -->
<record model="survey.survey" id="feedback_form">
<field name="title">User Feedback Form</field>
<field name="state">draft</field>
<field name="visible_to_user" eval="True"/>
<field name="users_can_go_back" eval="True" />
<field name="color" eval="6" />
<field name="description"> </field>
<field name="thank_you_message"></field>
</record>
</data>
</openerp>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Recruitment Form -->
<record model="survey.survey" id="recruitment_form">
<field name="title">Recruitment Form</field>
<field name="state">draft</field>
<field name="visible_to_user" eval="False"/>
<field name="users_can_go_back" eval="False" />
<field name="color" eval="5" />
<field name="description"> </field>
<field name="thank_you_message"> </field>
</record>
</data>
</openerp>
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<!-- Grant survey permissions to demo user -->
<record id="base.user_demo" model="res.users">
<field eval="[(4, ref('base.group_survey_manager'))]" name="groups_id"/>
</record>
</data>
</openerp>
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,433 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import openerp
from openerp import tools
from openerp.report import report_sxw
from openerp.report.interface import report_rml
from openerp.tools import to_xml
class survey_analysis(report_rml):
def create(self, cr, uid, ids, datas, context):
registry = openerp.registry(cr.dbname)
surv_obj = registry['survey']
user_obj = registry['res.users']
rml_obj=report_sxw.rml_parse(cr, uid, surv_obj._name,context)
company=user_obj.browse(cr,uid,[uid],context)[0].company_id
rml ="""<document filename="Survey Analysis Report.pdf">
<template pageSize="(595.0,842.0)" title="Survey Analysis" author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20">
<pageTemplate>
<frame id="first" x1="1.3cm" y1="1.5cm" width="18.4cm" height="26.5cm"/>
<pageGraphics>
<fill color="black"/>
<stroke color="black"/>
<setFont name="DejaVuSans" size="8"/>
<drawString x="1.3cm" y="28.3cm"> """+to_xml(rml_obj.formatLang(time.strftime("%Y-%m-%d %H:%M:%S"),date_time=True))+"""</drawString>
<setFont name="DejaVuSans-Bold" size="10"/>
<drawString x="9.8cm" y="28.3cm">"""+ to_xml(company.name) +"""</drawString>
<stroke color="#000000"/>
<lines>1.3cm 28.1cm 20cm 28.1cm</lines>
</pageGraphics>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="Table1">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6"/>
</blockTableStyle>
<blockTableStyle id="Table2">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table3">
<blockAlignment value="LEFT"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table4">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table5">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table_heading">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table_head_2">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="answer_right" alignment="RIGHT" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="Standard1" fontName="Helvetica-Bold" alignment="RIGHT" fontSize="09.0"/>
<paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/>
<paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/>
<paraStyle name="response" fontName="Helvetica-Oblique" fontSize="9.5"/>
<paraStyle name="response-bold" fontName="Helvetica-Bold" fontSize="9" alignment="RIGHT" />
<paraStyle name="page" fontName="Helvetica" fontSize="11.0" leftIndent="0.0"/>
<paraStyle name="question" fontName="Helvetica-BoldOblique" fontSize="10.0" leftIndent="3.0"/>
<paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="answer" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="title" fontName="Helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/>
<paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_Center_heading" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
</stylesheet>
<images/>
"""
if datas.has_key('form') and datas['form']['survey_ids']:
ids = datas['form']['survey_ids']
for survey in surv_obj.browse(cr, uid, ids):
rml += """<story>
<para style="title">Answers Summary</para>
<para style="Standard"><font></font></para>
<para style="P2">
<font color="white"> </font>
</para>
<blockTable colWidths="280.0,100.0,120.0" style="Table_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Started Survey </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Completed Survey </para>
</td>
</tr>
</blockTable>
<blockTable colWidths="280.0,100.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_start_survey) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_comp_survey) + """</para>
</td>
</tr>
</blockTable>
<para style="P2">
<font color="white"> </font>
</para>"""
for page in survey.page_ids:
rml += """ <blockTable colWidths="500" style="Table4">
<tr>
<td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td>
</tr>
</blockTable>"""
for que in page.question_ids:
rml +="""<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td>
</tr>
</blockTable>"""
cols_widhts = []
if que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans']:
cols_widhts.append(200)
for col in range(0, len(que.column_heading_ids) + 1):
cols_widhts.append(float(300 / (len(que.column_heading_ids) + 1)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = [(0,'')]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id,col.title))
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in range(0, len(matrix_ans)):
rml+="""<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml += """<td><para style="response-bold">Answer Count</para></td>
</tr>"""
last_col = cols_widhts[-1]
for ans in que.answer_choice_ids:
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %s", (ans.id,))
tot_res = cr.fetchone()[0]
cr.execute("select count(id) ,sra.column_id from survey_response_answer sra where sra.answer_id=%s group by sra.column_id", (ans.id,))
calc_res = cr.dictfetchall()
for mat_col in range(1, len(matrix_ans)):
percantage = 0.0
cal_count = 0
for cal in calc_res:
if cal['column_id'] == matrix_ans[mat_col][0]:
cal_count = cal['count']
if tot_res:
percantage = round(float(cal_count)*100 / tot_res,2)
if percantage:
rml += """<td color="#FFF435"><para style="answer_bold">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>"""
else:
rml += """<td color="#FFF435"><para style="answer">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>"""
rml += """<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td>
</tr>"""
rml += """</blockTable>"""
if que.is_comment_require:
cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''",(que.id,))
tot_res = cr.fetchone()[0]
rml += """<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date','multiple_textboxes_diff_type']:
rml += """<blockTable colWidths="240.0,210,50.0" style="Table1">"""
rml += """ <tr>
<td> <para style="Standard"> </para></td>
<td> <para style="terp_default_Center_heading">Answer Percentage</para></td>
<td> <para style="response-bold">Answer Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
progress = ans.average * 7 / 100
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td>
<illustration>
<stroke color="lightslategray"/>
<rect x="0.1cm" y="-0.45cm" width="7.2 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/>
"""
if progress:
rml += """<fill color="lightsteelblue"/>
<rect x="0.2cm" y="-0.35cm" width='""" + tools.ustr(str(float(progress)) +'cm') + """' height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>"""
rml += """
<fill color="black"/>
<setFont name="Helvetica" size="9"/>
<drawString x="3.2cm" y="-0.30cm">""" + tools.ustr(ans.average) + """%</drawString></illustration>
</td>
<td><para style="answer_right">""" + tools.ustr(ans.response) + """</para></td></tr>"""
rml += """</blockTable>"""
if que.is_comment_require:
# if que.make_comment_field:
# cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,))
# tot_res = cr.fetchone()[0]
# tot_avg = 0.00
# if que.tot_resp:
# tot_avg = round(float(tot_res * 100)/ que.tot_resp,2)
# rml+="""<blockTable colWidths="280.0,120,100.0" style="Table1"><tr><td><para style="answer">""" +to_xml(tools.ustr(que.comment_label)) + """</para></td>
# <td><para style="answer">""" + str(tot_avg) + """%</para></td>
# <td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
# else:
cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,))
tot_res = cr.fetchone()[0]
rml += """<blockTable colWidths="450.0,50.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['single_textbox']:
cr.execute("select count(id) from survey_response_line where question_id = %s and single_text!=''",(que.id,))
rml += """<blockTable colWidths="400.0,100.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="response-bold">Answer Count</para></td>
</tr>
<tr><td><para style="answer"></para></td>
<td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr>
</blockTable>"""
elif que.type in['comment']:
cr.execute("select count(id) from survey_response_line where question_id = %s and comment !=''", (que.id,))
rml += """<blockTable colWidths="400.0,100.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="response-bold">Answer Count</para></td>
</tr>
<tr><td><para style="answer"></para></td>
<td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr>
</blockTable>"""
elif que.type in['rating_scale']:
cols_widhts.append(200)
for col in range(0,len(que.column_heading_ids) + 2):
cols_widhts.append(float(300 / (len(que.column_heading_ids) + 2)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = [(0,'')]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id,col.title))
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in range(0,len(matrix_ans)):
rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml += """<td><para style="response-bold">Rating Average</para></td>
<td><para style="response-bold">Answer Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
res_count = 0
rating_weight_sum = 0
for mat_col in range(1, len(matrix_ans)):
cr.execute("select count(sra.answer_id) from survey_response_line sr, survey_response_answer sra\
where sr.id = sra.response_id and sra.answer_id = %s and sra.column_id ='%s'", (ans.id,matrix_ans[mat_col][0]))
tot_res = cr.fetchone()[0]
cr.execute("select count(sra.answer_id),sqc.rating_weight from survey_response_line sr, survey_response_answer sra ,\
survey_question_column_heading sqc where sr.id = sra.response_id and \
sqc.question_id = sr.question_id and sra.answer_id = %s and sqc.title ='%s'\
+ group by sra.answer_id,sqc.rating_weight", (ans.id,matrix_ans[mat_col][1]))
col_weight = cr.fetchone()
if not col_weight:
col_weight= (0,0)
elif not col_weight[1]:
col_weight = (col_weight[0],0)
res_count = col_weight[0]
if tot_res and res_count:
rating_weight_sum += int(col_weight[1]) * tot_res
tot_per = round((float(tot_res) * 100) / int(res_count), 2)
else:
tot_per = 0.0
if tot_res:
rml += """<td><para style="answer_bold">""" + tools.ustr(tot_per) + "%(" + tools.ustr(tot_res) + """)</para></td>"""
else:
rml += """<td><para style="answer">""" + tools.ustr(tot_per)+"%(" + tools.ustr(tot_res) + """)</para></td>"""
percantage = 0.00
if res_count:
percantage = round((float(rating_weight_sum)/res_count), 2)
rml += """<td><para style="answer_right">""" + tools.ustr(percantage) + """</para></td>
<td><para style="answer_right">""" + tools.ustr(res_count) + """</para></td></tr>"""
rml += """</blockTable>"""
elif que.type in['matrix_of_drop_down_menus']:
for column in que.column_heading_ids:
rml += """<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(column.title)) + """</para></td></tr></blockTable>"""
menu_choices = column.menu_choice.split('\n')
cols_widhts = []
cols_widhts.append(200)
for col in range(0, len(menu_choices) + 1):
cols_widhts.append(float(300 / (len(menu_choices) + 1)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>
<td><para style="response"></para></td>"""
for menu in menu_choices:
rml += """<td><para style="response">""" + to_xml(tools.ustr(menu)) + """</para></td>"""
rml += """<td><para style="response-bold">Answer Count</para></td></tr>"""
cr.execute("select count(id), sra.answer_id from survey_response_answer sra \
where sra.column_id='%s' group by sra.answer_id ", (column.id,))
res_count = cr.dictfetchall()
cr.execute("select count(sra.id),sra.value_choice, sra.answer_id, sra.column_id from survey_response_answer sra \
where sra.column_id='%s' group by sra.value_choice ,sra.answer_id, sra.column_id", (column.id,))
calc_percantage = cr.dictfetchall()
for ans in que.answer_choice_ids:
rml += """<tr><td><para style="answer_right">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
for mat_col in range(0, len(menu_choices)):
calc = 0
response = 0
for res in res_count:
if res['answer_id'] == ans.id: response = res['count']
for per in calc_percantage:
if ans.id == per['answer_id'] and menu_choices[mat_col] == per['value_choice']:
calc = per['count']
percantage = 0.00
if calc and response:
percantage = round((float(calc)* 100) / response,2)
if calc:
rml += """<td><para style="answer_bold">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
else:
rml += """<td><para style="answer">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
response = 0
for res in res_count:
if res['answer_id'] == ans.id: response = res['count']
rml += """<td><para style="answer_right">""" + tools.ustr(response) + """</para></td></tr>"""
rml += """</blockTable>"""
elif que.type in['numerical_textboxes']:
rml += """<blockTable colWidths="240.0,20,100.0,70,70.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="Standard"> </para></td>
<td> <para style="response">Answer Average</para></td>
<td> <para style="response">Answer Total</para></td>
<td> <para style="response-bold">Answer Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
cr.execute("select answer from survey_response_answer where answer_id=%s group by answer", (ans.id,))
tot_res = cr.dictfetchall()
total = 0
for tot in tot_res:
total += int(tot['answer'])
per = 0.00
if len(tot_res):
per = round((float(total) / len(tot_res)),2)
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td> <para style="Standard"> </para></td>
<td> <para style="answer">""" + tools.ustr(per) +"""</para></td>
<td><para style="answer">""" + tools.ustr(total) + """</para></td>
<td><para style="answer_right">""" + tools.ustr(len(tot_res)) + """</para></td></tr>"""
rml+="""</blockTable>"""
rml +="""<blockTable colWidths="300,100,100.0" style="Table3">
<tr>
<td><para style="Standard1"></para></td>
<td><para style="Standard1">Answered Question</para></td>
<td><para style="Standard1">""" + tools.ustr(que.tot_resp) + """</para></td>
</tr>
<tr>
<td><para style="Standard1"></para></td>
<td><para style="Standard1">Skipped Question</para></td>
<td><para style="Standard1">""" + tools.ustr(survey.tot_start_survey - que.tot_resp) + """</para></td>
</tr>
</blockTable>"""
rml += """</story>"""
rml += """</document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
self.internal_header=True
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_analysis('report.survey.analysis', 'survey','','')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,542 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import openerp
from openerp import tools
from openerp.report import report_sxw
from openerp.report.interface import report_rml
from openerp.tools import to_xml
from openerp.tools.translate import _
class survey_browse_response(report_rml):
def create(self, cr, uid, ids, datas, context):
_divide_columns_for_matrix = 0.7
_display_ans_in_rows = 5
_pageSize = ('29.7cm','21.1cm')
registry = openerp.registry(cr.dbname)
if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('21.6cm','27.9cm')
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('21.6cm','35.6cm')
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('21.1cm','29.7cm')
elif datas.has_key('form') and datas['form'].get('orientation',False) == 'horizontal':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('27.9cm','21.6cm')
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('35.6cm','21.6cm')
elif datas['form'].get('paper_size') == 'a4':
_pageSize = ('29.7cm','21.1cm')
_frame_width = tools.ustr(_pageSize[0])
_frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm'
_tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm'
rml ="""<document filename="Survey Answer Report.pdf">
<template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Answer' author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20" >
<pageTemplate id="first">
<frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
<pageGraphics>
<lineMode width="1.0"/>
<lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+"""</lines>
<lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines>
<lines>"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>
<lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
if datas.has_key('form') and datas['form']['page_number']:
rml +="""
<fill color="gray"/>
<setFont name="Helvetica" size="10"/>
<drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">"""+_('Page : ')+"""<pageNumber/> </drawRightString>"""
rml +="""</pageGraphics>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="tbl_white">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="tbl_gainsboro">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="ans_tbl_white">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="ans_tbl_gainsboro">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="simple_table">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6"/>
</blockTableStyle>
<blockTableStyle id="note_table">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table2">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table3">
<blockAlignment value="LEFT"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table4">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table5">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table41">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table51">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="Table_heading">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="title_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<blockBackground colorName="black" start="0,0" stop="-1,-1"/>
<blockTextColor colorName="white" start="0,0" stop="0,0"/>
</blockTableStyle>
<blockTableStyle id="page_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
<blockTextColor colorName="white" start="0,0" stop="0,0"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="title" fontName="Helvetica-Bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
<paraStyle name="answer_right" alignment="RIGHT" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="Standard1" fontName="Helvetica-Bold" alignment="RIGHT" fontSize="09.0"/>
<paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/>
<paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/>
<paraStyle name="response" fontName="Helvetica-Oblique" fontSize="9.5"/>
<paraStyle name="page" fontName="Helvetica" fontSize="11.0" leftIndent="0.0"/>
<paraStyle name="question" fontName="Helvetica-BoldOblique" fontSize="10.0" leftIndent="3.0"/>
<paraStyle name="answer_Bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="answer" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="answer1" fontName="Helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="Title" fontName="Helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/>
<paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
<paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_default_9_Bold" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_tblheader_General_Centre_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_right_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_right" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="descriptive_text" fontName="Helvetica-Bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
<paraStyle name="descriptive_text_heading" fontName="Helvetica-Bold" fontSize="18.0" alignment="RIGHT" leftIndent="0.0" textColor="white"/>
</stylesheet>
<images/>
<story>"""
surv_resp_obj = registry['survey.response']
rml_obj=report_sxw.rml_parse(cr, uid, surv_resp_obj._name,context)
if datas.has_key('form') and datas['form'].has_key('response_ids'):
response_id = datas['form']['response_ids']
elif context.has_key('response_id') and context['response_id']:
response_id = [int(context['response_id'][0])]
else:
response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)])
surv_resp_line_obj = registry['survey.response.line']
surv_obj = registry['survey']
for response in surv_resp_obj.browse(cr, uid, response_id):
for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
tbl_width = float(_tbl_widths.replace('cm', ''))
colwidth = "2.5cm,4.8cm," + str(tbl_width - 15.0) +"cm,3.2cm,4.5cm"
resp_create = tools.ustr(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S')))
rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading">
<tr>
<td><para style="terp_default_9_Bold">""" + _('Print Date : ') + """</para></td>
<td><para style="terp_default_9">""" + to_xml(rml_obj.formatLang(time.strftime("%Y-%m-%d %H:%M:%S"),date_time=True)) + """</para></td>
<td><para style="terp_default_9"></para></td>
<td><para style="terp_default_9_Bold">""" +_('Answered by : ') + """</para></td>
<td><para style="terp_default_9">""" + to_xml(response.user_id.login or '') + """</para></td>
</tr>
<tr>
<td><para style="terp_default_9"></para></td>
<td><para style="terp_default_9"></para></td>
<td><para style="terp_default_9"></para></td>
<td><para style="terp_default_9_Bold">""" +_('Answer Date : ') + """</para></td>
<td><para style="terp_default_9">""" + to_xml(resp_create) + """</para></td>
</tr>
</blockTable><para style="P2"></para>"""
status = _("Not Finished")
if response.state == "done": status = _("Finished")
colwidth = str(tbl_width - 7) + "cm,"
colwidth += "7cm"
rml += """<blockTable colWidths='""" + str(colwidth) + """' style="title_tbl">
<tr>
<td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td>
<td><para style="descriptive_text_heading">"""+_('Status :- ')+ to_xml(tools.ustr(status)) + """</para><para style="P2"><font></font></para></td>
</tr>
</blockTable>"""
if survey.note:
rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table">
<tr><td><para style="response">""" + to_xml(tools.ustr(survey.note or '')) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
for page in survey.page_ids:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="page_tbl">
<tr><td><para style="page">"""+_('Page :- ') + to_xml(tools.ustr(page.title or '')) + """</para></td></tr>
</blockTable>"""
if page.note:
rml += """<para style="P2"></para>
<blockTable colWidths='""" + str(_tbl_widths) + """' style="note_table">
<tr><td><para style="response">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
</blockTable>"""
for que in page.question_ids:
rml += """<para style="P2"></para>
<blockTable colWidths='""" + str(_tbl_widths) + """' style="Table5">
<tr><td><para style="question">""" + to_xml(to_xml(que.question)) + """</para></td></tr>
</blockTable>"""
answer = surv_resp_line_obj.browse(cr ,uid, surv_resp_line_obj.search(cr, uid, [('question_id', '=', que.id),('response_id', '=', response.id)]))
if que.type in ['descriptive_text']:
rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
</blockTable>"""
elif que.type in ['table']:
if len(answer) and answer[0].state == "done":
col_heading = registry['survey.tbl.column.heading']
cols_widhts = []
tbl_width = float(_tbl_widths.replace('cm', ''))
for i in range(0, len(que.column_heading_ids)):
cols_widhts.append(tbl_width / float(len(que.column_heading_ids)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths + 'cm'
matrix_ans = []
rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
rml += """<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
rml += """</tr></blockTable>"""
i = 0
for row in range(0, que.no_of_rows):
if i%2 != 0:
style = 'tbl_white'
else:
style = 'tbl_gainsboro'
i +=1
rml += """<blockTable colWidths=" """ + str(colWidths) + """ " style='"""+style+"""'><tr>"""
table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id), ('name', '=', row)]))
for column in matrix_ans:
value = False
for col in table_data:
if column == col.column_id.title:
value = col.value
if value:
rml += """<td> <para style="terp_default_9">""" + to_xml(tools.ustr(value)) +"""</para></td>"""
else:
rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>"""
rml += """</tr></blockTable>"""
else:
rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">"""+ _('No Answer') + """</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
if len(answer) and answer[0].state == "done":
ans_list = []
for ans in answer[0].response_answer_ids:
ans_list.append(to_xml(tools.ustr(ans.answer_id.answer)))
answer_choice=[]
for ans in que['answer_choice_ids']:
answer_choice.append(to_xml(tools.ustr((ans.answer))))
def divide_list(lst, n):
return [lst[i::n] for i in range(n)]
divide_list = divide_list(answer_choice,_display_ans_in_rows)
for lst in divide_list:
if que.type == 'multiple_choice_multiple_ans':
if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)):
lst.append('')
if not lst:
del divide_list[divide_list.index(lst):]
for divide in divide_list:
a = _divide_columns_for_matrix * len(divide)
b = float(_tbl_widths.replace('cm', '')) - float(a)
cols_widhts = []
for div in range(0, len(divide)):
cols_widhts.append(float(a / len(divide)))
cols_widhts.append(float(b / len(divide)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths +'cm'
rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for div in range(0, len(divide)):
if divide[div] != '':
if que.type == 'multiple_choice_multiple_ans':
if divide[div] in ans_list:
rml += """<td><illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""<td><illustration>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/>
</illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
if divide[div] in ans_list:
rml += """<td><illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml += """<td>
<illustration>
<circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/>
</illustration>
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml += """<td></td><td></td>"""
rml += """</tr></blockTable>"""
if que.is_comment_require and answer[0].comment:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">No Answer</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']:
if len(answer) and answer[0].state == "done":
cols_widhts = []
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = tools.ustr(colWidths) + 'cm'
answer_list = {}
for ans in answer[0].response_answer_ids:
answer_list[ans.answer_id.answer] = ans.answer
for que_ans in que['answer_choice_ids']:
if que_ans.answer in answer_list:
rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr>
</blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response"></para></td></tr>
</blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Answer</para></td> </tr>
</blockTable>"""
elif que.type in ['single_textbox']:
if len(answer) and answer[0].state == "done":
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr>
</blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Answer</para></td> </tr>
</blockTable>"""
elif que.type in ['comment']:
if len(answer) and answer[0].state == "done":
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr>
</blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Answer</para></td> </tr>
</blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus']:
if len(answer) and answer[0].state == "done":
if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
pass
cols_widhts = []
if len(que.column_heading_ids):
cols_widhts.append(float(_tbl_widths.replace('cm','')) / float(2.0))
for col in que.column_heading_ids:
cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids)))
else:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
tmp = 0.0
sum = 0.0
i = 0
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
for col in cols_widhts:
if i == 0:
cols_widhts[i] = cols_widhts[i] / 2.0
tmp = cols_widhts[i]
sum += col
i += 1
cols_widhts.append(round(tmp, 2))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths + 'cm'
matrix_ans = [(0, ''),]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id, col.title))
len_matrix = len(matrix_ans)
if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
matrix_ans.append((0,que.column_name))
rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for mat_col in range(0, len(matrix_ans)):
rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml += """</tr>"""
rml += """</blockTable>"""
i = 0
for ans in que.answer_choice_ids:
if i%2 != 0:
style = 'ans_tbl_white'
else:
style = 'ans_tbl_gainsboro'
i += 1
rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
comment_value = ""
for mat_col in range(1, len_matrix):
value = """"""
for res_ans in answer[0].response_answer_ids:
if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]:
comment_value = to_xml(tools.ustr(res_ans.comment_field))
if que.type in ['matrix_of_drop_down_menus']:
value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
<fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration>
<fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration>"""
break
else:
if que.type in ['matrix_of_drop_down_menus']:
value = """"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
rml+= """<td>""" + value + """</td>"""
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
if comment_value == 'False':
comment_value = ''
rml += """<td><para style="response">""" + to_xml(tools.ustr(comment_value)) + """</para></td>"""
rml += """</tr></blockTable>"""
if que.is_comment_require:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>"""
else:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">No Answer</para></td> </tr>
</blockTable>"""
if datas.has_key('form') and not datas['form']['without_pagebreak']:
rml += """<pageBreak/>"""
elif not datas.has_key('form'):
rml += """<pageBreak/>"""
else:
rml += """<para style="P2"><font></font></para>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_browse_response('report.survey.browse.response', 'survey','','')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-397
View File
@@ -1,397 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import openerp
from openerp import tools
from openerp.report.interface import report_rml
from openerp.tools import to_xml
class survey_form(report_rml):
def create(self, cr, uid, ids, datas, context):
_divide_columns_for_matrix = 0.7
_display_ans_in_rows = 5
_pageSize = ('29.7cm','21.1cm')
if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('21.6cm','27.9cm')
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('21.6cm','35.6cm')
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('21.1cm','29.7cm')
elif datas.has_key('form') and datas['form'].get('orientation','') == 'horizontal':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('27.9cm','21.6cm')
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('35.6cm','21.6cm')
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('29.7cm','21.1cm')
_frame_width = tools.ustr(_pageSize[0])
_frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm'
_tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm'
rml="""<document filename="Survey Form.pdf">
<template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Form' author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20" >
<pageTemplate id="first">
<frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
<pageGraphics>
<lineMode width="1.0"/>
<lines>1.0cm """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) + 'cm' + """ """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) + 'cm' + """</lines>
<lines>1.0cm """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) +'cm'+ """ 1.0cm 1.00cm</lines>
<lines>""" + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm' + """ """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00)) + 'cm' + """ 1.00cm</lines>
<lines>1.0cm 1.00cm """ + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
if datas.has_key('form') and datas['form']['page_number']:
rml +="""
<fill color="gray"/>
<setFont name="Helvetica" size="10"/>
<drawRightString x='""" + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00)) + 'cm' + """' y="0.6cm">Page : <pageNumber/> </drawRightString>"""
rml +="""</pageGraphics>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="ans_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="tbl_white">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="tbl_gainsboro">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="ans_tbl_white">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="ans_tbl_gainsboro">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="page_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
<blockTextColor colorName="white" start="0,0" stop="0,0"/>
</blockTableStyle>
<blockTableStyle id="title_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<blockBackground colorName="black" start="0,0" stop="-1,-1"/>
<blockTextColor colorName="white" start="0,0" stop="0,0"/>
</blockTableStyle>
<blockTableStyle id="question_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
</blockTableStyle>
<blockTableStyle id="note_table">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="response" fontName="Helvetica-Oblique" fontSize="9.5"/>
<paraStyle name="page" fontName="Helvetica-Bold" fontSize="15.0" leftIndent="0.0" textColor="white"/>
<paraStyle name="title" fontName="Helvetica-Bold" fontSize="18.0" leading="15" leftIndent="0.0" textColor="white"/>
<paraStyle name="question" fontName="Helvetica-BoldOblique" fontSize="10.0" leftIndent="3.0"/>
<paraStyle name="answer" fontName="Helvetica" fontSize="09.0" leftIndent="0.0"/>
<paraStyle name="descriptive_text" fontName="Helvetica" fontSize="10.0" leftIndent="0.0"/>
<paraStyle name="answer_left" alignment="LEFT" fontName="Helvetica-Bold" fontSize="8.0" leftIndent="0.0"/>
<paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
<paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
</stylesheet>
<story>"""
surv_obj = openerp.registry(cr.dbname)['survey']
for survey in surv_obj.browse(cr,uid,ids):
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
<tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
if survey.note:
rml += """
<para style="P2"></para>
<blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
<tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(survey.note)) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
seq = 0
for page in survey.page_ids:
seq += 1
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
<tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
if page.note:
rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
<tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
</blockTable>"""
for que in page.question_ids:
cols_widhts = []
rml += """
<para style="P2"><font></font></para>
<blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
<tr><td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td></tr>
</blockTable>
<para style="P2"><font></font></para>"""
if que.type in ['descriptive_text']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths + 'cm'
rml += """
<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>
<td>
<para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para>
</td>
</tr>
</blockTable>"""
elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']:
answer = []
for ans in que.answer_choice_ids:
answer.append(to_xml(tools.ustr((ans.answer))))
def divide_list(lst, n):
return [lst[i::n] for i in range(n)]
divide_list = divide_list(answer,_display_ans_in_rows)
for lst in divide_list:
if que.type == 'multiple_choice_multiple_ans':
if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)):
lst.append('')
if not lst:
del divide_list[divide_list.index(lst):]
for divide in divide_list:
a = _divide_columns_for_matrix*len(divide)
b = float(_tbl_widths.replace('cm','')) - float(a)
cols_widhts = []
for div in range(0,len(divide)):
cols_widhts.append(float(a/len(divide)))
cols_widhts.append(float(b/len(divide)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths +'cm'
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>"""
for div in range(0,len(divide)):
if divide[div] != '':
if que.type == 'multiple_choice_multiple_ans':
rml += """
<td>
<illustration>
<rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/>
</illustration>
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml += """
<td>
<illustration>
<circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/>
</illustration>
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml += """
<td></td>
<td></td>"""
rml += """
</tr></blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']:
if len(que.column_heading_ids):
cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0))
for col in que.column_heading_ids:
cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids)))
else:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
tmp = 0.0
sum = 0.0
i = 0
if que.comment_column:
for col in cols_widhts:
if i == 0:
cols_widhts[i] = cols_widhts[i]/2.0
tmp = cols_widhts[i]
sum += col
i += 1
cols_widhts.append(round(tmp,2))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
matrix_ans = ['',]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
if que.comment_column:
matrix_ans.append(to_xml(tools.ustr(que.column_name)))
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"><tr>"""
for mat_col in matrix_ans:
rml += """<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml += """</tr></blockTable>"""
i = 0
for ans in que.answer_choice_ids:
if i%2 != 0:
style='ans_tbl_white'
else:
style='ans_tbl_gainsboro'
i += 1
rml += """
<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
rec_width = float((sum-tmp)*10+100)
value = ""
if que.type in ['matrix_of_drop_down_menus']:
value = """ <fill color="white"/>
<rect x="-0.1cm" y="-0.45cm" width='""" + tools.ustr(cols_widhts[-1] - 0.5) +"cm" + """' height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """ <fill color="white"/>
<circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>"""
else:
value = """ <fill color="white"/>
<rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
for mat_col in range(1,len(matrix_ans)):
if matrix_ans[mat_col] == que.column_name:
if mat_col == 1:
rml += """
<td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>"""
else:
rml += """<td></td>"""
else:
rml += """<td><illustration>""" + value + """</illustration></td>"""
rml += """</tr></blockTable>"""
elif que.type in ['multiple_textboxes', 'numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']:
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = tools.ustr(colWidths) + 'cm'
for ans in que.answer_choice_ids:
rml += """<para style="P1"></para>
<blockTable colWidths=" """+ colWidths + """ " style="ans_tbl">
<tr>
<td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td>
<illustration>
<rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(str(cols_widhts[0] - 0.3) + "cm") + """' height="0.6cm" fill="no" stroke="yes"/>
</illustration>
</td>
</tr>
</blockTable>"""
elif que.type in ['comment']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
rml += """<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
<tr>
<td><para style="comment"><font color="white"> </font></para>
<illustration>
<rect x="0.1cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.6) +'cm') + """' height="1.5cm" fill="no" stroke="yes"/>
</illustration>
</td>
</tr>
</blockTable>"""
elif que.type in ['single_textbox']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
rml += """<para style="P2"><font color="white"> </font></para>
<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
<tr>
<td>
<illustration>
<rect x="0.2cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.7) +'cm') + """' height="0.6cm" fill="no" stroke="yes"/>
</illustration>
</td>
</tr>
</blockTable>"""
elif que.type in ['table']:
tbl_width = float(_tbl_widths.replace('cm',''))
for i in range(0,len(que.column_heading_ids)):
cols_widhts.append(tbl_width/float(len(que.column_heading_ids)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
rml += """<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>"""
for col in que.column_heading_ids:
rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
rml += """</tr></blockTable>"""
i = 0
for r in range(0,que.no_of_rows):
if i%2 != 0:
style = 'tbl_white'
else:
style = 'tbl_gainsboro'
i += 1
rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>"""
for c in que.column_heading_ids:
rml += """
<td><para style="terp_default_9"><font color="white"> </font></para></td>"""
rml += """</tr></blockTable>"""
if datas.has_key('form') and not datas['form']['without_pagebreak']:
rml += """<pageBreak/>"""
elif not datas.has_key('form'):
rml += """<pageBreak/>"""
else:
rml += """<para style="P2"><font></font></para>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_form('report.survey.form', 'survey','','')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+19 -24
View File
@@ -1,24 +1,19 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_survey_type_manager,survey.type.manager,model_survey_type,base.group_tool_manager,1,1,1,1
access_survey_request_manager,survey.request manager,model_survey_request,base.group_tool_manager,1,1,1,1
access_survey_tbl_column_heading_manager,survey.tbl.column.heading manager,model_survey_tbl_column_heading,base.group_tool_manager,1,1,1,1
access_survey_res_partner_user,survey.res.partner.user,base.model_res_partner,base.group_tool_user,1,1,1,1
access_survey_user,survey.user,model_survey,base.group_tool_user,1,1,1,1
access_survey_page_user,survey.page user,model_survey_page,base.group_tool_user,1,1,1,1
access_survey_question_user,survey.question user,model_survey_question,base.group_tool_user,1,1,1,1
access_survey_answer_user,survey.answer user,model_survey_answer,base.group_tool_user,1,1,1,1
access_survey_response_user,survey.response user,model_survey_response,base.group_tool_user,1,1,1,1
access_survey_response_answer_user,survey.response.answer user,model_survey_response_answer,base.group_tool_user,1,1,1,1
access_survey_history_user,survey.history.user,model_survey_history,base.group_tool_user,1,1,1,1
access_survey_response_line_user,survey.response.line user,model_survey_response_line,base.group_tool_user,1,1,1,1
access_survey_res_partner_user,survey.res.partner.user,base.model_res_partner,base.group_tool_user,1,1,1,1
access_survey_survey_user,survey.survey.user,model_survey,base.group_survey_user,1,1,1,1
access_survey_page_survey_user,survey.page.survey.user,model_survey_page,base.group_survey_user,1,1,1,1
access_survey_question_survey_user,survey.question.survey.user,model_survey_question,base.group_survey_user,1,1,1,1
access_survey_answer_survey_user,survey.answer.survey.user,model_survey_answer,base.group_survey_user,1,1,1,1
access_survey_response_survey_user,survey.response.survey.user,model_survey_response,base.group_survey_user,1,1,1,1
access_survey_response_answer_survey_user,survey.response.answer.survey.user,model_survey_response_answer,base.group_survey_user,1,1,1,1
access_survey_history_survey_user,survey.history.survey.user,model_survey_history,base.group_survey_user,1,1,1,1
access_survey_response_line_survey_user,survey.response.line.survey.user,model_survey_response_line,base.group_survey_user,1,1,1,1
access_survey_question_column_heading_survey_user,survey.question.column.heading.survey.user,model_survey_question_column_heading,base.group_survey_user,1,0,0,0
access_survey_question_column_heading_user,survey.question.column.heading user,model_survey_question_column_heading,base.group_tool_user,1,1,1,1
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_survey_public,survey.survey public,model_survey_survey,base.group_public,1,0,0,0
access_survey_page_public,survey.page public,model_survey_page,base.group_public,1,0,0,0
access_survey_question_public,survey.question public,model_survey_question,base.group_public,1,0,0,0
access_survey_label_public,survey.label public,model_survey_label,base.group_public,1,0,0,0
access_survey_user_input_public,survey.user_input public,model_survey_user_input,base.group_public,1,1,1,0
access_survey_user_input_line_public,survey.user_input_line public,model_survey_user_input_line,base.group_public,1,1,1,0
access_survey_user,survey.survey user,model_survey_survey,base.group_survey_user,1,0,0,0
access_survey_page_user,survey.page user,model_survey_page,base.group_survey_user,1,0,0,0
access_survey_question_user,survey.question user,model_survey_question,base.group_survey_user,1,0,0,0
access_survey_label_user,survey.label user,model_survey_label,base.group_survey_user,1,0,0,0
access_survey_user_input_user,survey.user_input user,model_survey_user_input,base.group_survey_user,1,1,1,0
access_survey_user_input_line_user,survey.user_input_line user,model_survey_user_input_line,base.group_survey_user,1,1,1,0
access_survey_manager,survey.survey manager,model_survey_survey,base.group_survey_manager,1,1,1,1
access_survey_page_manager,survey.page manager,model_survey_page,base.group_survey_manager,1,1,1,1
access_survey_question_manager,survey.question manager,model_survey_question,base.group_survey_manager,1,1,1,1
access_survey_label_manager,survey.label manager,model_survey_label,base.group_survey_manager,1,1,1,1
access_survey_user_input_manager,survey.user_input manager,model_survey_user_input,base.group_survey_manager,1,1,1,1
access_survey_user_input_line_manager,survey.user_input_line manager,model_survey_user_input_line,base.group_survey_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_survey_type_manager access_survey_public survey.type.manager survey.survey public model_survey_type model_survey_survey base.group_tool_manager base.group_public 1 1 0 1 0 1 0
3 access_survey_request_manager access_survey_page_public survey.request manager survey.page public model_survey_request model_survey_page base.group_tool_manager base.group_public 1 1 0 1 0 1 0
4 access_survey_tbl_column_heading_manager access_survey_question_public survey.tbl.column.heading manager survey.question public model_survey_tbl_column_heading model_survey_question base.group_tool_manager base.group_public 1 1 0 1 0 1 0
5 access_survey_res_partner_user access_survey_label_public survey.res.partner.user survey.label public base.model_res_partner model_survey_label base.group_tool_user base.group_public 1 1 0 1 0 1 0
6 access_survey_user access_survey_user_input_public survey.user survey.user_input public model_survey model_survey_user_input base.group_tool_user base.group_public 1 1 1 1 0
7 access_survey_page_user access_survey_user_input_line_public survey.page user survey.user_input_line public model_survey_page model_survey_user_input_line base.group_tool_user base.group_public 1 1 1 1 0
8 access_survey_question_user access_survey_user survey.question user survey.survey user model_survey_question model_survey_survey base.group_tool_user base.group_survey_user 1 1 0 1 0 1 0
9 access_survey_answer_user access_survey_page_user survey.answer user survey.page user model_survey_answer model_survey_page base.group_tool_user base.group_survey_user 1 1 0 1 0 1 0
10 access_survey_response_user access_survey_question_user survey.response user survey.question user model_survey_response model_survey_question base.group_tool_user base.group_survey_user 1 1 0 1 0 1 0
11 access_survey_response_answer_user access_survey_label_user survey.response.answer user survey.label user model_survey_response_answer model_survey_label base.group_tool_user base.group_survey_user 1 1 0 1 0 1 0
12 access_survey_history_user access_survey_user_input_user survey.history.user survey.user_input user model_survey_history model_survey_user_input base.group_tool_user base.group_survey_user 1 1 1 1 0
13 access_survey_response_line_user access_survey_user_input_line_user survey.response.line user survey.user_input_line user model_survey_response_line model_survey_user_input_line base.group_tool_user base.group_survey_user 1 1 1 1 0
14 access_survey_res_partner_user access_survey_manager survey.res.partner.user survey.survey manager base.model_res_partner model_survey_survey base.group_tool_user base.group_survey_manager 1 1 1 1
15 access_survey_survey_user access_survey_page_manager survey.survey.user survey.page manager model_survey model_survey_page base.group_survey_user base.group_survey_manager 1 1 1 1
16 access_survey_page_survey_user access_survey_question_manager survey.page.survey.user survey.question manager model_survey_page model_survey_question base.group_survey_user base.group_survey_manager 1 1 1 1
17 access_survey_question_survey_user access_survey_label_manager survey.question.survey.user survey.label manager model_survey_question model_survey_label base.group_survey_user base.group_survey_manager 1 1 1 1
18 access_survey_answer_survey_user access_survey_user_input_manager survey.answer.survey.user survey.user_input manager model_survey_answer model_survey_user_input base.group_survey_user base.group_survey_manager 1 1 1 1
19 access_survey_response_survey_user access_survey_user_input_line_manager survey.response.survey.user survey.user_input_line manager model_survey_response model_survey_user_input_line base.group_survey_user base.group_survey_manager 1 1 1 1
access_survey_response_answer_survey_user survey.response.answer.survey.user model_survey_response_answer base.group_survey_user 1 1 1 1
access_survey_history_survey_user survey.history.survey.user model_survey_history base.group_survey_user 1 1 1 1
access_survey_response_line_survey_user survey.response.line.survey.user model_survey_response_line base.group_survey_user 1 1 1 1
access_survey_question_column_heading_survey_user survey.question.column.heading.survey.user model_survey_question_column_heading base.group_survey_user 1 0 0 0
access_survey_question_column_heading_user survey.question.column.heading user model_survey_question_column_heading base.group_tool_user 1 1 1 1
+76 -11
View File
@@ -1,19 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record model="res.groups" id="base.group_tool_user">
<field name="name">User</field>
<field name="category_id" ref="base.module_category_tools"/>
</record>
<record model="res.groups" id="base.group_tool_manager">
<field name="name">Manager</field>
<field name="category_id" ref="base.module_category_tools"/>
<field name="implied_ids" eval="[(4, ref('base.group_tool_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<data>
<!-- Survey users -->
<record model="res.groups" id="base.group_survey_user">
<field name="name">Survey / User</field>
</record>
<!-- Survey managers -->
<record model="res.groups" id="base.group_survey_manager">
<field name="name">Survey / Manager</field>
<field name="implied_ids" eval="[(4, ref('base.group_survey_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<!-- Record rules -->
<record id="survey_public_access" model="ir.rule">
<field name="name">Public access to surveys</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="domain_force">[('state', '=', 'open'), ('auth_required', '=', False)]</field>
<field name="groups" eval="[(4, ref('base.group_public'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>
<record id="survey_rule" model="ir.rule">
<field name="name">Access to survey for regular users</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="domain_force">[('state', '=', 'open'), ('visible_to_user', '=', True)]</field>
<field name="groups" eval="[(4, ref('base.group_survey_user'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>
<record id="survey_rule_manager" model="ir.rule">
<field name="name">Survey Manager access rights</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('base.group_survey_manager'))]"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>
<record id="survey_public_access" model="ir.rule">
<field name="name">Public access to user_input</field>
<field name="model_id" ref="survey.model_survey_user_input"/>
<field name="domain_force">[('create_uid', '=', 'uid')]</field>
<field name="groups" eval="[(4, ref('base.group_public'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>
<record id="survey_rule" model="ir.rule">
<field name="name">Access to user_input for regular users</field>
<field name="model_id" ref="survey.model_survey_user_input"/>
<field name="domain_force">[('create_uid', '=', 'uid')]</field>
<field name="groups" eval="[(4, ref('base.group_survey_user'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>
<record id="survey_rule_manager" model="ir.rule">
<field name="name">Survey Manager access rights</field>
<field name="model_id" ref="survey.model_survey_user_input"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('base.group_survey_manager'))]"/>
<field eval="1" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>
</data>
</openerp>
@@ -1,157 +0,0 @@
Date : 8th October, 2009
Created by : Harshad Modi(hmo) and Yogesh(ysa)
--------------------------------------------------------------------------------------
**** Specification of Survay module in OpenERP ****
Basic Requirements :
======================================================================================
> Design own survey form
> Desing own Questionaries
> Collect Response
> Analyze Result
Design own survey form:
---------------------------------------------------------------
Allow to make multiple own survey pages with multiple questions with different question type.
Note : After finish first Phase of Development, Allow to design page template to specify customize theme for bgcolor, bgimage, font style, font color
Design Questinaries :
-------------------------------------------------------
Questinaries should has :
* can specify question text
* can make Answer sheet
Question Type:
* Survey Admin can able to design answer option like:
- Mutiple Choice with one answer
- Mutilpe Choice with multiple answer
Collect Response :
---------------------------------------------------------
Survey Admin can able to :
- Create a link
- Send a survey invitation to others peple by mail
- Allow to set max limit of Response
- Survey Admin can able to close survey
Analyze Result :
----------------------------------------------------------
- Show Result with all Survey pages with total responses, responce count and calculate avarage response.
OpenERP model Design :
====================================================================
survey :
-------------------------------------------
title - char(128)
pages_ids - one2many(survey_page)
date_open
date_close
survey_link
max_response_limit
status (draft, open, close, cancel)
resposible - many2one (res.user)
survey_page:
-------------------------------------------------------------------
title - char(128)
page_template_id - many2one( survey_page_template)
survey_id - many2one(survey)
question_ids - one2many(survey_question)
sequence - int
note - char(256)
survey_question:
--------------------------------------------------------------
page_id - many2one(survey_page)
question - char(128)
answer_choice_ids - one2many(survey_answer)
response_ids - one2many(survey_response)
is_require_answer
allow_comment
sequence - int
survey_answer:
--------------------------------------------------------------------------
question_id - many2one(survey_question)
answer - char(128)
sequence - int
survey_response:
--------------------------------------------------------------------
date_create
date_modify
status (done, skip)
response_by - many2one(res.users)
question_id - many2one(survey_question)
response_type ( from manual, link, mail)
response_answer_ids - one2many(survey_response_answer)
survey_response_answer:
--------------------------------------------------------------------
response_id - many2one(survey_response)
question_id - many2one(survey_answer)
comment
OpenERP View Design:
==================================================
Survey View :
see survey.png file
Survey Pages View:
see survey_page.png file
Survey Question View:
see survey_qyestion.png file
Survey Response View :
see survey_response.png file
OpenERP Report Design :
===================================================
Design postgres view to display statistical information of response per question, response per user, etc..
More detail will be provided later.
OpenERP Menu Design :
=====================================================
Survey Management :
> Surveys
> All Surveys
> New Survey
> Survey Pages
> All Survey Pages
> New Survey Page
> Survey Response
> All Survey Responses
> New Survey Response
> Reports
> Response per Survey
> Response per Survey Page
> Response per Question
> Response per User
References :
===============================================
http://www.surveymonkey.com/
Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

+34 -2
View File
@@ -6,8 +6,40 @@
}
.openerp .oe_kanban_survey {
/* Customize height and width according bootstrap3 */
width: 212px;
min-height: 86px !important;
/* End of customize */
}
.openerp .oe_kanban_survey .oe_kanban_survey_list{
width: 100%;
}
.openerp .oe_kanban_survey .oe_kanban_status,
.openerp .oe_kanban_survey .oe_kanban_status_green,
.openerp .oe_kanban_survey .oe_kanban_status_salmon,
.openerp .oe_kanban_survey .oe_kanban_status_red {
display: block;
height: 10px;
width: 10px;
background-color: #dddddd;
border-radius: 5px;
margin-top: 3px;
}
.openerp .oe_kanban_survey .oe_kanban_status_green {
background-color: green;
}
.openerp .oe_kanban_survey .oe_kanban_status_salmon {
background-color: salmon;
}
.openerp .oe_kanban_survey .oe_kanban_status_red {
background-color: red;
}
.openerp .oe_kanban_survey .oe_inactive {
color: #aaaaaa;
}
.openerp .oe_kanban_survey .oe_stats_box {
width: 96px;
display: inline-block;
margin: 2px 2px 0px 0px;
text-align: center;
border: 1px solid rgba(0, 0, 0, 0.16);
}
+128
View File
@@ -0,0 +1,128 @@
/*
* OpenERP, Open Source Management Solution
* Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$(document).ready(function () {
'use strict';
console.debug("[survey] Custom JS for survey is loading...");
var the_form = $('.js_surveyform');
var prefill_controller = the_form.attr("data-prefill");
var validate_controller = the_form.attr("data-validate");
var submit_controller = the_form.attr("data-submit");
// Printing mode: will disable all the controls in the form
if (_.isUndefined(submit_controller)) {
$('.js_surveyform :input').prop('disabled', true);
}
// Custom code for right behavior of radio buttons with comments box
$('.js_comments>input[type="text"]').focusin(function(){
$(this).prev().find('>input').attr("checked","checked");
});
$('.js_radio input[type="radio"][data-oe-survey-otherr!="1"]').click(function(){
$(this).closest('.js_radio').find('.js_comments>input[type="text"]').val("");
});
$('.js_comments input[type="radio"]').click(function(){
$(this).closest('.js_comments').find('>input[data-oe-survey-othert="1"]').focus();
});
// Custom code for right behavior of dropdown menu with comments
$('.js_drop input[data-oe-survey-othert="1"]').hide();
$('.js_drop select').change(function(){
var other_val = $(this).find('.js_other_option').val();
if($(this).val() === other_val){
$(this).parent().removeClass('col-md-12').addClass('col-md-6');
$(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').show().focus();
}
else{
$(this).parent().removeClass('col-md-6').addClass('col-md-12');
$(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').val("").hide();
}
});
// Custom code for right behavior of checkboxes with comments box
$('.js_ck_comments>input[type="text"]').focusin(function(){
$(this).prev().find('>input').attr("checked","checked");
});
$('.js_ck_comments input[type="checkbox"]').change(function(){
if (! $(this).prop("checked")){
$(this).closest('.js_ck_comments').find('input[type="text"]').val("");
}
});
// Pre-filling of the form with previous answers
function prefill(){
var prefill_def = $.ajax(prefill_controller, {dataType: "json"})
.done(function(json_data){
_.each(json_data, function(value, key){
the_form.find(".form-control[name=" + key + "]").val(value);
the_form.find("input[name^=" + key + "]").each(function(){
$(this).val(value);
});
});
})
.fail(function(){
console.warn("[survey] Unable to load prefill data");
});
return prefill_def;
};
// function validate(form){
// return false;
// }
// Parameters for form submission
$('.js_surveyform').ajaxForm({
url: submit_controller,
type: 'POST', // submission type
dataType: 'json', // answer expected type
beforeSubmit: function(){ // hide previous errmsg before resubmitting
$('.js_errzone').html("").hide();
},
success: function(response, status, xhr, wfe){ // submission attempt
if(_.has(response, 'errors')){ // some questions have errors
_.each(_.keys(response.errors), function(key){
$("#" + key + '>.js_errzone').append('<p>' + response.errors[key] + '</p>').show();
});
return false;
}
else if (_.has(response, 'redirect')){ // form is ok
window.location.replace(response.redirect);
return true;
}
else { // server sends bad data
console.error("Incorrect answer sent by server");
return false;
}
},
timeout: 5000,
error: function(jqXHR, textStatus, errorThrown){ // failure of AJAX request
$('#AJAXErrorModal').modal('show');
}
});
// Handles the event when a question is focused out
$('.js_question-wrapper').focusout(
function(){
console.debug("[survey] Focus lost on question " + $(this).attr("id"));
});
console.debug("[survey] Custom JS for survey loaded!");
// Launch prefilling
prefill();
});
+804 -638
View File
File diff suppressed because it is too large Load Diff
-17
View File
@@ -1,17 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="survey.type" id="survey_type1">
<field name="name">Human Resources</field>
<field name="code">Human Resources</field>
</record>
<record model="survey.type" id="survey_type2">
<field name="name">Customer Feeback</field>
<field name="code">Customer Feeback</field>
</record>
<record model="survey.type" id="survey_type3">
<field name="name">Supplier Selection</field>
<field name="code">Supplier Selection</field>
</record>
</data>
</openerp>
File diff suppressed because it is too large Load Diff
-25
View File
@@ -1,25 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<report auto="False"
id="report_survey_form"
model="survey"
name="survey.form"
string="Survey"/>
<report auto="True"
id="survey_analysis"
model="survey"
name="survey.analysis"
rml=""
string="Survey Statistics"/>
<report auto="True"
id="survey_browse_response"
model="survey"
name="survey.browse.response"
rml=""
string="Survey Answers"/>
</data>
</openerp>
File diff suppressed because it is too large Load Diff
@@ -1,50 +0,0 @@
-
In order to check Survey Request of the survey "Initial Partner Feedback" I create a Survey Request for survey "Initial Partner Feedback".
-
!record {model: survey.request, id: survey_request_1}:
survey_id: survey_Initial_partner_feedback
user_id: base.user_demo
-
!assert {model: survey.request, id: survey_request_1, string: Survey Request should be in draft state}:
- state == 'draft'
-
I set Survey Request for the survey in waiting state.
-
!python {model: survey.request}: |
self.survey_req_waiting_answer(cr, uid, [ref("survey_request_1")], context)
-
I check that state of Survey Request for the survey is waiting or not.
-
!assert {model: survey.request, id: survey_request_1, severity: error, string: Survey Request should be in waiting state}:
- state == 'waiting_answer'
-
I cancel the Survey Request of the survey.
-
!python {model: survey.request}: |
self.survey_req_cancel(cr, uid, [ref("survey_request_1")], context)
-
I check that state of Survey Request of the survey is cancel or not.
-
!assert {model: survey.request, id: survey_request_1, severity: error, string: Survey Request should be in cancel state}:
- state == 'cancel'
-
I set Survey Request of the survey in draft state.
-
!python {model: survey.request}: |
self.survey_req_draft(cr, uid, [ref("survey_request_1")], context)
-
I check that state of Survey request of the survey is draft or not.
-
!assert {model: survey.request, id: survey_request_1, severity: error, string: Survey Request should be in draft state}:
- state == 'draft'
-
I set survey request of the survey in done state.
-
!python {model: survey.request}: |
self.survey_req_waiting_answer(cr, uid, [ref("survey_request_1")], context)
self.survey_req_done(cr, uid, [ref("survey_request_1")], context)
-
I check that state of Survey request of the survey is done or not.
-
!assert {model: survey.request, id: survey_request_1, severity: error, string: Survey Request should be in done state}:
- state == 'done'
@@ -1,111 +0,0 @@
-
In order to check the survey module in OpenERP I use the survey "Initial Partner Feedback".
-
I set the survey in Open state.
-
!python {model: survey}: |
sur = self.survey_open(cr, uid, [ref("survey_Initial_partner_feedback")], context)
-
I check state of survey is open or not.
-
!assert {model: survey, id: survey_Initial_partner_feedback, severity: error, string: Survey should be in open state}:
- state == 'open'
-
I check that the survey is reopened or not.
-
!python {model: survey}: |
self.survey_cancel(cr, uid, [ref('survey_Initial_partner_feedback')],context)
self.survey_open(cr, uid, [ref('survey_Initial_partner_feedback')],context)
-
I check that state of survey is open or not.
-
!assert {model: survey, id: survey_Initial_partner_feedback, severity: error, string: Survey should be in open state}:
- state == 'open'
-
I set the state of the survey open.
-
!python {model: survey}: |
sur = self.survey_open(cr, uid, [ref("survey_Initial_partner_feedback")], context)
-
In order to print the survey I click on Print.
-
!python {model: survey.print}: |
id = self.create(cr, uid, {'survey_ids': [(6,0,[ref('survey.survey_Initial_partner_feedback')])]})
self.action_next(cr, uid, [id], context)
-
In order to answer the survey I click on "Answer a Survey" wizard.
-
!python {model: survey.name.wiz}: |
id = self.create(cr, uid, {'survey_id': ref("survey_Initial_partner_feedback")})
self.action_next(cr, uid, [id], context)
-
I give the answer of the first and second page of the survey.
-
!python {model: survey.question.wiz}: |
ctx = {'active_model':'survey', 'active_id': ref('survey_Initial_partner_feedback'), 'active_ids': [ref('survey_Initial_partner_feedback')]}
self.fields_view_get(cr, uid, ref("survey.view_survey_question_message"),"form", context=ctx)
values = self.default_get(cr, uid, ['name'], ctx)
id = self.create(cr, uid, {str(ref("survey_initial_question_company_name")) +"_single" :'Tiny' , str(ref("survey_initial_question_company_size")) + "_selection" : int(ref("survey.survey_initial_question_company_size_51")), }, context)
self.action_next(cr, uid, [id], context)
id = self.create(cr, uid, {str(ref("survey_initial_question_contract_customers")) + "_selection" : int(ref("survey_initial_answer_sometimes")), str(ref("survey_initial_question_sell_to_your_customers")) + "_selection" : int(ref("survey_initial_answer_maintenance_contract")), }, context)
self.action_next(cr, uid, [id], context)
-
I print the answers of the survey.
-
!python {model: survey.browse.answer}: |
id = self.create(cr, uid, {'survey_id': ref('survey.survey_Initial_partner_feedback')})
self.action_next(cr, uid, [id], context)
-
I edit questions of the survey as per requirement.
-
!python {model: survey.question.wiz}: |
name_wiz_obj = self.pool.get('survey.name.wiz')
id = name_wiz_obj.create(cr, uid, {'survey_id': ref("survey_Initial_partner_feedback")})
ctx = {'active_model':'survey', 'active_id': ref('survey_Initial_partner_feedback'), 'active_ids': [ref('survey_Initial_partner_feedback')], 'question_id': ref('survey_initial_question_company_name'), 'page_number': -1,'sur_name_id': id}
self.action_edit_question(cr, uid, [ref('survey_initial_question_company_name')], context = ctx)
self.action_delete_question(cr, uid, [ref('survey_initial_question_company_name')], context = ctx)
self.action_new_question(cr, uid, [], context = ctx)
-
I edit Page of the survey as per requirement.
-
!python {model: survey.question.wiz}: |
name_wiz_obj = self.pool.get('survey.name.wiz')
id = name_wiz_obj.create(cr, uid, {'survey_id': ref("survey_Initial_partner_feedback")})
ctx = {'active_model':'survey', 'active_id': ref('survey_Initial_partner_feedback'), 'active_ids': [ref('survey_Initial_partner_feedback')], 'page_id': ref('survey_initial_page_Contracts'), 'sur_name_id': id}
self.action_edit_page(cr, uid, [ref('survey_initial_page_Contracts')], context = ctx)
self.action_delete_page(cr, uid, [ref('survey_initial_page_Contracts')], context = ctx)
self.action_new_page(cr, uid, [], context = ctx)
-
In order to send invitation to the users I click on "Send Invitation" wizard.
-
!python {model: survey.send.invitation}: |
context = {'active_model':'survey', 'active_id': ref('survey_Initial_partner_feedback'), 'active_ids': [ref('survey_Initial_partner_feedback')]}
values = self.default_get(cr, uid, ['mail_from', 'mail_subject', 'send_mail_existing', 'mail_subject_existing', 'mail', 'partner_ids', 'send_mail'], context)
values['mail_from'] = 'Surveyor'
new_id = self.create(cr, uid, values)
self.action_send(cr, uid, [new_id], context)
-
I set the value in "Total start survey" field.
-
!record {model: survey, id: survey_Initial_partner_feedback}:
tot_start_survey: 1
-
I set the survey in Cancel state.
-
!python {model: survey}: |
self.survey_cancel(cr, uid, [ref("survey_Initial_partner_feedback")], context)
-
I check state of survey is cancel or not.
-
!assert {model: survey, id: survey_Initial_partner_feedback, severity: error, string: Survey should be in cancel state}:
- state == 'cancel'
-
I set the survey in close state.
-
!python {model: survey}: |
self.survey_close(cr, uid, [ref("survey_Initial_partner_feedback")], context)
-
I check state of Survey is close or not.
-
!assert {model: survey, id: survey_Initial_partner_feedback, severity: error, string: Survey should be in close state}:
- state == 'close'
@@ -1,6 +0,0 @@
-
I check the question type of the survey "Initial Partner Feedback".
-
!python {model: survey.question}: |
sur_question = self.on_change_type(cr, uid, [ref("survey_Initial_partner_feedback")], 'multiple_textboxes_diff_type')
assert sur_question
-26
View File
@@ -1,26 +0,0 @@
-
I print the Survey Browse Response Report through the wizard.
-
!python {model: survey}: |
ctx = {'model': 'survey','active_ids': [(6,0,[ref('survey_partner_feedback')])]}
data_dict = {'response_ids' : [(6,0,[ref('survey.survey_partner_feedback')])], 'page_number' : True, 'without_pagebreak': True}
from openerp.tools import test_reports
test_reports.try_report_action(cr, uid, 'action_view_survey_print_answer',wiz_data=data_dict, context=ctx, our_module='survey')
-
I print the Survey Analysis Report through the wizard.
-
!python {model: survey}: |
ctx = {'model': 'survey','active_ids': [(6,0,[ref('survey_partner_feedback')])]}
data_dict = {'survey_ids' : [(6,0,[ref('survey.survey_partner_feedback')])]}
from openerp.tools import test_reports
test_reports.try_report_action(cr, uid, 'action_view_survey_print_statistics',wiz_data=data_dict, context=ctx, our_module='survey')
-
I print the Survey Form Report through the wizard.
-
!python {model: survey}: |
ctx = {'model': 'survey','active_ids': [(6,0,[ref('survey_partner_feedback')])]}
data_dict = {'survey_ids' : [(6,0,[ref('survey.survey_partner_feedback')])], 'page_number' : True, 'without_pagebreak': True}
from openerp.tools import test_reports
test_reports.try_report_action(cr, uid, 'action_view_survey_print',wiz_data=data_dict, context=ctx, our_module='survey')
+118
View File
@@ -0,0 +1,118 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2012-TODAY OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv.orm import except_orm
from openerp.tools import mute_logger
from time import time
class test_survey():
# def setUp(self):
# cr, uid = self.cr, self.uid
# # Usefull models
# self.ir_model = self.registry('ir.model')
# self.ir_model_data = self.registry('ir.model.data')
# self.obj_survey = self.registry('survey.survey')
# self.obj_survey_response = self.registry('survey.response')
# self.obj_survey_question_wiz = self.registry('survey.question.wiz')
# self.obj_survey_print = self.registry('survey.print')
# self.survey_id = self.obj_survey.create(cr, uid, {
# 'title': 'Initial Partner Feedback',
# 'max_response_limit': 20,
# 'type': ref("survey_type2"),
# 'state': 'draft',
# 'authenticate': 0,
# 'date_open': time.strftime('%Y-%m-%d %H:%M:%S')
# })
# self.survey_browse = self.obj_survey.browse(cr, uid, self.survey_id, context)
#@mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm')
# def test_00_survey_public(self):
# cr, uid = self.cr, self.uid
# # In order to check the survey module in OpenERP I use the survey "Initial Partner Feedback".
# # I set the survey in Open state.
# self.obj_survey.survey_open(cr, uid, [self.survey_id], context)
# # I check state of survey is open or not.
# self.assertEqual(self.survey_browse.state, 'open', 'Survey should be in open state')
# # I check that the survey is reopened or not.
# self.obj_survey.survey_cancel(cr, uid, [self.survey_id], context)
# self.obj_survey.survey_open(cr, uid, [self.survey_id], context)
# self.assertEqual(self.survey_browse.state, 'open', 'Survey should be in open state again')
# # I set the state of the survey open.
# self.obj_survey.survey_open(cr, uid, [self.survey_id], context)
# # In order to print the survey I click on Print.
# id = self.obj_survey_print.create(cr, uid, {'survey_ids': [(6, 0, [self.survey_id])]})
# self.obj_survey_print.action_next(cr, uid, [id], context)
# # In order to answer the survey I click on "Answer a Survey" with a public token.
# ctx = {}
# ctx.update({'survey_id': self.survey_id, 'survey_token': self.survey_browse.token})
# fields_view = self.obj_survey_question_wiz.fields_view_get(self, cr, uid, view_id=None, view_type='form', context=ctx)
# id = self.obj_survey_question_wiz.create(cr, uid, {}, ctx)
# self.obj_survey_question_wiz.action_next(cr, uid, [id], ctx)
# # I give the answer of the first and second page of the survey.
# #ctx = {'active_model':'survey.survey', 'active_id': self.survey_id, 'active_ids': [self.survey_id]}
# self.obj_survey_question_wiz.fields_view_get(cr, uid, ref("survey.view_survey_question_message"),"form", context=ctx)
# values = self.obj_survey_question_wiz.default_get(cr, uid, ['name'], ctx)
# id = self.obj_survey_question_wiz.create(cr, uid, {str(ref("survey_initial_question_company_name")) +"_single" :'Tiny' , str(ref("survey_initial_question_company_size")) + "_selection" : int(ref("survey.survey_initial_question_company_size_51")), }, context)
# self.obj_survey_question_wiz.action_next(cr, uid, [id], context)
# id = self.obj_survey_question_wiz.create(cr, uid, {str(ref("survey_initial_question_contract_customers")) + "_selection" : int(ref("survey_initial_answer_sometimes")), str(ref("survey_initial_question_sell_to_your_customers")) + "_selection" : int(ref("survey_initial_answer_maintenance_contract")), }, context)
# self.obj_survey_question_wiz.action_next(cr, uid, [id], context)
# # I edit questions of the survey as per requirement.
# id = self.obj_survey_name_wiz.create(cr, uid, {'survey_id': self.survey_id})
# ctx.update({'question_id': ref('survey_initial_question_company_name'), 'page_number': -1, 'sur_name_id': id})
# self.obj_survey_question_wiz.action_edit_question(cr, uid, [ref('survey_initial_question_company_name')], context=ctx)
# self.obj_survey_question_wiz.action_delete_question(cr, uid, [ref('survey_initial_question_company_name')], context=ctx)
# self.obj_survey_question_wiz.action_new_question(cr, uid, [], context=ctx)
# # I edit Page of the survey as per requirement.
# id = self.obj_survey_name_wiz.create(cr, uid, {'survey_id': self.survey_id})
# ctx.update({'page_id': ref('survey_initial_page_Contracts'), 'sur_name_id': id})
# self.obj_survey_question_wiz.action_edit_page(cr, uid, [ref('survey_initial_page_Contracts')], context=ctx)
# self.obj_survey_question_wiz.action_delete_page(cr, uid, [ref('survey_initial_page_Contracts')], context=ctx)
# self.obj_survey_question_wiz.action_new_page(cr, uid, [], context=ctx)
# # In order to send invitation to the users I click on "Send Invitation" wizard.
# # I set the survey in Cancel state.
# self.obj_survey.survey_cancel(cr, uid, [self.survey_id], context)
# # I check state of survey is cancel or not.
# self.assertEqual(self.survey_browse.state, 'cancel', 'Survey should be in cancel state')
# # I set the survey in close state.
# self.obj_survey.survey_close(cr, uid, [self.survey_id], context)
# # I check state of Survey is close or not.
# self.assertEqual(self.survey_browse.state, 'close', 'Survey should be in cancel state')
# # sur_question = self.on_change_type(cr, uid, [ref("survey_Initial_partner_feedback")], 'multiple_textboxes_diff_type')
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:
+292
View File
@@ -0,0 +1,292 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- List of all the surveys -->
<template id="list" name="Survey List">
<t t-call="website.layout">
<div class="wrap">
<div class="container">
<h1>Open surveys</h1>
<div class="table-responsive">
<table class="table table-hover">
<tr><th>Title</th></tr>
<t t-foreach="surveys" t-as="survey">
<tr>
<td><a t-att-href="survey.public_url" t-field="survey.title" /></td>
</tr>
</t>
</table>
</div>
</div>
</div>
</t>
</template>
<!-- "Thank you" message when the survey is completed -->
<template id="sfinished" name="Survey Finished">
<t t-call="website.layout">
<div class="wrap">
<div class="container">
<div class="jumbotron mt32">
<h1>Thank you!</h1>
<div t-field="survey.thank_you_message" />
<div>If you wish, you can <a t-att-href="'/survey/print/%s/%s' % (survey.id, token)">print your answers</a>.</div>
</div>
</div>
</div>
</t>
</template>
<!-- Message when the survey is not open -->
<template id="notopen" name="Survey not open">
<t t-call="website.layout">
<div class="wrap">
<div class="container">
<div class="jumbotron mt32">
<h1>Not open</h1>
<p>This survey is not open. Thank you for your interest!</p>
</div>
</div>
</div>
</t>
</template>
<!-- First page of a survey -->
<template id="survey_init" name="Survey">
<t t-call="website.layout">
<div class="wrap">
<div class="oe_structure" />
<div class="container">
<div class='jumbotron mt32'>
<h1 t-field='survey.title' />
<div t-field='survey.description' />
<a class="btn btn-primary btn-lg" t-att-href="'/survey/fill/%s/%s' % (survey.id, token)">
Start Survey
</a>
</div>
</div>
<div class="oe_structure" />
</div>
</t>
</template>
<!-- A survey -->
<template id="survey" name="Survey">
<t t-call="website.layout">
<t t-set="head">
<script type="text/javascript" src="/survey/static/src/js/survey.js" />
</t>
<div class="wrap">
<div class="oe_structure"/>
<div class="container">
<t t-call="survey.page" />
</div>
<div class="oe_structure"/>
</div>
</t>
</template>
<!-- A page -->
<template id="page" name="Page">
<div class="page-header">
<p class="pull-right">Page <span t-raw='page_nr + 1'/> on <span t-raw="len(survey.page_ids)"/></p>
<h1 t-field='page.title' />
<div t-field='page.description'/>
</div>
<form role="form" method="post" class="js_surveyform" t-att-name="'%s_%s' % (survey.id, page.id)" t-att-action="'/survey/fill/%s/%s' % (survey.id, token)" t-att-data-prefill="'/survey/prefill/%s/%s/%s' % (survey.id, token, page.id)" t-att-data-validate="'/survey/validate/%s' % (survey.id)" t-att-data-submit="'/survey/submit/%s' % (survey.id)">
<input type="hidden" name="page_id" t-att-value="page.id" />
<input type="hidden" name="token" t-att-value="token" />
<t t-foreach='page.question_ids' t-as='question'>
<t t-set="prefix" t-value="'%s_%s_%s' % (survey.id, page.id, question.id)" />
<div class="js_question-wrapper" t-att-id="prefix">
<h2>
<span t-field='question.question' />
<span t-if="question.constr_mandatory" class="text-danger">*</span>
</h2>
<p class="text-muted"><t t-if="question.description"><span t-field='question.description'/></t></p>
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
<t t-if="question.type == 'datetime'"><t t-call="survey.datetime"/></t>
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
<div class="js_errzone alert alert-danger" style="display:none;"></div>
</div>
</t>
<div class="text-center mt16 mb16">
<button t-if="survey.users_can_go_back and page_nr > 0" type="submit" class="btn btn-default" name="button_submit" value="previous">Previous page</button>
<button t-if="not last" type="submit" class="btn btn-primary" name="button_submit" value="next">Next page</button>
<button t-if="last" type="submit" class="btn btn-primary" name="button_submit" value="finish">Submit survey</button>
</div>
</form>
<!-- Modal used to display error message, i.c.o. ajax error -->
<div class="modal fade" id="AJAXErrorModal" role="dialog" aria-labelledby="AJAXErrorModal" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
<h4 class="modal-title">A problem has occured</h4>
</div>
<div class="modal-body"><p>Something went wrong while contacting survey server. <strong class="text-danger">Your answers have probably not been recorded.</strong> Try refreshing.</p></div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
</template>
<!-- Question widgets -->
<template id="free_text" name="Free text box">
<textarea class="form-control" rows="3" t-att-name="prefix"></textarea>
</template>
<template id="textbox" name="Text box">
<input type="text" class="form-control" t-att-name="prefix"/>
</template>
<template id="numerical_box" name="Numerical box">
<input type="number" step="any" class="form-control" t-att-name="prefix"/>
</template>
<template id="datetime" name="Datetime box">
<input type="datetime-local" class="form-control" t-att-name="prefix" placeholder="jj-mm-aaaa hh:mm" />
</template>
<template id="simple_choice" name="Simple choice">
<div t-if="question.display_mode == 'dropdown'" class="js_drop row">
<div class="col-md-12">
<select class="form-control" t-att-name="prefix">
<option disabled="1" selected="1" value="">Choose...</option>
<t t-foreach='question.labels_ids' t-as='label'>
<option t-att-value='label.id'><t t-esc='label.value'/></option>
</t>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<option class="js_other_option" value="-1"><span t-esc="question.comment_children_ids[0].question" /></option>
</t>
</select>
</div>
<div t-if='question.comments_allowed and question.comment_count_as_answer' class="col-md-6">
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)" data-oe-survey-othert="1"/>
</div>
<div t-if='question.comments_allowed and not question.comment_count_as_answer' class="col-md-12 mt16">
<span t-field="question.comment_children_ids[0].question"/>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)"/>
</div>
</div>
<div t-if="question.display_mode == 'columns' " class="row js_radio">
<div t-foreach='question.labels_ids' t-as='label' t-attf-class="col-md-#{question.column_nb}">
<label>
<input type="radio" t-att-name="prefix" t-att-value='label.id' />
<span t-field='label.value'/>
</label>
</div>
<div t-if='question.comments_allowed and question.comment_count_as_answer' class="js_comments col-md-12" >
<label>
<input type="radio" t-att-name="prefix" value="-1"/>
<span t-field="question.comment_children_ids[0].question" />
</label>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)"/>
</div>
<div t-if='question.comments_allowed and not question.comment_count_as_answer' class="col-md-12">
<span t-field="question.comment_children_ids[0].question"/>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)" data-oe-survey-othert="1"/>
</div>
</div>
</template>
<template id="multiple_choice" name="Multiple choice">
<div class="row">
<div t-foreach='question.labels_ids' t-as='label' t-attf-class="col-md-#{question.column_nb}">
<label>
<input type="checkbox" t-att-name="'%s_%s' % (prefix, label.id)" t-att-value='label.id' />
<span t-field='label.value'/>
</label>
</div>
<div t-if='question.comments_allowed and question.comment_count_as_answer' class="js_ck_comments col-md-12" >
<label>
<input type="checkbox" t-att-name="'%s_%s' % (prefix, -1)" value="-1" />
<span t-field="question.comment_children_ids[0].question" />
</label>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)"/>
</div>
<div t-if='question.comments_allowed and not question.comment_count_as_answer' class="col-md-12">
<span t-field="question.comment_children_ids[0].question"/>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)" data-oe-survey-othert="1"/>
</div>
</div>
</template>
<template id="matrix" name="Matrix">
<table class="table table-hover">
<thead>
<tr>
<th> </th>
<th t-foreach="question.labels_ids" t-as="col_label"><span t-field="col_label.value" /></th>
</tr>
</thead>
<tbody>
<tr t-foreach="question.labels_ids_2" t-as="row_label">
<th><span t-field="row_label.value" /></th>
<td t-foreach="question.labels_ids" t-as="col_label">
<input t-if="question.matrix_subtype == 'simple'" type="radio" t-att-name="'%s_%s' % (prefix, row_label.id)" t-att-value='col_label.id' />
<input t-if="question.matrix_subtype == 'multiple'" type="checkbox" t-att-name="'%s_%s_%s' % (prefix, row_label.id, col_label.id)" t-att-value='col_label.id' />
</td>
</tr>
</tbody>
</table>
<div t-if='question.comments_allowed'>
<span t-field="question.comment_children_ids[0].question"/>
<input type="text" class="form-control" t-att-name="'%s_%s' % (prefix, question.comment_children_ids[0].id)" />
</div>
</template>
<!-- Printable view of a survey (all pages) -->
<template id="survey_print" name="Survey">
<t t-call="website.layout">
<t t-set="head">
<script type="text/javascript" src="/survey/static/src/js/survey.js" />
</t>
<div class="wrap">
<div class="container">
<div class="row">
<div class='jumbotron mt32'>
<h1><span t-field='survey.title'/></h1>
<t t-if="survey.description is not False"><div t-field='survey.description'/></t>
</div>
<form role="form" method="post" class="js_surveyform" t-att-name="'%s' % (survey.id)" t-att-data-prefill="'/survey/prefill/%s/%s' % (survey.id, token)">
<t t-foreach="survey.page_ids" t-as="page">
<div class="page-header">
<h1 t-field='page.title' />
<div t-field='page.description'/>
</div>
<t t-foreach='page.question_ids' t-as='question'>
<t t-set="prefix" t-value="'%s_%s_%s' % (survey.id, page.id, question.id)" />
<div class="js_question-wrapper" t-att-id="prefix">
<h2>
<span t-field='question.question' />
<span t-if="question.constr_mandatory" class="text-danger">*</span>
</h2>
<p class="text-muted"><t t-if="question.description"><span t-field='question.description'/></t></p>
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
<t t-if="question.type == 'datetime'"><t t-call="survey.datetime"/></t>
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
<div class="js_errzone alert alert-danger" style="display:none;"></div>
</div>
</t>
<hr/>
</t>
</form>
</div>
</div>
</div>
</t>
</template>
</data>
</openerp>
+596
View File
@@ -0,0 +1,596 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- USER INPUTS -->
<record id="survey_user_input_search" model="ir.ui.view">
<field name="name">survey_user_input_search</field>
<field name="model">survey.user_input</field>
<field name="arch" type="xml">
<search string="Search Survey">
<field name="survey_id"/>
<field name="email"/>
<field name="partner_id"/>
<filter string="Completed" domain="[('state','=', 'done')]"/>
<filter string="Partially completed" domain="[('state','=', 'skip')]"/>
<filter string="New" domain="[('state','=', 'new')]"/>
<filter string="Test" domain="[('state','=', 'test')]"/>
<group expand="0" string="Group By...">
<filter name="group_by_survey" string="Survey" domain="[]" context="{'group_by':'survey_id'}"/>
<filter string="Email" domain="[]" context="{'group_by':'email'}"/>
<filter string="Partner" domain="[]" context="{'group_by':['partner_id']}"/>
</group>
</search>
</field>
</record>
<record model="ir.ui.view" id="survey_user_input_form">
<field name="name">survey_user_input_form</field>
<field name="model">survey.user_input</field>
<field name="arch" type="xml">
<form string="Survey User inputs" version="7.0">
<header>
<button name="action_survey_resent" states="new,skip" string="Sent Invitation Again" type="object" class="oe_highlight" icon="gtk-redo"/><br/>
<button name="action_print_response" states="done" string="View Answers" type="object" class="oe_highlight" icon="gtk-print"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_right oe_button_box" name="button_box">
</div>
<group col="2">
<group>
<field name="survey_id"/>
<field name="date_create"/>
<field name="type"/>
<field name="token" groups="base.group_no_one"/>
</group>
<group>
<field name="deadline"/>
<field name="partner_id"/>
<field name="email" widget="email"/>
<field name="test_entry" groups="base.group_no_one"/>
</group>
</group>
<field name="user_input_line_ids" mode="tree" attrs="{'readonly': False}">
<tree>
<field name="page_id"/>
<field name="question_id"/>
<field name="answer_type"/>
<field name="skipped"/>
<field name="date_create"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="survey_user_input_tree">
<field name="name">survey_user_input_tree</field>
<field name="model">survey.user_input</field>
<field name="arch" type="xml">
<tree string="Survey User inputs" version="7.0">
<field name="survey_id"/>
<field name="date_create"/>
<field name="deadline"/>
<field name="partner_id"/>
<field name="email"/>
<field name="type"/>
<field name="state"/>
<button name="action_survey_resent" states="new,skip" string="Resent the invitation" type="object" icon="gtk-redo"/>
<button name="action_print_response" states="done,skip" string="Print Answers" type="object" icon="gtk-print"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_user_input">
<field name="name">Survey Response</field>
<field name="res_model">survey.user_input</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="survey_user_input_tree"></field>
<field name="search_view_id" ref="survey_user_input_search"/>
<field name="context">{'search_default_group_by_survey': True}</field>
<field name="help" type="html">
<p>Nobody has replied to your surveys yet.</p>
</field>
</record>
<record id="action_selected_survey_user_input" model="ir.actions.act_window">
<field name="name">Survey User input</field>
<field name="res_model">survey.user_input</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="survey_user_input_tree"></field>
<field name="search_view_id" ref="survey_user_input_search"/>
<field name="context">{'search_default_survey_id': active_id, 'default_survey_id': active_id}</field>
<field name="help" type="html">
<p>Nobody has replied to your survey yet.</p>
</field>
</record>
<!-- SURVEY -->
<record model="ir.ui.view" id="survey_form">
<field name="name">survey_form</field>
<field name="model">survey.survey</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<form string="Survey" version="7.0">
<header groups="base.group_survey_manager">
<button name="action_send_survey" string="Invite people" states="open" type="object" class="oe_highlight" />
<field name="state" widget="statusbar" statusbar_visible="draft,open,close,cancel" clickable="True"/>
</header>
<sheet class="oe_survey">
<div class="oe_button_box oe_right" groups="base.group_survey_manager">
<button name="action_test_survey" string="Test Survey" type="object"/>
<button name="action_print_survey" string="Print Survey" type="object"/>
</div>
<div class="oe_title">
<label for="title" class="oe_edit_only"/>
<h1>
<field name="title" attrs="{'readonly':[('state','in',['close','cancel'])]}"/>
</h1>
</div>
<group nolabel="1" col="4">
<field name="visible_to_user" />
<field name="auth_required" />
<field name="public_url" widget="url" attrs="{'invisible': [('visible_to_user', '=', False)]}"/>
</group>
<field name="description" attrs="{'readonly': True}"/>
<notebook>
<page string="Pages and questions">
<field name="page_ids" mode="tree" attrs="{'readonly':[('state','=','close')]}" context="{'default_survey_id': active_id}" nolabel="1">
<tree>
<field name="sequence" widget="handle"/>
<field name="title"/>
<field name="question_ids"/>
</tree>
</field>
</page>
<page string="Survey options">
<group nolabel="1" col="4">
<field name="user_input_limit" attrs="{'readonly':[('state','=','close')]}"/>
<label string="completed surveys" colspan="2"/>
<field name="users_can_go_back" colspan="4" />
<field name="thank_you_message" colspan="4" attrs="{'readonly': True}"/>
<field name="res_model" attrs="{'invisible': True}"/>
</group>
</page>
<page string="User inputs">
<field name="user_input_ids" mode="tree">
<tree>
<field name="date_create"/>
<field name="deadline"/>
<field name="type"/>
<field name="state"/>
<field name="token"/>
<field name="partner_id"/>
<field name="email"/>
<field name="user_input_line_ids"/>
</tree>
</field>
</page>
</notebook>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
<record model="ir.ui.view" id= "survey_tree">
<field name="name">survey_tree</field>
<field name="model">survey.survey</field>
<field name="arch" type="xml">
<tree colors="gray:state == 'close'" string="Survey">
<field name="title" />
<field name="date_open" string="Opening date" />
<field name="date_close" string="Closing date" />
<field name="state" />
<field name="tot_start_survey" string="Started" />
<field name="tot_comp_survey" string="Completed" />
<field name="user_input_limit" string="Max closing limit" />
<button name="action_fill_survey" states="open"
string="Fill in Survey" type="object" icon="gtk-execute" context="{'survey_id': active_id}" attrs="{'invisible':[('state','!=','open')]}" />
<button name="action_print_survey" string="Print Answer" type="object" icon="gtk-print" />
<button name="print_statistics" string="Print Statistics" states="open,close,cancel" type="object" icon="gtk-print" groups="base.group_survey_manager" />
</tree>
</field>
</record>
<record id="survey_search" model="ir.ui.view">
<field name="name">survey_search</field>
<field name="model">survey.survey</field>
<field name="arch" type="xml">
<search string="Search Survey">
<field name="title" string="Survey"/>
<filter string="Draft" domain="[('state','=', 'draft')]"/>
<filter string="Open" domain="[('state','=','open')]"/>
<filter string="Closed" domain="[('state','=','close')]"/>
<filter string="Cancelled" domain="[('state','=','cancel')]"/>
<separator/>
<filter string="Not completed yet" name="unread_message" domain="[('user_input_ids.state', 'in', ['new', 'skip'])]"/>
<group expand="1" string="Group by...">
<filter string="Status" name="group_status" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
</group>
</search>
</field>
</record>
<record model="ir.ui.view" id="view_survey_kanban">
<field name="name">event.survey.kanban</field>
<field name="model">survey.survey</field>
<field name="arch" type="xml">
<kanban>
<field name="title"/>
<field name="date_open"/>
<field name="tot_comp_survey"/>
<field name="user_input_limit"/>
<field name="color"/>
<field name="state"/>
<field name="auth_required"/>
<field name="public_url"/>
<templates>
<div t-name="kanban-box" t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_survey oe_kanban_global_click">
<div class="oe_dropdown_toggle oe_dropdown_kanban" t-if="widget.view.is_action_enabled('edit')">
<span class="oe_e">i</span>
<ul class="oe_dropdown_menu">
<li t-if="widget.view.is_action_enabled('edit')"><a type="open">Edit...</a></li>
<li t-if="record.state.raw_value === 'open'"><a name="action_send_survey" type="object">Invite People...</a></li>
<li t-if="record.state.raw_value === 'open'"><a name="action_survey_fill2" type="object">Start Survey...</a></li>
<li><a name="action_print_survey" type="object">Print Survey...</a></li>
<li t-if="record.tot_comp_survey.raw_value"><a name="%(action_selected_survey_user_input)d" type="action">View Answers...(<field name="tot_comp_survey"/><t t-if="record.user_input_limit.raw_value > 0"> / <field name="user_input_limit"/></t>)</a></li>
<li t-if="record.tot_comp_survey.raw_value"><a name="print_statistics" type="object">Print Statistics...</a></li>
<li t-if="widget.view.is_action_enabled('delete')"><a type="delete">Delete!</a></li>
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
</ul>
</div>
<div class="oe_kanban_content">
<span class="oe_kanban_right" t-if="widget.view.is_action_enabled('edit')">
<a t-if="record.state.raw_value === 'draft'" title="Draft" class="oe_kanban_status"> </a>
<a t-if="record.state.raw_value === 'open'" title="Open" class="oe_kanban_status_green"> </a>
<a t-if="record.state.raw_value === 'close'" title="Closed" class="oe_kanban_status_red"> </a>
<a t-if="record.state.raw_value === 'cancel'" title="Cancelled" class="oe_kanban_status_salmon"> </a>
</span>
<h3 class="oe_kanban_ellipsis"><t t-esc="record.title.raw_value.toString()"></t></h3>
<div><p>
<ul>
<li>Opening: <field name="date_open"/></li>
<li>Closing: <field name="date_close"/></li>
</ul>
</p></div>
<div class="oe_stats_box"><span><field name="tot_start_survey"/></span><br/>started</div>
<div class="oe_stats_box"><span><field name="tot_comp_survey"/></span><br/>completed</div>
</div>
</div>
</templates>
</kanban>
</field>
</record>
<record model="ir.ui.view" id="survey_calendar">
<field name="name">survey.calendar</field>
<field name="model">survey.survey</field>
<field name="arch" type="xml">
<calendar string="Surveys Calendar" date_start="date_open" date_stop="date_close" color="state">
<field name="title" />
</calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_form">
<field name="name">Surveys</field>
<field name="res_model">survey.survey</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form,calendar</field>
<field name="view_id" ref="view_survey_kanban"></field>
<field name="search_view_id" ref="survey_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Click to create a new survey.</p>
<p>You can create survey for different purposes: recruitment interviews, employee's periodical evaluations, marketing campaigns, etc.</p>
<p>A survey is made of pages containing questions of several types: text, multiple choices, etc.</p>
</field>
</record>
<!-- PAGES -->
<record model="ir.ui.view" id="survey_page_form">
<field name="name">survey_page_form</field>
<field name="model">survey.page</field>
<field name="arch" type="xml">
<form string="Survey Page" version="7.0">
<sheet class="oe_survey">
<group invisible="context.get('edit')" attrs="{'invisible': [('survey_id','!=',None)]}">
<field name="survey_id"/>
</group>
<div class="oe_title">
<label for="title" class="oe_edit_only"/>
<h1><field name="title"/></h1>
</div>
<field name="description" attrs="{'readonly': True}"/>
<group nolabel="1">
<field name="question_ids" nolabel="1" mode="tree" context="{'default_page_id': active_id}">
<tree>
<field name="sequence" widget="handle"/>
<field name="question"/>
<field name="type"/>
<field name="constr_mandatory"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="survey_page_tree">
<field name="name">survey_page_tree</field>
<field name="model">survey.page</field>
<field name="arch" type="xml">
<tree string="Survey Page">
<field name="sequence" widget="handle"/>
<field name="title"/>
<field name="survey_id"/>
<field name="question_ids" string="#Questions"/>
</tree>
</field>
</record>
<record id="view_survey_page_filter" model="ir.ui.view">
<field name="name">survey.page.list.select</field>
<field name="model">survey.page</field>
<field name="arch" type="xml">
<search string="Search Survey Page">
<field name="title" string="Page"/>
<field name="survey_id"/>
<group expand="0" string="Group By...">
<filter name="group_by_survey" string="Survey" domain="[]" context="{'group_by':'survey_id'}"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_page_form">
<field name="name">Survey Pages</field>
<field name="res_model">survey.page</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="survey_page_tree"></field>
<field name="context">{'search_default_group_by_survey': True}</field>
</record>
<record model="ir.ui.view" id="survey_page_wizard_test1">
<field name="name">survey_page_wizard_test</field>
<field name="model">survey.page</field>
<field name="priority">20</field>
<field name="arch" type="xml">
<form string="Survey Pages">
<field name="title" colspan="4"/>
<separator string="Description" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
<group colspan="4">
<label string="" colspan="3"/>
<button name="survey_save" string="Ok" type="object" icon="gtk-go-forward"/>
</group>
</form>
</field>
</record>
<!-- QUESTIONS -->
<record model="ir.ui.view" id="survey_question_form">
<field name="name">survey_question_form</field>
<field name="model">survey.question</field>
<field name="arch" type="xml">
<form string="Survey Question" version="7.0">
<sheet class="oe_survey">
<group col="4">
<!-- The question -->
<group colspan="4">
<field name="type" readonly="context.get('is_comment_question', False)"/>
<field name="matrix_subtype" attrs="{'invisible':[('type','not in',['matrix'])]}"/>
<field name="question" />
<field name="description" />
</group>
<!-- Labels -->
<group colspan="4" nolabel="1" attrs="{'invisible':[('type','not in',['simple_choice', 'multiple_choice', 'matrix'])]}">
<field name="display_mode" string="Display mode" attrs="{'invisible':[('type','not in',['simple_choice'])]}"/>
<field name="column_nb" string="Number of columns" attrs="{'invisible':[('display_mode','=','dropdown'), ('type','=','simple_choice')]}"/>
<field name="labels_ids" colspan="4" nolabel="1" context="{'default_question_id': active_id}">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="value" string="Answer choices"/>
</tree>
</field>
<field name="labels_ids_2" colspan="4" nolabel="1" context="{'default_question_id_2': active_id}" attrs="{'invisible':[('type','not in',['matrix'])]}">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="value" string="Rows labels"/>
</tree>
</field>
</group>
<!-- Question validation -->
<group colspan="4" nolabel="1" invisible="context.get('is_comment_question', False)">
<field name="constr_mandatory" string="Is this question mandatory?"/>
<group colspan="4" attrs="{'invisible':[('constr_mandatory','=',False)]}">
<group colspan="4" col="4" attrs="{'invisible':[('type','not in',['matrix'])]}">
<field name="constr_type" string="Users must answer..."/>
<field name="constr_minimum_req_ans" nolabel="1" attrs="{'invisible':[('constr_type','not in',['at least','a range'])]}" />
<field name="constr_maximum_req_ans" nolabel="1" attrs="{'invisible':[('constr_type','not in',['at most','a range', 'exactly'])]}" />
</group>
<field colspan="2" name="constr_error_msg" string="Error message"/>
</group>
</group>
<!-- Answer validation -->
<group colspan="4" col="4" nolabel="1" attrs="{'invisible':[('type','not in',['textbox'])]}">
<group>
<field name="validation_required" colspan="2"/>
<group colspan="4" col="4" attrs="{'invisible':[('validation_required','=',False)]}">
<field name="validation_type" />
<field name="validation_error_msg" />
<group colspan="4" col="4" attrs="{'invisible':[('validation_type','!=','has_length')]}">
<field name="validation_length_min" string="between"/>
<field name="validation_length_max" string="and"/>
</group>
<group colspan="4" col="4" attrs="{'invisible':[('validation_type','!=','is_decimal')]}">
<field name="validation_min_float_value" string="between"/>
<field name="validation_max_float_value" string="and"/>
</group>
<group colspan="4" col="4" attrs="{'invisible':[('validation_type','!=','is_integer')]}">
<field name="validation_min_int_value" string="between"/>
<field name="validation_max_int_value" string="and"/>
</group>
<group colspan="4" col="4" attrs="{'invisible':[('validation_type','!=','is_date')]}">
<field name="validation_min_date" string="between"/>
<field name="validation_max_date" string="and"/>
</group>
</group>
</group>
</group>
<!-- Comments -->
<group colspan="4" nolabel="1" attrs="{'invisible':[('type','not in',['simple_choice','multiple_choice', 'matrix'])]}">
<field name='comments_allowed' />
<group colspan="4" attrs="{'invisible':[('comments_allowed','=',False)]}">
<field name='comment_count_as_answer' attrs="{'invisible':[('type','not in',['simple_choice','multiple_choice'])]}" />
<field colspan="4" nolabel="1" name="comment_children_ids" context="{'default_parent_id': active_id, 'default_type': 'textbox', 'is_comment_question': True}" widget="many2man_tags">
<tree>
<field name="question" string="Comment question (only one question allowed, others will be ignored)"/>
</tree>
</field>
</group>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="survey_question_tree">
<field name="name">survey_question_tree</field>
<field name="model">survey.question</field>
<field name="arch" type="xml">
<tree string="Survey Question">
<field name="sequence" widget="handle"/>
<field name="question"/>
<field name="page_id"/>
<field name="survey_id"/>
<field name="type"/>
</tree>
</field>
</record>
<record id="survey_question_search" model="ir.ui.view">
<field name="name">survey_question_search</field>
<field name="model">survey.question</field>
<field name="arch" type="xml">
<search string="Search Question">
<field name="question" string="Question"/>
<field name="survey_id"/>
<field name="page_id"/>
<field name="type"/>
<group expand="1" string="Group by...">
<filter name="group_by_survey" string="Survey" domain="[]" context="{'group_by':'survey_id'}"/>
<filter name="group_by_page" string="Page" domain="[]" context="{'group_by':'page_id'}"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_question_form">
<field name="name">Survey Questions</field>
<field name="res_model">survey.question</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="survey_question_tree"></field>
<field name="search_view_id" ref="survey_question_search"/>
<field name="context">{'search_default_group_by_survey': True, 'search_default_group_by_page': True}</field>
</record>
<!-- LABELS -->
<record model="ir.ui.view" id="survey_label_tree">
<field name="name">survey_label_tree</field>
<field name="model">survey.label</field>
<field name="arch" type="xml">
<tree string="Survey Label">
<field name="sequence" widget="handle"/>
<field name="question_id"/>
<field name="question_id_2"/>
<field name="value"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_label_form">
<field name="name">Survey Labels</field>
<field name="res_model">survey.label</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="survey_label_tree"></field>
</record>
<!-- USER INPUT LINES
.. note:: these views are useful mainly for technical users/administrators -->
<record model="ir.ui.view" id="survey_user_input_line_form">
<field name="name">survey_user_input_line_form</field>
<field name="model">survey.user_input_line</field>
<field name="arch" type="xml">
<form string="User input line details" version="7.0">
<sheet>
<group col="4">
<field name="question_id"/>
<field name="date_create"/>
<field name="answer_type"/>
<field name="skipped" />
</group>
<group>
<field name="value_text" colspan='2' attrs="{'invisible': [('answer_type','!=','text')]}"/>
<field name="value_number" colspan='2' attrs="{'invisible': [('answer_type','!=','number')]}"/>
<field name="value_date" colspan='2' attrs="{'invisible': [('answer_type','!=','date')]}"/>
<field name="value_free_text" colspan='2' attrs="{'invisible': [('answer_type','!=','free_text')]}"/>
<field name="value_suggested_row" colspan='2' />
<field name="value_suggested" colspan='2' attrs="{'invisible': [('answer_type','!=','suggestion')]}"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="survey_response_line_tree">
<field name="name">survey_response_line_tree</field>
<field name="model">survey.user_input_line</field>
<field name="arch" type="xml">
<tree string="Survey Answer Line">
<field name="survey_id"/>
<field name="user_input_id"/>
<field name="page_id"/>
<field name="question_id"/>
<field name="date_create"/>
<field name="answer_type"/>
<field name="skipped"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_survey_user_input_line">
<field name="name">Survey User Input lines</field>
<field name="res_model">survey.user_input_line</field>
<field name="view_mode">tree,form</field>
</record> -->
<!-- ACTIONS -->
<act_window context="{'search_default_survey_id': [active_id], 'default_survey_id': active_id}" id="act_survey_pages" name="Pages" res_model="survey.page" src_model="survey.survey"/>
<act_window context="{'search_default_survey': active_id, 'default_survey': active_id}" id="act_survey_question" name="Questions" res_model="survey.question" src_model="survey.survey"/>
<act_window context="{'search_default_page_id': active_id, 'default_page_id': active_id}" id="act_survey_page_question" name="Questions" res_model="survey.question" src_model="survey.page"/>
<act_window domain="[('question_id', '=', active_id)]" id="act_survey_answer" name="Answers" res_model="survey.label" src_model="survey.question"/>
<!-- MENU ELEMENTS -->
<!-- Top menubar item -->
<menuitem name="Surveys" id="survey_main" sequence="120"/>
<!-- Left menu categories-->
<menuitem name="Surveys" id="menu_surveys" parent="survey_main" sequence="10" groups="base.group_survey_user"/>
<menuitem name="Statistics" id="menu_statistics" parent="survey_main" sequence="20" groups="base.group_survey_manager"/>
<menuitem name="Technical Settings" id="menu_surveys_configuration" parent="survey_main" sequence="30" groups="base.group_no_one"/>
<!-- Left menu elements: Survey -->
<menuitem name="Surveys" id="menu_survey_form" action="action_survey_form" parent="menu_surveys" sequence="1"/>
<!-- Left menu elements: Statistics -->
<menuitem name="Survey User inputs" id="menu_survey_type_form1" action="action_survey_user_input" parent="menu_statistics" sequence="1"/>
<!-- Left menu elements: Technical Configuration -->
<menuitem name="Survey Pages" id="menu_survey_page_form1" action="action_survey_page_form" parent="menu_surveys_configuration" sequence="1"/>
<menuitem name="Survey Questions" id="menu_survey_question_form1" action="action_survey_question_form" parent="menu_surveys_configuration" sequence="2"/>
<menuitem name="Survey Labels" id="menu_survey_label_form1" action="action_survey_label_form" parent="menu_surveys_configuration" sequence="3"/>
<menuitem name="Survey User Input Lines" id="menu_survey_response_line_form" action="action_survey_user_input_line" parent="menu_surveys_configuration" sequence="4"/>
</data>
</openerp>
+1 -7
View File
@@ -19,12 +19,6 @@
#
##############################################################################
import survey_send_invitation
import survey_print_statistics
import survey_print_answer
import survey_browse_answer
import survey_selection
import survey_answer
import survey_print
import survey_email_compose_message
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
File diff suppressed because it is too large Load Diff
-37
View File
@@ -1,37 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!--
Survey Question Wizard
-->
<record id="view_survey_question_message" model="ir.ui.view">
<field name="name">Survey Answer</field>
<field name="model">survey.question.wiz</field>
<field name="arch" type="xml">
<form string="Your Messages" version="7.0">
<field name="name" nolabel="1" colspan="4" />
</form>
</field>
</record>
<record id="view_survey_question_message1" model="ir.ui.view">
<field name="name">Survey Search</field>
<field name="model">survey.question.wiz</field>
<field name="arch" type="xml">
<search string="Your Messages">
<field name="name"/>
</search>
</field>
</record>
<record id="action_view_survey_question_message" model="ir.actions.act_window">
<field name="type">ir.actions.act_window</field>
<field name="res_model">survey.question.wiz</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -1,59 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class survey_browse_answer(osv.osv_memory):
_name = 'survey.browse.answer'
_columns = {
'survey_id': fields.many2one('survey', "Survey", required="1"),
'response_id': fields.many2one("survey.response", "Survey Answers", help="If this field is empty, all answers of the selected survey will be print."),
}
def action_next(self, cr, uid, ids, context=None):
"""
Open Browse Response wizard. if you select only survey_id then this wizard open with all response_ids and
if you select survey_id and response_id then open the particular response of the survey.
"""
if context is None: context = {}
record = self.read(cr, uid, ids, [])
record = record and record[0] or {}
if record['response_id']:
res_id = [(record.get('response_id') and record['response_id'][0])]
else:
sur_response_obj = self.pool.get('survey.response')
res_id = sur_response_obj.search(cr, uid, [('survey_id', '=', record['survey_id'][0])])
context.update({'active' : True,'survey_id' : record['survey_id'][0], 'response_id' : res_id, 'response_no' : 0})
search_obj = self.pool.get('ir.ui.view')
search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
return {
'view_type': 'form',
"view_mode": 'form',
'res_model': 'survey.question.wiz',
'type': 'ir.actions.act_window',
'target': 'new',
'search_view_id':search_id[0],
'context' : context
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,42 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!--
Browse Response Wizard (Survey Browse answer)
-->
<record id="view_survey_answer" model="ir.ui.view">
<field name="name">Survey</field>
<field name="model">survey.browse.answer</field>
<field name="arch" type="xml">
<form string="Survey" version="7.0">
<group col="4">
<field name="survey_id"/>
<field name="response_id" domain="[('survey_id','=', survey_id)]"/>
</group>
<footer>
<button name="action_next" string="Start" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_browse_survey_response"
model="ir.actions.act_window">
<field name="name">Answer Survey</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">survey.browse.answer</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem name="Browse Answers" id="menu_browse_survey_response"
action="action_browse_survey_response" parent="base.next_id_10"
groups="base.group_tool_manager" icon="STOCK_PRINT_PREVIEW"/>
</data>
</openerp>
@@ -0,0 +1,222 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.translate import _
from datetime import datetime
import re
import uuid
emails_split = re.compile(r"[;,\n\r]+")
class survey_mail_compose_message(osv.TransientModel):
_name = 'survey.mail.compose.message'
_inherit = 'mail.compose.message'
_description = 'Email composition wizard for Survey'
_log_access = True
def _get_public_url(self, cr, uid, ids, name, arg, context=None):
res = dict((id, 0) for id in ids)
survey_obj = self.pool.get('survey.survey')
for wizard in self.browse(cr, uid, ids, context=context):
res[wizard.id] = survey_obj.browse(cr, uid, wizard.survey_id, context=context).public_url
return res
def _get_public_url_html(self, cr, uid, ids, name, arg, context=None):
""" Compute if the message is unread by the current user """
urls = self._get_public_url(cr, uid, ids, name, arg, context=context)
for key, url in urls.items():
urls[key] = '<a href="%s">%s</a>' % (url, _("Click here to start survey"))
return urls
_columns = {
'survey_id': fields.many2one('survey.survey', 'Survey', required=True),
'public': fields.selection([('public_link', 'Share the public web link to your audience.'),
('email_public_link', 'Send by email the public web link to your audience.'),
('email_private', 'Send private invitation to your audience (only one response per recipient and per invitation).')],
string='Share options', required=True),
'public_url': fields.function(_get_public_url, string="Public url", type="char"),
'public_url_html': fields.function(_get_public_url_html, string="Public HTML web link", type="char"),
'partner_ids': fields.many2many('res.partner',
'survey_mail_compose_message_res_partner_rel',
'wizard_id', 'partner_id', 'Existing contacts'),
'attachment_ids': fields.many2many('ir.attachment',
'survey_mail_compose_message_ir_attachments_rel',
'wizard_id', 'attachment_id', 'Attachments'),
'multi_email': fields.text(string='List of emails', help="This list of emails of recipients will not converted in contacts. Emails separated by commas, semicolons or newline."),
'date_deadline': fields.date(string="Deadline to which the invitation to respond is valid", help="Deadline to which the invitation to respond for this survey is valid. If the field is empty, the invitation is still valid."),
}
_defaults = {
'public': 'email_private',
'survey_id': lambda self, cr, uid, ctx={}: ctx.get('model') == 'survey.survey' and ctx.get('res_id') or None
}
def default_get(self, cr, uid, fields, context=None):
res = super(survey_mail_compose_message, self).default_get(cr, uid, fields, context=context)
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
res.update({'partner_ids': context.get('active_ids')})
return res
def onchange_multi_email(self, cr, uid, ids, multi_email, context=None):
emails = list(set(emails_split.split(multi_email or "")))
emails_checked = []
error_message = ""
for email in emails:
email = email.strip()
if email:
if not re.search(r"^[^@]+@[^@]+$", email):
error_message += "\n'%s'" % email
else:
emails_checked.append(email)
if error_message:
raise osv.except_osv(_('Warning!'), _("One email at least is incorrect: %s" % error_message))
emails_checked.sort()
values = {'multi_email': '\n'.join(emails_checked)}
return {'value': values}
def onchange_survey_id(self, cr, uid, ids, survey_id, context=None):
""" Compute if the message is unread by the current user. """
if survey_id:
survey = self.pool.get('survey.survey').browse(cr, uid, survey_id, context=context)
return {
'value': {
'subject': survey.title,
'public_url': survey.public_url,
'public_url_html': '<a href="%s">%s</a>' % (survey.public_url, _("Click here to take survey")),
}}
else:
txt = _("Please select a survey")
return {
'value': {
'public_url': txt,
'public_url_html': txt,
}}
#------------------------------------------------------
# Wizard validation and send
#------------------------------------------------------
def send_mail(self, cr, uid, ids, context=None):
""" Process the wizard content and proceed with sending the related
email(s), rendering any template patterns on the fly if needed """
if context is None:
context = {}
survey_response_obj = self.pool.get('survey.user_input')
partner_obj = self.pool.get('res.partner')
mail_mail_obj = self.pool.get('mail.mail')
try:
model, anonymous_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_anonymous')
except ValueError:
anonymous_id = None
def create_response_and_send_mail(wizard, token, partner_id, email):
""" Create one mail by recipients and replace __URL__ by link with identification token """
#set url
url = wizard.survey_id.public_url
if token:
url = url + token
# post the message
values = {
'model': None,
'res_id': None,
'subject': wizard.subject,
'body': wizard.body.replace("__URL__", url),
'body_html': wizard.body.replace("__URL__", url),
'parent_id': None,
'partner_ids': partner_id and [(4, partner_id)] or None,
'notified_partner_ids': partner_id and [(4, partner_id)] or None,
'attachment_ids': wizard.attachment_ids or None,
'email_from': wizard.email_from or None,
'email_to': email,
}
mail_id = mail_mail_obj.create(cr, uid, values, context=context)
mail_mail_obj.send(cr, uid, [mail_id], context=context)
def create_token(wizard, partner_id, email):
if context.get("survey_resent_token"):
response_ids = survey_response_obj.search(cr, uid, [('survey_id', '=', wizard.survey_id.id), ('state', 'in', ['new', 'skip']), '|', ('partner_id', '=', partner_id), ('email', '=', email)], context=context)
if response_ids:
return survey_response_obj.read(cr, uid, response_ids, ['token'], context=context)[0]['token']
if wizard.public != 'email_private':
return None
else:
token = uuid.uuid4().__str__()
# create response with token
survey_response_obj.create(cr, uid, {
'survey_id': wizard.survey_id.id,
'deadline': wizard.date_deadline,
'date_create': datetime.now(),
'type': 'link',
'state': 'new',
'token': token,
'partner_id': partner_id,
'email': email})
return token
for wizard in self.browse(cr, uid, ids, context=context):
# check if __URL__ is in the text
if wizard.body.find("__URL__") < 0:
raise osv.except_osv(_('Warning!'), _("The content of the text don't contain '__URL__'. \
__URL__ is automaticaly converted into the special url of the survey."))
if not wizard.multi_email and not wizard.partner_ids and (context.get('default_partner_ids') or context.get('default_multi_email')):
wizard.multi_email = context.get('default_multi_email')
wizard.partner_ids = context.get('default_partner_ids')
# quick check of email list
emails_list = []
if wizard.multi_email:
emails = list(set(emails_split.split(wizard.multi_email)) - set([partner.email for partner in wizard.partner_ids]))
for email in emails:
email = email.strip()
if re.search(r"^[^@]+@[^@]+$", email):
emails_list.append(email)
# remove public anonymous access
partner_list = []
for partner in wizard.partner_ids:
if not anonymous_id or not partner.user_ids or anonymous_id not in [x.id for x in partner.user_ids[0].groups_id]:
partner_list.append({'id': partner.id, 'email': partner.email})
if not len(emails_list) and not len(partner_list):
if wizard.model == 'res.partner' and wizard.res_id:
return False
raise osv.except_osv(_('Warning!'), _("Please enter at least one valid recipient."))
for email in emails_list:
partner_id = partner_obj.search(cr, uid, [('email', '=', email)], context=context)
partner_id = partner_id and partner_id[0] or None
token = create_token(wizard, partner_id, email)
create_response_and_send_mail(wizard, token, partner_id, email)
for partner in partner_list:
token = create_token(wizard, partner['id'], partner['email'])
create_response_and_send_mail(wizard, token, partner['id'], partner['email'])
return {'type': 'ir.actions.act_window_close'}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Survey send invitation by email: template -->
<record id="email_template_survey" model="email.template">
<field name="name">Survey - Send by Email</field>
<field name="model_id" ref="model_survey_survey" />
<field name="auto_delete" eval="True" />
<field name="body_html">
<![CDATA[
<div style="font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); ">
<p>Hello,</p>
<p>We are conducting a survey, and your response would be appreciated.</p>
<p><a href="__URL__">Please, click here to start survey</a></p>
<p>Thanks for your participation!</p>
</div>
]]>
</field>
</record>
<!-- Replace the default mass-mailing wizard in base with the composition wizard -->
<act_window name="Partner Survey Mailing" res_model="survey.mail.compose.message" src_model="res.partner" view_mode="form" multi="True" target="new" key2="client_action_multi" id="survey.action_partner_survey_mail" context="{'default_use_template': True, 'default_template_id': ref('email_template_survey')}" />
<!-- Composition form (context['survey_resent_token'], if True, hide share option, emails list and partner_ids) -->
<record model="ir.ui.view" id="survey_email_compose_message">
<field name="name">survey.mail.compose.message.form</field>
<field name="model">survey.mail.compose.message</field>
<field name="arch" type="xml">
<form string="Compose Email" version="7.0">
<field name="composition_mode" invisible="1"/>
<field name="model" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="parent_id" invisible="1"/>
<group col="2">
<field name="survey_id" readonly="context.get('default_survey_id')" on_change="onchange_survey_id(survey_id)" />
<field name="public" widget="radio" invisible="context.get('survey_resent_token')" />
</group>
<group col="1" invisible="context.get('survey_resent_token')" attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}" class="oe_survey_email_public">
<div>
You can share your survey web public link and/or send private invitations to your audience.<br />
People can response once per invitation, and whenever they want with the public web link.
</div>
<div>Copy, paste and share the web link below to your audience.</div>
<div>
<field name="public_url"/>
</div>
<div>Copy and paste the HTML code below to add this web link to any webpage.</div>
<div><field name="public_url_html" /></div>
</group>
<group col="1" attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">
<group col="2">
<field invisible="context.get('survey_resent_token')" name="partner_ids" widget="many2many_tags_email" placeholder="Add list of existing contacts..." context="{'force_email':True, 'show_email':True}" />
<field invisible="context.get('survey_resent_token')" name="multi_email" placeholder="Add list of email of recipients (will not converted in partner), separated by commas, semicolons or newline..." on_change="onchange_multi_email(multi_email)" no_resize="1" />
<field name="subject" placeholder="Subject..."/>
</group>
<field name="body" help="__URL__ will be automatically transformed into web address (public or private, depending on your choice). You can click on 'Show Source' button to see __URL__ in the link tag on the email template."/>
<group col="2">
<div>
<label for="attachment_ids" />
<field name="attachment_ids" widget="many2many_binary" />
</div>
<div class="oe_survey_date_deadline">
<label for="date_deadline" />
<field name="date_deadline" />
</div>
</group>
</group>
<footer attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}">
<button string="Close" class="oe_link" special="cancel" />
</footer>
<footer attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">
<button string="Send" name="send_mail" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel" />
<group class="oe_right" col="1">
<div>
Use template
<field name="template_id" nolabel="1" on_change="onchange_template_id(template_id, composition_mode, model, res_id, context)" />
</div>
<button icon="/email_template/static/src/img/email_template_save.png" type="object" name="save_as_template" string="Save as new template" class="oe_link" help="Save as a new template" />
</group>
</footer>
</form>
</field>
</record>
</data>
</openerp>
-67
View File
@@ -1,67 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
class survey_print(osv.osv_memory):
_name = 'survey.print'
_columns = {
'survey_ids': fields.many2many('survey', string="Survey", required="1"),
'orientation' : fields.selection([('vertical','Portrait(Vertical)'),\
('horizontal','Landscape(Horizontal)')], 'Orientation'),
'paper_size' : fields.selection([('letter','Letter (8.5" x 11")'),\
('legal','Legal (8.5" x 14")'),('a4','A4 (210mm x 297mm)')], 'Paper Size'),
'page_number' : fields.boolean('Include Page Number'),
'without_pagebreak' : fields.boolean('Print Without Page Breaks'),
}
_defaults = {
'orientation': lambda *a:'vertical',
'paper_size': lambda *a:'letter',
'page_number':lambda *a: 0,
'without_pagebreak':lambda *a: 0
}
def action_next(self, cr, uid, ids, context=None):
"""
Print Survey Form(print template of the survey).
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Survey IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for print survey form.
"""
datas = {'ids' : self.read(cr, uid, ids, ['survey_ids'], context=context)[0]['survey_ids']}
res = self.read(cr, uid, ids, ['survey_title', 'orientation', 'paper_size',\
'page_number', 'without_pagebreak'], context=context)
res = res and res[0] or {}
datas['form'] = res
datas['model'] = 'survey.print'
return {
'type': 'ir.actions.report.xml',
'report_name': 'survey.form',
'datas': datas,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-45
View File
@@ -1,45 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Survey Print Form View -->
<record id="view_survey_print" model="ir.ui.view">
<field name="name">Survey Print</field>
<field name="model">survey.print</field>
<field name="arch" type="xml">
<form string="Survey Print" version="7.0">
<group col="4">
<separator string="Survey" colspan="4"/>
<field name="survey_ids" nolabel="1" colspan="4" />
<separator string="Print Option" colspan="4"/>
<field name="orientation" colspan="4"/>
<field name="paper_size" colspan="4"/>
<field name="page_number" colspan="4"/>
<field name="without_pagebreak" colspan="4"/>
</group>
<footer>
<button name="action_next" string="Print" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Survey Print action -->
<record id="action_view_survey_print" model="ir.actions.act_window">
<field name="name">Print Survey</field>
<field name="res_model">survey.print</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem name="Print Surveys" id="menu_print_survey_form" sequence="1"
action="action_view_survey_print" parent="base.next_id_10"
groups="base.group_tool_manager" icon="STOCK_PRINT"/>
</data>
</openerp>
@@ -1,72 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
class survey_print_answer(osv.osv_memory):
_name = 'survey.print.answer'
_columns = {
'response_ids': fields.many2many('survey.response','survey_print_response',\
'response_id','print_id', "Answer", required="1"),
'orientation': fields.selection([('vertical','Portrait(Vertical)'),\
('horizontal','Landscape(Horizontal)')], 'Orientation'),
'paper_size': fields.selection([('letter','Letter (8.5" x 11")'),\
('legal','Legal (8.5" x 14")'),\
('a4','A4 (210mm x 297mm)')], 'Paper Size'),
'page_number': fields.boolean('Include Page Number'),
'without_pagebreak': fields.boolean('Print Without Page Breaks')
}
_defaults = {
'orientation': lambda *a:'vertical',
'paper_size': lambda *a:'letter',
'page_number': lambda *a: 0,
'without_pagebreak': lambda *a: 0
}
def action_next(self, cr, uid, ids, context=None):
"""
Print Survey Answer in pdf format.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of print answer IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for created survey answer report
"""
if context is None:
context = {}
datas = {'ids': context.get('active_ids', [])}
res = self.read(cr, uid, ids, ['response_ids', 'orientation', 'paper_size',\
'page_number', 'without_pagebreak'], context=context)
res = res and res[0] or {}
datas['form'] = res
datas['model'] = 'survey.print.answer'
return {
'type': 'ir.actions.report.xml',
'report_name': 'survey.browse.response',
'datas': datas,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,45 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Survey Print answer Form View -->
<record id="view_survey_print_answer" model="ir.ui.view">
<field name="name">Survey Print Answer</field>
<field name="model">survey.print.answer</field>
<field name="arch" type="xml">
<form string="Print Answer" version="7.0">
<group col="4">
<separator string="Answer" colspan="4"/>
<field name="response_ids" nolabel="1" colspan="4" />
<separator string="Print Option" colspan="4"/>
<field name="orientation" colspan="4"/>
<field name="paper_size" colspan="4"/>
<field name="page_number" colspan="4"/>
<field name="without_pagebreak" colspan="4"/>
</group>
<footer>
<button name="action_next" string="Print" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Survey Print answer action -->
<record id="action_view_survey_print_answer"
model="ir.actions.act_window">
<field name="name">Print Answer</field>
<field name="res_model">survey.print.answer</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem name="Surveys Answers" action="action_view_survey_print_answer" id="menu_print_survey_answer"
parent="base.next_id_10" icon="STOCK_PRINT" groups="base.group_tool_manager"/>
</data>
</openerp>
@@ -1,37 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Survey Print Statistics Form View -->
<record id="view_survey_print_statistics" model="ir.ui.view">
<field name="name">Survey Print Statistics</field>
<field name="model">survey.print.statistics</field>
<field name="arch" type="xml">
<form string="Survey Print Statistics" version="7.0">
<field name="survey_ids"/>
<footer>
<button name="action_next" string="Print" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Survey Print Statistics action -->
<record id="action_view_survey_print_statistics"
model="ir.actions.act_window">
<field name="name">Survey Print Statistics</field>
<field name="res_model">survey.print.statistics</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem name="Surveys Statistics" action="action_view_survey_print_statistics" id="menu_print_survey_statistics"
parent="base.next_id_10" icon="STOCK_PRINT" groups="base.group_tool_manager"/>
</data>
</openerp>
-105
View File
@@ -1,105 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from lxml import etree
from openerp.osv import fields, osv
from openerp.tools.translate import _
class survey_name_wiz(osv.osv_memory):
_name = 'survey.name.wiz'
_columns = {
'survey_id': fields.many2one('survey', 'Survey', required=True, ondelete='cascade', domain= [('state', '=', 'open')]),
'page_no': fields.integer('Page Number'),
'note': fields.text("Description"),
'page': fields.char('Page Position',size = 12),
'transfer': fields.boolean('Page Transfer'),
'store_ans': fields.text('Store Answer'),
'response': fields.char('Answer',size=16)
}
_defaults = {
'page_no': -1,
'page': 'next',
'transfer': 1,
'response': 0,
'survey_id': lambda self,cr,uid,context:context.get('survey_id',False),
'store_ans': '{}' #Setting the default pattern as '{}' as the field is of type text. The field always gets the value in dict format
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(survey_name_wiz, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
if uid != 1:
survey_obj = self.pool.get('survey')
line_ids = survey_obj.search(cr, uid, [('invited_user_ids','in',uid)], context=context)
domain = str([('id', 'in', line_ids)])
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='survey_id']")
for node in nodes:
node.set('domain', domain)
res['arch'] = etree.tostring(doc)
return res
def action_next(self, cr, uid, ids, context=None):
"""
Start the survey, Increment in started survey field but if set the max_response_limit of
survey then check the current user how many times start this survey. if current user max_response_limit
is reach then this user can not start this survey(Raise Exception).
"""
survey_obj = self.pool.get('survey')
search_obj = self.pool.get('ir.ui.view')
if context is None: context = {}
this = self.browse(cr, uid, ids, context=context)[0]
survey_id = this.survey_id.id
context.update({'survey_id': survey_id, 'sur_name_id': this.id})
cr.execute('select count(id) from survey_history where user_id=%s\
and survey_id=%s' % (uid,survey_id))
res = cr.fetchone()[0]
sur_rec = survey_obj.browse(cr,uid,survey_id,context=context)
if sur_rec.response_user and res >= sur_rec.response_user:
raise osv.except_osv(_('Warning!'),_("You cannot give response for this survey more than %s times.") % (sur_rec.response_user))
if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey:
raise osv.except_osv(_('Warning!'),_("You cannot give more responses. Please contact the author of this survey for further assistance."))
search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
return {
'view_type': 'form',
"view_mode": 'form',
'res_model': 'survey.question.wiz',
'type': 'ir.actions.act_window',
'target': 'new',
'search_view_id': search_id[0],
'context': context
}
def on_change_survey(self, cr, uid, ids, survey_id, context=None):
"""
on change event of survey_id field, if note is available in selected survey then display this note in note fields.
"""
if not survey_id:
return {}
notes = self.pool.get('survey').read(cr, uid, survey_id, ['note'])['note']
return {'value': {'note': notes}}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-36
View File
@@ -1,36 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!--
Display Survey List
-->
<record id="view_survey_name" model="ir.ui.view">
<field name="name">Survey</field>
<field name="model">survey.name.wiz</field>
<field name="arch" type="xml">
<form string="Survey" version="7.0">
<group>
<field name="survey_id" on_change="on_change_survey(survey_id)"/>
</group>
<field name="note" placeholder="Add Description" attrs="{'readonly': [('survey_id','=',False)]}"/>
<footer>
<button name="action_next" string="Start" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_view_survey_name"
model="ir.actions.act_window">
<field name="name">Give Survey Answer</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">survey.name.wiz</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
@@ -1,240 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
import time
from random import choice
import string
import os
import datetime
import socket
from openerp import tools
from openerp.modules.module import get_module_resource
from openerp.osv import fields, osv
import openerp.report
from openerp.tools.translate import _
class survey_send_invitation(osv.osv_memory):
_name = 'survey.send.invitation'
_columns = {
'partner_ids': fields.many2many('res.partner','survey_res_partner','partner_id',\
'survey_id', "Answer", required=1),
'send_mail': fields.boolean('Send Mail for New User'),
'send_mail_existing': fields.boolean('Send Reminder for Existing User'),
'mail_subject': fields.char('Subject', size=256),
'mail_subject_existing': fields.char('Subject', size=256),
'mail_from': fields.char('From', size=256, required=1),
'mail': fields.text('Body')
}
_defaults = {
'send_mail': lambda *a: 1,
'send_mail_existing': lambda *a: 1,
}
def genpasswd(self):
chars = string.letters + string.digits
return ''.join([choice(chars) for i in range(6)])
def default_get(self, cr, uid, fields_list, context=None):
if context is None:
context = {}
data = super(survey_send_invitation, self).default_get(cr, uid, fields_list, context)
survey_obj = self.pool.get('survey')
msg = ""
name = ""
for sur in survey_obj.browse(cr, uid, context.get('active_ids', []), context=context):
name += "\n --> " + sur.title + "\n"
if sur.state != 'open':
msg += sur.title + "\n"
data['mail_subject'] = _("Invitation for %s") % (sur.title)
data['mail_subject_existing'] = _("Invitation for %s") % (sur.title)
data['mail_from'] = sur.responsible_id.email
if msg:
raise osv.except_osv(_('Warning!'), _('The following surveys are not in open state: %s') % msg)
data['mail'] = _('''
Hello %%(name)s, \n\n
Would you please spent some of your time to fill-in our survey: \n%s\n
You can access this survey with the following parameters:
URL: %s
Your login ID: %%(login)s\n
Your password: %%(passwd)s\n
\n\n
Thanks,''') % (name, self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='http://localhost:8069', context=context))
return data
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False):
if not report_name or not res_ids:
return (False, Exception('Report name and Resources ids are required !!!'))
try:
ret_file_name = get_module_resource('survey', 'report') + file_name + '.pdf'
result, format = openerp.report.render_report(cr, uid, res_ids, report_name[len('report.'):], {}, {})
fp = open(ret_file_name, 'wb+');
fp.write(result);
fp.close();
except Exception,e:
print 'Exception in create report:',e
return (False, str(e))
return (True, ret_file_name)
def action_send(self, cr, uid, ids, context=None):
if context is None:
context = {}
record = self.read(cr, uid, ids, [],context=context)
survey_ids = context.get('active_ids', [])
record = record and record[0]
partner_ids = record['partner_ids']
user_ref= self.pool.get('res.users')
survey_ref= self.pool.get('survey')
mail_message = self.pool.get('mail.message')
model_data_obj = self.pool.get('ir.model.data')
group_id = model_data_obj._get_id(cr, uid, 'base', 'group_survey_user')
group_id = model_data_obj.browse(cr, uid, group_id, context=context).res_id
act_id = self.pool.get('ir.actions.act_window')
act_id = act_id.search(cr, uid, [('res_model', '=' , 'survey.name.wiz'), \
('view_type', '=', 'form')])
out = "login,password\n"
skipped = 0
existing = ""
created = ""
error = ""
new_user = []
attachments = {}
current_sur = survey_ref.browse(cr, uid, context.get('active_id'), context=context)
exist_user = current_sur.invited_user_ids
if exist_user:
for use in exist_user:
new_user.append(use.id)
for id in survey_ref.browse(cr, uid, survey_ids):
report = self.create_report(cr, uid, [id.id], 'report.survey.form', id.title)
file = open(get_module_resource('survey', 'report') + id.title +".pdf")
file_data = ""
while 1:
line = file.readline()
file_data += line
if not line:
break
file.close()
attachments[id.title +".pdf"] = file_data
os.remove(get_module_resource('survey', 'report') + id.title +".pdf")
for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids):
if not partner.email:
skipped+= 1
continue
user = user_ref.search(cr, uid, [('login', "=", partner.email)])
if user:
if user[0] not in new_user:
new_user.append(user[0])
user = user_ref.browse(cr, uid, user[0])
user_ref.write(cr, uid, user.id, {'survey_id':[[6, 0, survey_ids]]})
mail = record['mail']%{'login':partner.email, 'passwd':user.password, \
'name' : partner.name}
if record['send_mail_existing']:
vals = {
'state': 'outgoing',
'subject': record['mail_subject_existing'],
'body_html': '<pre>%s</pre>' % 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': '<pre>%s</pre>' % 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]]
}
create_ctx = dict(context, no_reset_password=True)
user = user_ref.create(cr, uid, res_data, context=create_ctx)
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
}
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
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -1,74 +0,0 @@
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Survey send invitation Form View -->
<record id="view_survey_send_invitation" model="ir.ui.view">
<field name="name">Send Invitation</field>
<field name="model">survey.send.invitation</field>
<field name="arch" type="xml">
<form string="Send Invitation" version="7.0">
<group col="4">
<separator string="Select Partner" colspan="4"/>
<field name="partner_ids" nolabel="1" colspan="4" widget="many2many_tags"/>
<separator colspan="4" string="Send Mail for New User"/>
<field name="send_mail" nolabel="1"/>
<field name="mail_subject" colspan="3"/>
<separator colspan="4" string="Send Reminder for Existing User"/>
<field name="send_mail_existing" nolabel="1"/>
<field name="mail_subject_existing" colspan="3"/>
<separator colspan="4"/>
<field name="mail_from" colspan="4"/>
<separator string="Message" colspan="4"/>
<field name="mail" nolabel="1" colspan="4"/>
</group>
<footer>
<button name="action_send" string="_Send" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Survey send invitation action -->
<record id="action_view_survey_send_invitation" model="ir.actions.act_window">
<field name="name">Send Invitation</field>
<field name="res_model">survey.send.invitation</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<act_window id="action_act_view_survey_send_invitation"
key2="client_action_multi" name="Send Invitations"
res_model="survey.send.invitation" src_model="survey"
view_mode="form" target="new" view_type="form" />
<!-- Survey send invitation Display Log Form View -->
<record id="view_survey_send_invitation_log" model="ir.ui.view">
<field name="name">survey send invitation log</field>
<field name="model">survey.send.invitation.log</field>
<field name="arch" type="xml">
<form string="User creation" version="7.0">
<group string="Results :">
<field name="note"/>
</group>
</form>
</field>
</record>
<!-- Survey send invitation action -->
<record id="action_view_survey_send_invitation_log" model="ir.actions.act_window">
<field name="name">survey.send.invitation.log</field>
<field name="res_model">survey.send.invitation.log</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
+22
View File
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import survey
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -19,31 +19,23 @@
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
class survey_print_statistics(osv.osv_memory):
_name = 'survey.print.statistics'
_columns = {
'survey_ids': fields.many2many('survey', string="Survey", required="1"),
}
def action_next(self, cr, uid, ids, context=None):
"""
Print Survey Statistics in pdf format.
"""
if context is None:
context = {}
datas = {'ids': context.get('active_ids', [])}
res = self.read(cr, uid, ids, ['survey_ids'], context=context)
res = res and res[0] or {}
datas['form'] = res
datas['model'] = 'survey.print.statistics'
return {
'type': 'ir.actions.report.xml',
'report_name': 'survey.analysis',
'datas': datas,
}
{
'name': 'Survey CRM',
'version': '2.0',
'category': 'Marketing',
'complexity': 'easy',
'description': """
Survey - CRM (bridge module)
=================================================================================
This module adds a Survey mass mailing button inside the more option of lead/customers views
""",
'author': 'OpenERP SA',
'depends': ['crm', 'survey'],
'data': [
'crm_view.xml',
],
'installable': True,
'auto_install': True
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Replace the default mass-mailing wizard in base with the composition wizard -->
<act_window name="Partner Survey Mailing"
res_model="survey.mail.compose.message"
src_model="crm.lead"
view_mode="form"
multi="True"
target="new"
key2="client_action_multi"
id="survey.action_partner_survey_mail_crm"
context="{
'default_use_template': True,
'default_template_id': ref('survey.email_template_survey'),
}" />
</data>
</openerp>
+43
View File
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import osv
class survey_mail_compose_message(osv.TransientModel):
_inherit = 'survey.mail.compose.message'
def default_get(self, cr, uid, fields, context=None):
res = super(survey_mail_compose_message, self).default_get(cr, uid, fields, context=context)
if context.get('active_model') == 'crm.lead' and context.get('active_ids'):
partner_ids = []
emails_list = []
for lead in self.pool.get('crm.lead').browse(cr, uid, context.get('active_ids'), context=context):
if lead.partner_id:
partner_ids.append(lead.partner_id.id)
else:
email = lead.contact_name and "%s <%s>" % (lead.contact_name, lead.email_from or "") or lead.email_from or None
if email and email not in emails_list:
emails_list.append(email)
multi_email = "\n".join(emails_list)
res.update({'partner_ids': list(set(partner_ids)), 'multi_email': multi_email})
return res