2010-01-20 14:28:28 +00:00
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
2013-10-21 09:03:19 +00:00
# Copyright (C) 2004-TODAY OpenERP S.A. <http: //www.openerp.com>
2010-01-20 14:28:28 +00:00
#
2013-10-21 09:03:19 +00:00
# This program is free software: you can redistribute it and / or modify
2010-12-08 13:59:16 +00:00
# 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.
2010-01-20 14:28:28 +00:00
#
# 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
2010-12-08 13:59:16 +00:00
# GNU Affero General Public License for more details.
2010-01-20 14:28:28 +00:00
#
2010-12-08 13:59:16 +00:00
# You should have received a copy of the GNU Affero General Public License
2013-10-21 09:03:19 +00:00
# along with this program. If not, see <http: //www.gnu.org/licenses/>.
2010-01-20 14:28:28 +00:00
#
##############################################################################
2012-12-06 14:56:32 +00:00
import copy
2013-10-21 09:03:19 +00:00
from urllib import urlencode
from urlparse import urljoin
2010-09-29 08:05:01 +00:00
from datetime import datetime
2012-12-06 14:56:32 +00:00
from openerp . osv import fields , osv
from openerp . tools . translate import _
2013-10-21 09:03:19 +00:00
import uuid
from openerp import SUPERUSER_ID
2013-10-22 15:10:51 +00:00
# TO BE REMOVED
# class survey_type(osv.osv):
# _name = 'survey.type'
# _description = 'Survey Type'
# _columns = {
# 'name': fields.char("Name", size=128, required=1, translate=True),
# }
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2012-12-06 14:56:32 +00:00
2010-01-27 13:55:23 +00:00
2010-01-20 14:28:28 +00:00
class survey ( osv . osv ) :
2013-10-22 15:10:51 +00:00
''' Settings for a multi-page/multi-question survey.
Each survey can have one or more attached pages , and each page can present
one or more questions .
'''
_name = ' survey.survey '
2010-01-20 14:28:28 +00:00
_description = ' Survey '
_rec_name = ' title '
2013-10-21 09:03:19 +00:00
_inherit = [ ' mail.thread ' , ' ir.needaction_mixin ' ]
2010-01-27 13:55:23 +00:00
2013-10-22 15:10:51 +00:00
# Protected methods #
2013-10-21 09:03:19 +00:00
def _needaction_domain_get ( self , cr , uid , context = None ) :
user_browse = self . pool . get ( ' res.users ' ) . browse ( cr , SUPERUSER_ID , uid , context = context )
model , group_id = self . pool . get ( ' ir.model.data ' ) . get_object_reference ( cr , uid , ' base ' , ' group_survey_manager ' )
if group_id in [ x . id for x in user_browse . groups_id ] :
return [ ' & ' , ( ' response_ids.state ' , ' in ' , [ ' new ' , ' skip ' ] ) , ( ' response_ids.partner_id.user_id ' , ' = ' , uid ) ]
else :
return [ ]
def _get_tot_start_survey ( self , cr , uid , ids , name , arg , context = None ) :
""" Compute if the message is unread by the current user. """
res = dict ( ( id , 0 ) for id in ids )
sur_res_obj = self . pool . get ( ' survey.response ' )
for id in ids :
res [ id ] = sur_res_obj . search ( cr , SUPERUSER_ID , [ ( ' survey_id ' , ' = ' , id ) , ( ' state ' , ' = ' , ' skip ' ) ] , context = context , count = True )
return res
def _get_tot_comp_survey ( self , cr , uid , ids , name , arg , context = None ) :
""" Compute if the message is unread by the current user. """
res = dict ( ( id , 0 ) for id in ids )
sur_res_obj = self . pool . get ( ' survey.response ' )
for id in ids :
res [ id ] = sur_res_obj . search ( cr , SUPERUSER_ID , [ ( ' survey_id ' , ' = ' , id ) , ( ' state ' , ' = ' , ' done ' ) ] , context = context , count = True )
return res
def _get_public_url ( self , cr , uid , ids , name , arg , context = None ) :
""" Compute if the message is unread by the current user. """
res = dict ( ( id , 0 ) for id in ids )
base_url = self . pool . get ( ' ir.config_parameter ' ) . get_param ( cr , uid , ' web.base.url ' )
survey_obj = self . pool . get ( ' survey ' )
for survey_browse in survey_obj . browse ( cr , uid , ids , context = context ) :
query = {
' db ' : cr . dbname
}
fragment = {
' active_id ' : survey_browse . id ,
' action ' : ' survey.action_filling ' ,
' params ' : survey_browse . token ,
}
res [ survey_browse . id ] = urljoin ( base_url , " ? %s # %s " % ( urlencode ( query ) , urlencode ( fragment ) ) )
return res
2010-01-27 13:55:23 +00:00
2013-10-22 15:10:51 +00:00
# Model fields #
2010-01-20 14:28:28 +00:00
_columns = {
2013-10-21 09:03:19 +00:00
' title ' : fields . char ( ' Survey Title ' , size = 128 , required = 1 , translate = True ) ,
2013-10-22 15:10:51 +00:00
' category ' : fields . char ( ' Category ' , size = 128 , translate = True ) ,
' page_ids ' : fields . one2many ( ' survey.page ' , ' survey_id ' , ' Pages ' ) ,
' date_open ' : fields . datetime ( ' Survey Opening Date ' , readonly = 1 ) , #TODO purpose ?
' date_close ' : fields . datetime ( ' Survey Closing Date ' , readonly = 1 ) , #TODO purpose ?
' max_response_limit ' : fields . integer ( ' Maximum Answer Limit ' ,
help = " Set to one if survey is answerable only once " ) , #TODO field name not expressive
' state ' : fields . selection (
[ ( ' draft ' , ' Draft ' ) , ( ' open ' , ' Open ' ) , ( ' close ' , ' Closed ' ) ,
( ' cancel ' , ' Cancelled ' ) ] , ' Status ' , required = 1 , readonly = 1 ,
translate = 1 ) ,
' visible_to_user ' : fields . boolean ( ' Visible in the survey menu ' ,
help = " If checked, survey users can see this survey in the kanban view. " ) ,
2013-10-21 09:03:19 +00:00
' authenticate ' : fields . boolean ( ' A login is required ' , help = " If checked, users who click on the public web link will be redirected to a login page where they must provide a login name and password. If unchecked, they may complete the survey directly. " ) ,
' tot_start_survey ' : fields . function ( _get_tot_start_survey , string = " Total Started Survey " , type = " integer " ) ,
' tot_comp_survey ' : fields . function ( _get_tot_comp_survey , string = " Total Completed Survey " , type = " integer " ) ,
' note ' : fields . text ( ' Description ' , size = 128 , translate = True ) ,
2010-03-26 13:27:16 +00:00
' type ' : fields . many2one ( ' survey.type ' , ' Type ' ) ,
2012-07-05 12:43:05 +00:00
' color ' : fields . integer ( ' Color Index ' ) ,
2013-10-21 09:03:19 +00:00
' response_ids ' : fields . one2many ( ' survey.response ' , ' survey_id ' , ' Responses ' , readonly = 1 ) ,
' public_url ' : fields . function ( _get_public_url , string = " Public web link " , type = " char " ) ,
' token ' : fields . char ( ' Public token ' , size = 8 , required = 1 ) ,
' email_template_id ' : fields . many2one ( ' email.template ' , ' Email Template ' , ondelete = ' set null ' ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2013-10-22 15:10:51 +00:00
' state ' : ' draft ' ,
2013-10-21 09:03:19 +00:00
' visible_to_user ' : True ,
' authenticate ' : True ,
2012-10-23 22:33:58 +00:00
' date_open ' : fields . datetime . now ,
2013-10-21 09:03:19 +00:00
' token ' : lambda s , cr , uid , c : uuid . uuid4 ( ) ,
2010-01-20 14:28:28 +00:00
}
2013-10-22 15:10:51 +00:00
# Public methods #
2013-10-21 09:03:19 +00:00
def survey_draft ( self , cr , uid , ids , arg ) :
return self . write ( cr , uid , ids , { ' state ' : ' draft ' , ' date_open ' : None } )
2010-01-20 14:28:28 +00:00
def survey_open ( self , cr , uid , ids , arg ) :
2013-10-21 09:03:19 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' open ' , ' date_open ' : datetime . now ( ) } )
2010-01-20 14:28:28 +00:00
def survey_close ( self , cr , uid , ids , arg ) :
2013-10-21 09:03:19 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' close ' , ' date_close ' : datetime . now ( ) } )
2010-01-20 14:28:28 +00:00
def survey_cancel ( self , cr , uid , ids , arg ) :
2013-10-21 09:03:19 +00:00
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' , ' date_close ' : datetime . now ( ) } )
2011-08-03 06:32:01 +00:00
2010-12-14 07:37:12 +00:00
def copy ( self , cr , uid , ids , default = None , context = None ) :
2010-12-09 05:36:29 +00:00
vals = { }
current_rec = self . read ( cr , uid , ids , context = context )
2012-09-24 16:26:45 +00:00
title = _ ( " %s (copy) " ) % ( current_rec . get ( ' title ' ) )
2013-10-21 09:03:19 +00:00
vals . update ( { ' title ' : title } )
2010-12-09 05:36:29 +00:00
return super ( survey , self ) . copy ( cr , uid , ids , vals , context = context )
2010-02-05 11:25:40 +00:00
2010-04-08 06:00:47 +00:00
def action_print_survey ( self , cr , uid , ids , context = None ) :
"""
If response is available then print this response otherwise print survey form ( print template of the survey ) .
@param self : The object pointer
@param cr : the current row , from the database cursor ,
2013-10-21 09:03:19 +00:00
@param uid : the current user ’ s ID forsecurity checks ,
2010-04-08 06:00:47 +00:00
@param ids : List of Survey IDs
2013-10-21 09:03:19 +00:00
@param context : A standard dictionary forcontextual values
@return : Dictionary value forprint survey form .
2010-04-08 06:00:47 +00:00
"""
2013-10-21 09:03:19 +00:00
page_setting = { ' orientation ' : ' vertical ' , ' without_pagebreak ' : 0 , ' paper_size ' : ' letter ' , ' page_number ' : 1 , ' survey_title ' : 1 }
2010-11-23 07:05:05 +00:00
if context is None :
2010-04-08 06:00:47 +00:00
context = { }
datas = { }
2013-10-21 09:03:19 +00:00
response_id = None
2010-04-09 11:22:38 +00:00
if ' response_id ' in context :
response_id = context . get ( ' response_id ' , 0 )
datas [ ' ids ' ] = [ context . get ( ' survey_id ' , 0 ) ]
2013-10-21 09:03:19 +00:00
elif ' print_response ' in context :
response_id = self . pool . get ( ' survey.response ' ) . search ( cr , uid , [ ( ' survey_id ' , ' = ' , ids ) ] , context = context )
2010-04-09 11:22:38 +00:00
datas [ ' ids ' ] = ids
2010-04-08 06:00:47 +00:00
report = { }
2010-04-09 11:22:38 +00:00
if response_id and response_id [ 0 ] :
2010-04-08 06:00:47 +00:00
context . update ( { ' survey_id ' : datas [ ' ids ' ] } )
datas [ ' form ' ] = page_setting
datas [ ' model ' ] = ' survey.print.answer '
report = {
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.browse.response ' ,
' datas ' : datas ,
2013-10-21 09:03:19 +00:00
' context ' : context ,
' nodestroy ' : True ,
2010-04-08 06:00:47 +00:00
}
else :
datas [ ' form ' ] = page_setting
datas [ ' model ' ] = ' survey.print '
report = {
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.form ' ,
' datas ' : datas ,
2013-10-21 09:03:19 +00:00
' context ' : context ,
' nodestroy ' : True ,
2010-04-08 06:00:47 +00:00
}
return report
2012-09-24 16:26:45 +00:00
2013-10-21 09:03:19 +00:00
def print_statistics ( self , cr , uid , ids , context = None ) :
"""
Print Survey Statistics in pdf format .
"""
return {
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.analysis ' ,
' datas ' : {
' model ' : ' survey.print.statistics ' ,
' ids ' : [ ] ,
' form ' : {
' id ' : None ,
' survey_ids ' : ids
} ,
} ,
}
def _check_valid ( self , cr , uid , ids , context = None ) :
for survey in self . browse ( cr , SUPERUSER_ID , ids , context = context ) :
if not survey . page_ids or not [ page . question_ids for page in survey . page_ids if page . question_ids ] :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' This survey has no question defined or has no pages defined. ' ) )
def action_fill_survey ( self , cr , uid , ids , context = None ) :
id = ids [ 0 ]
survey = self . browse ( cr , uid , id , context = context )
context . update ( { ' edit ' : False , ' survey_id ' : id , ' survey_token ' : survey . token , ' ir_actions_act_window_target ' : ' inline ' } )
2012-04-17 05:50:10 +00:00
return {
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
' res_model ' : ' survey.question.wiz ' ,
' type ' : ' ir.actions.act_window ' ,
2013-10-21 09:03:19 +00:00
' target ' : ' inline ' ,
' name ' : survey . title ,
2012-08-21 05:36:25 +00:00
' context ' : context
}
2013-10-21 09:03:19 +00:00
def action_test_survey ( self , cr , uid , ids , context = None ) :
context . update ( { ' survey_test ' : True } )
return self . action_fill_survey ( cr , uid , ids , context = context )
def action_edit_survey ( self , cr , uid , ids , context = None ) :
id = ids [ 0 ]
context . update ( {
' survey_id ' : id ,
' edit ' : True ,
' ir_actions_act_window_target ' : ' new ' ,
} )
2012-10-11 09:36:46 +00:00
return {
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
' res_model ' : ' survey.question.wiz ' ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
2013-10-21 09:03:19 +00:00
' name ' : self . browse ( cr , uid , id , context = context ) . title ,
2012-10-11 09:36:46 +00:00
' context ' : context
}
2013-10-21 09:03:19 +00:00
def action_survey_sent ( self , cr , uid , ids , context = None ) :
'''
This function opens a window to compose an email , with the survey template message loaded by default
'''
self . _check_valid ( cr , uid , ids , context = context )
survey_browse = self . pool . get ( ' survey ' ) . browse ( cr , uid , ids , context = context ) [ 0 ]
if survey_browse . state != " open " :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " You cannot send invitations because the survey is not open. " ) )
assert len ( ids ) == 1 , ' This option should only be used for a single id at a time. '
ir_model_data = self . pool . get ( ' ir.model.data ' )
try :
template_id = ir_model_data . get_object_reference ( cr , uid , ' survey ' , ' email_template_survey ' ) [ 1 ]
except ValueError :
template_id = False
ctx = dict ( context )
ctx . update ( {
' default_model ' : ' survey ' ,
' default_res_id ' : ids [ 0 ] ,
' default_survey_id ' : ids [ 0 ] ,
' default_use_template ' : bool ( template_id ) ,
' default_template_id ' : template_id ,
' default_composition_mode ' : ' comment ' ,
' survey_state ' : survey_browse . state
} )
2012-08-21 05:36:25 +00:00
return {
2013-10-21 09:03:19 +00:00
' type ' : ' ir.actions.act_window ' ,
2012-08-21 05:36:25 +00:00
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
2013-10-21 09:03:19 +00:00
' res_model ' : ' survey.mail.compose.message ' ,
2012-08-21 05:36:25 +00:00
' target ' : ' new ' ,
2013-10-21 09:03:19 +00:00
' context ' : ctx ,
2012-04-17 05:50:10 +00:00
}
2012-10-11 09:36:46 +00:00
2013-10-21 09:03:19 +00:00
def unlink ( self , cr , uid , ids , context = None ) :
email_template_ids = list ( )
for survey in self . browse ( cr , uid , ids , context = context ) :
email_template_ids . append ( survey . email_template_id . id )
if email_template_ids :
self . pool . get ( ' email.template ' ) . unlink ( cr , uid , email_template_ids , context = context )
return super ( survey , self ) . unlink ( cr , uid , ids , context = context )
2010-01-20 14:28:28 +00:00
2013-10-22 15:10:51 +00:00
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2010-01-20 14:28:28 +00:00
class survey_page ( osv . osv ) :
_name = ' survey.page '
_description = ' Survey Pages '
_rec_name = ' title '
_order = ' sequence '
_columns = {
2013-10-21 09:03:19 +00:00
' title ' : fields . char ( ' Page Title ' , size = 128 , required = 1 , translate = True ) ,
2010-03-26 13:27:16 +00:00
' survey_id ' : fields . many2one ( ' survey ' , ' Survey ' , ondelete = ' cascade ' ) ,
2012-07-10 11:07:40 +00:00
' question_ids ' : fields . one2many ( ' survey.question ' , ' page_id ' , ' Questions ' ) ,
2010-03-26 13:27:16 +00:00
' sequence ' : fields . integer ( ' Page Nr ' ) ,
2013-10-21 09:03:19 +00:00
' note ' : fields . text ( ' Description ' , translate = True ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2013-10-21 09:03:19 +00:00
' sequence ' : 1
2010-01-20 14:28:28 +00:00
}
2010-11-22 10:37:53 +00:00
def default_get ( self , cr , uid , fields , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-01-20 14:28:28 +00:00
data = super ( survey_page , self ) . default_get ( cr , uid , fields , context )
2013-10-21 09:03:19 +00:00
if context . get ( ' survey_id ' ) :
2011-01-18 11:54:45 +00:00
data [ ' survey_id ' ] = context . get ( ' survey_id ' , False )
2010-01-20 14:28:28 +00:00
return data
2010-11-22 10:37:53 +00:00
def survey_save ( self , cr , uid , ids , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2013-10-21 09:03:19 +00:00
surv_name_wiz = self . pool . get ( ' survey.question.wiz ' )
surv_name_wiz . write ( cr , uid , [ context . get ( ' wizard_id ' , False ) ] , { ' transfer ' : True , ' page_no ' : context . get ( ' page_number ' , 0 ) } )
2010-01-20 14:28:28 +00:00
return {
2010-04-06 07:02:31 +00:00
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
' res_model ' : ' survey.question.wiz ' ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
' context ' : context
}
2010-01-20 14:28:28 +00:00
2010-12-14 07:37:12 +00:00
def copy ( self , cr , uid , ids , default = None , context = None ) :
2010-12-09 05:36:29 +00:00
vals = { }
current_rec = self . read ( cr , uid , ids , context = context )
2012-09-24 16:26:45 +00:00
title = _ ( " %s (copy) " ) % ( current_rec . get ( ' title ' ) )
2013-10-21 09:03:19 +00:00
vals . update ( { ' title ' : title } )
2010-12-09 05:36:29 +00:00
return super ( survey_page , self ) . copy ( cr , uid , ids , vals , context = context )
2010-02-05 11:25:40 +00:00
2010-01-20 14:28:28 +00:00
2013-10-22 15:10:51 +00:00
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2010-01-20 14:28:28 +00:00
class survey_question ( osv . osv ) :
_name = ' survey.question '
_description = ' Survey Question '
_rec_name = ' question '
_order = ' sequence '
2010-11-22 10:37:53 +00:00
def _calc_response ( self , cr , uid , ids , field_name , arg , context = None ) :
2010-01-20 14:28:28 +00:00
if len ( ids ) == 0 :
return { }
val = { }
2010-03-26 13:27:16 +00:00
cr . execute ( " select question_id, count(id) as Total_response from \
2010-06-10 13:34:19 +00:00
survey_response_line where state = ' done ' and question_id IN % s \
2013-10-21 09:03:19 +00:00
group by question_id " , (tuple(ids), ))
2010-01-20 14:28:28 +00:00
ids1 = copy . deepcopy ( ids )
2013-10-21 09:03:19 +00:00
for rec in cr . fetchall ( ) :
2010-01-20 14:28:28 +00:00
ids1 . remove ( rec [ 0 ] )
val [ rec [ 0 ] ] = int ( rec [ 1 ] )
for id in ids1 :
val [ id ] = 0
return val
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
_columns = {
2013-10-21 09:03:19 +00:00
' page_id ' : fields . many2one ( ' survey.page ' , ' Survey Page ' , ondelete = ' cascade ' ) ,
' question ' : fields . char ( ' Question ' , required = 1 , translate = True ) ,
2010-03-26 13:27:16 +00:00
' answer_choice_ids ' : fields . one2many ( ' survey.answer ' , ' question_id ' , ' Answer ' ) ,
2010-05-11 09:00:24 +00:00
' is_require_answer ' : fields . boolean ( ' Require Answer to Question ' ) ,
2013-10-21 09:03:19 +00:00
' required_type ' : fields . selection ( [ ( ' all ' , ' All ' ) , ( ' at least ' , ' At Least ' ) , ( ' at most ' , ' At Most ' ) , ( ' exactly ' , ' Exactly ' ) , ( ' a range ' , ' A Range ' ) ] , ' Respondent must answer ' ) ,
2010-03-26 13:27:16 +00:00
' req_ans ' : fields . integer ( ' #Required Answer ' ) ,
' maximum_req_ans ' : fields . integer ( ' Maximum Required Answer ' ) ,
' minimum_req_ans ' : fields . integer ( ' Minimum Required Answer ' ) ,
2013-10-21 09:03:19 +00:00
' req_error_msg ' : fields . text ( ' Error Message ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' allow_comment ' : fields . boolean ( ' Allow Comment Field ' ) ,
' sequence ' : fields . integer ( ' Sequence ' ) ,
2013-10-21 09:03:19 +00:00
' tot_resp ' : fields . function ( _calc_response , type = " integer " , string = " Total Answer " ) ,
' survey_id ' : fields . related ( ' page_id ' , ' survey_id ' , type = ' many2one ' , relation = ' survey ' , string = ' Survey ' , store = True ) ,
' descriptive_text ' : fields . text ( ' Descriptive Text ' , translate = True ) ,
' column_heading_ids ' : fields . one2many ( ' survey.question.column.heading ' , ' question_id ' , ' Column heading ' ) ,
' type ' : fields . selection ( [ ( ' multiple_choice_only_one_ans ' , ' Multiple Choice (Only One Answer) ' ) ,
( ' multiple_choice_multiple_ans ' , ' Multiple Choice (Multiple Answer) ' ) ,
2013-10-22 15:10:51 +00:00
( ' matrix_of_choices_only_one_ans ' , ' Matrix of Choices (Only One Answers Per Row) ' ) , # TDE: replace with matrix that is a container
( ' matrix_of_choices_only_multi_ans ' , ' Matrix of Choices (Multiple Answers Per Row) ' ) , # TDE: replace with matrix that is a container
2013-10-21 09:03:19 +00:00
( ' rating_scale ' , ' Rating Scale ' ) ,
( ' single_textbox ' , ' Single Textbox ' ) ,
2013-10-22 15:10:51 +00:00
( ' multiple_textboxes ' , ' Multiple Textboxes ' ) , # interest ? TDE: should be dropped -> comment box
( ' multiple_textboxes_diff_type ' , ' Multiple Textboxes With Different Type ' ) , # interest ? TDE: should be dropped -> comment box
2013-10-21 09:03:19 +00:00
( ' comment ' , ' Comment/Essay Box ' ) ,
( ' numerical_textboxes ' , ' Numerical Textboxes ' ) ,
( ' date ' , ' Date ' ) ,
2013-10-22 15:10:51 +00:00
( ' date_and_time ' , ' Date and Time ' ) , # TDE: rename datetime ^^
( ' descriptive_text ' , ' Descriptive Text ' ) , # TDE: rename free text
( ' table ' , ' Table ' ) , # TDE: drop
2013-10-21 09:03:19 +00:00
] , ' Question Type ' , required = 1 , ) ,
2010-05-11 09:00:24 +00:00
' is_comment_require ' : fields . boolean ( ' Add Comment Field ' ) ,
2013-10-21 09:03:19 +00:00
' comment_label ' : fields . char ( ' Field Label ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' comment_field_type ' : fields . selection ( [ ( ' char ' , ' Single Line Of Text ' ) , ( ' text ' , ' Paragraph of Text ' ) ] , ' Comment Field Type ' ) ,
' comment_valid_type ' : fields . selection ( [ ( ' do_not_validate ' , ''' Don ' t Validate Comment Text. ''' ) ,
2010-04-06 07:02:31 +00:00
( ' must_be_specific_length ' , ' Must Be Specific Length ' ) ,
( ' must_be_whole_number ' , ' Must Be A Whole Number ' ) ,
( ' must_be_decimal_number ' , ' Must Be A Decimal Number ' ) ,
( ' must_be_date ' , ' Must Be A Date ' ) ,
( ' must_be_email_address ' , ' Must Be An Email Address ' ) ,
] , ' Text Validation ' ) ,
2010-03-26 13:27:16 +00:00
' comment_minimum_no ' : fields . integer ( ' Minimum number ' ) ,
' comment_maximum_no ' : fields . integer ( ' Maximum number ' ) ,
' comment_minimum_float ' : fields . float ( ' Minimum decimal number ' ) ,
' comment_maximum_float ' : fields . float ( ' Maximum decimal number ' ) ,
' comment_minimum_date ' : fields . date ( ' Minimum date ' ) ,
' comment_maximum_date ' : fields . date ( ' Maximum date ' ) ,
2013-10-21 09:03:19 +00:00
' comment_valid_err_msg ' : fields . text ( ' Error message ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' make_comment_field ' : fields . boolean ( ' Make Comment Field an Answer Choice ' ) ,
2013-10-21 09:03:19 +00:00
' make_comment_field_err_msg ' : fields . text ( ' Error message ' , translate = True ) ,
2010-05-11 09:00:24 +00:00
' is_validation_require ' : fields . boolean ( ' Validate Text ' ) ,
2013-10-21 09:03:19 +00:00
' validation_type ' : fields . selection ( [ ( ' do_not_validate ' , ''' Don ' t Validate Comment Text. ''' ) , \
( ' must_be_specific_length ' , ' Must Be Specific Length ' ) , \
( ' must_be_whole_number ' , ' Must Be A Whole Number ' ) , \
( ' must_be_decimal_number ' , ' Must Be A Decimal Number ' ) , \
( ' must_be_date ' , ' Must Be A Date ' ) , \
2010-04-06 07:02:31 +00:00
( ' must_be_email_address ' , ' Must Be An Email Address ' ) \
] , ' Text Validation ' ) ,
2010-03-26 13:27:16 +00:00
' validation_minimum_no ' : fields . integer ( ' Minimum number ' ) ,
' validation_maximum_no ' : fields . integer ( ' Maximum number ' ) ,
' validation_minimum_float ' : fields . float ( ' Minimum decimal number ' ) ,
' validation_maximum_float ' : fields . float ( ' Maximum decimal number ' ) ,
' validation_minimum_date ' : fields . date ( ' Minimum date ' ) ,
' validation_maximum_date ' : fields . date ( ' Maximum date ' ) ,
2013-10-21 09:03:19 +00:00
' validation_valid_err_msg ' : fields . text ( ' Error message ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' numeric_required_sum ' : fields . integer ( ' Sum of all choices ' ) ,
2013-10-21 09:03:19 +00:00
' numeric_required_sum_err_msg ' : fields . text ( ' Error message ' , translate = True ) ,
2010-04-05 11:59:01 +00:00
' rating_allow_one_column_require ' : fields . boolean ( ' Allow Only One Answer per Column (Forced Ranking) ' ) ,
2010-03-26 13:27:16 +00:00
' in_visible_rating_weight ' : fields . boolean ( ' Is Rating Scale Invisible? ' ) ,
' in_visible_menu_choice ' : fields . boolean ( ' Is Menu Choice Invisible? ' ) ,
' in_visible_answer_type ' : fields . boolean ( ' Is Answer Type Invisible? ' ) ,
' comment_column ' : fields . boolean ( ' Add comment column in matrix ' ) ,
2013-10-21 09:03:19 +00:00
' column_name ' : fields . char ( ' Column Name ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' no_of_rows ' : fields . integer ( ' No of Rows ' ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2013-10-21 09:03:19 +00:00
' sequence ' : 1 ,
' page_id ' : lambda s , cr , uid , c : c . get ( ' page_id ' ) ,
' type ' : lambda s , cr , uid , c : _ ( ' multiple_choice_multiple_ans ' ) ,
' req_error_msg ' : lambda s , cr , uid , c : _ ( ' This question requires an answer. ' ) ,
' required_type ' : ' at least ' ,
' req_ans ' : 1 ,
' comment_field_type ' : ' char ' ,
' comment_label ' : lambda s , cr , uid , c : _ ( ' Other (please specify) ' ) ,
' comment_valid_type ' : ' do_not_validate ' ,
' comment_valid_err_msg ' : lambda s , cr , uid , c : _ ( ' The comment you entered is in an invalid format. ' ) ,
' validation_type ' : ' do_not_validate ' ,
' validation_valid_err_msg ' : lambda s , cr , uid , c : _ ( ' The comment you entered is in an invalid format. ' ) ,
' numeric_required_sum_err_msg ' : lambda s , cr , uid , c : _ ( ' The choices need to add up to [enter sum here]. ' ) ,
' make_comment_field_err_msg ' : lambda s , cr , uid , c : _ ( ' Please enter a comment. ' ) ,
' in_visible_answer_type ' : 1
2010-01-20 14:28:28 +00:00
}
def on_change_type ( self , cr , uid , ids , type , context = None ) :
2010-02-05 09:48:02 +00:00
val = { }
val [ ' is_require_answer ' ] = False
val [ ' is_comment_require ' ] = False
val [ ' is_validation_require ' ] = False
val [ ' comment_column ' ] = False
2010-03-15 10:52:27 +00:00
2010-02-04 10:20:01 +00:00
if type in [ ' multiple_textboxes_diff_type ' ] :
2010-02-05 09:48:02 +00:00
val [ ' in_visible_answer_type ' ] = False
return { ' value ' : val }
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if type in [ ' rating_scale ' ] :
2013-10-21 09:03:19 +00:00
val . update ( { ' in_visible_rating_weight ' : False , ' in_visible_menu_choice ' : True } )
2010-02-05 09:48:02 +00:00
return { ' value ' : val }
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
elif type in [ ' single_textbox ' ] :
2013-10-21 09:03:19 +00:00
val . update ( { ' in_visible_rating_weight ' : True , ' in_visible_menu_choice ' : True } )
2010-02-05 09:48:02 +00:00
return { ' value ' : val }
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
else :
2013-10-21 09:03:19 +00:00
val . update ( { ' in_visible_rating_weight ' : True , ' in_visible_menu_choice ' : True , \
' in_visible_answer_type ' : True } )
2010-02-05 09:48:02 +00:00
return { ' value ' : val }
2010-01-20 14:28:28 +00:00
2013-10-21 09:03:19 +00:00
def on_change_page_id ( self , cr , uid , ids , page_id , context = None ) :
if page_id :
page = self . pool . get ( ' survey.page ' ) . browse ( cr , uid , page_id , context = context )
return { ' survey_id ' : page . survey_id and page . survey_id . id }
return { ' value ' : { } }
2010-01-20 14:28:28 +00:00
def write ( self , cr , uid , ids , vals , context = None ) :
2013-10-22 15:10:51 +00:00
questions = self . read ( cr , uid , ids , [ ' answer_choice_ids ' , ' type ' ,
' required_type ' , ' req_ans ' , ' minimum_req_ans ' , ' maximum_req_ans ' ,
' column_heading_ids ' , ' page_id ' , ' question ' ] )
2010-01-20 14:28:28 +00:00
for question in questions :
col_len = len ( question [ ' column_heading_ids ' ] )
2013-10-21 09:03:19 +00:00
for col in vals . get ( ' column_heading_ids ' , [ ] ) :
if type ( col [ 2 ] ) == type ( { } ) :
col_len + = 1
else :
col_len - = 1
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
que_type = vals . get ( ' type ' , question [ ' type ' ] )
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
if que_type in [ ' matrix_of_choices_only_one_ans ' , ' matrix_of_choices_only_multi_ans ' , ' rating_scale ' ] :
2010-01-20 14:28:28 +00:00
if not col_len :
2013-10-21 09:03:19 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You must enter one or more column headings for question " %s " of page %s . ' ) % ( question [ ' question ' ] , question [ ' page_id ' ] [ 1 ] ) )
2010-01-20 14:28:28 +00:00
ans_len = len ( question [ ' answer_choice_ids ' ] )
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
for ans in vals . get ( ' answer_choice_ids ' , [ ] ) :
if type ( ans [ 2 ] ) == type ( { } ) :
ans_len + = 1
else :
ans_len - = 1
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
if que_type not in [ ' descriptive_text ' , ' single_textbox ' , ' comment ' , ' table ' ] :
2010-01-20 14:28:28 +00:00
if not ans_len :
2013-10-21 09:03:19 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You must enter one or more Answers for question " %s " of page %s . ' ) % ( question [ ' question ' ] , question [ ' page_id ' ] [ 1 ] ) )
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
req_type = vals . get ( ' required_type ' , question [ ' required_type ' ] )
2010-03-15 10:52:27 +00:00
2013-10-21 09:03:19 +00:00
if que_type in [ ' multiple_choice_multiple_ans ' , ' matrix_of_choices_only_one_ans ' , \
' matrix_of_choices_only_multi_ans ' , ' rating_scale ' , ' multiple_textboxes ' , \
' numerical_textboxes ' , ' date ' , ' date_and_time ' ] :
2010-01-27 13:55:23 +00:00
if req_type in [ ' at least ' , ' at most ' , ' exactly ' ] :
2013-10-21 09:03:19 +00:00
if ' req_ans ' in vals :
if not vals [ ' req_ans ' ] or vals [ ' req_ans ' ] > ans_len :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " #Required Answer you entered \
2010-03-26 13:27:16 +00:00
is greater than the number of answer . \
Please use a number that is smaller than % d . " ) % (ans_len + 1))
2010-01-27 13:55:23 +00:00
else :
2013-10-21 09:03:19 +00:00
if not question [ ' req_ans ' ] or question [ ' req_ans ' ] > ans_len :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " #Required Answer you entered is \
2010-03-26 13:27:16 +00:00
greater than the number of answer . \
Please use a number that is smaller than % d . " ) % (ans_len + 1))
2010-03-15 10:52:27 +00:00
2010-01-27 13:55:23 +00:00
if req_type == ' a range ' :
minimum_ans = 0
maximum_ans = 0
2013-10-21 09:03:19 +00:00
minimum_ans = ' minimum_req_ans ' in vals and vals [ ' minimum_req_ans ' ] or question [ ' minimum_req_ans ' ]
maximum_ans = ' maximum_req_ans ' in vals and vals [ ' maximum_req_ans ' ] or question [ ' maximum_req_ans ' ]
if not minimum_ans or minimum_ans > ans_len or not maximum_ans or maximum_ans > ans_len :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Minimum Required Answer you \
entered is greater than the number of answer . \
Please use a number that is smaller than % d . " ) % (ans_len + 1))
2010-01-27 13:55:23 +00:00
if maximum_ans < = minimum_ans :
2013-10-21 09:03:19 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Maximum Required Answer is greater \
2010-03-26 13:27:16 +00:00
than Minimum Required Answer " ))
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
return super ( survey_question , self ) . write ( cr , uid , ids , vals , context = context )
2010-11-22 10:37:53 +00:00
def create ( self , cr , uid , vals , context = None ) :
2013-10-21 09:03:19 +00:00
page = self . pool . get ( ' survey.page ' ) . browse ( cr , uid , ' page_id ' in vals and vals [ ' page_id ' ] or context [ ' page_id ' ] , context = context )
if ' answer_choice_ids ' in vals and not len ( vals . get ( ' answer_choice_ids ' , [ ] ) ) and \
vals . get ( ' type ' ) not in [ ' descriptive_text ' , ' single_textbox ' , ' comment ' , ' table ' ] :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You must enter one or more answers for question " %s " of page %s . ' ) % ( vals [ ' question ' ] , page . title ) )
if ' column_heading_ids ' in vals and not len ( vals . get ( ' column_heading_ids ' , [ ] ) ) and \
vals . get ( ' type ' ) in [ ' matrix_of_choices_only_one_ans ' , ' matrix_of_choices_only_multi_ans ' , ' rating_scale ' ] :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You must enter one or more column headings for question " %s " of page %s . ' ) % ( vals [ ' question ' ] , page . title ) )
if ' is_require_answer ' in vals and vals . get ( ' type ' ) in [ ' multiple_choice_multiple_ans ' , ' matrix_of_choices_only_one_ans ' , \
' matrix_of_choices_only_multi_ans ' , ' rating_scale ' , ' multiple_textboxes ' , ' numerical_textboxes ' , ' date ' , ' date_and_time ' ] :
if vals . get ( ' required_type ' ) in [ ' at least ' , ' at most ' , ' exactly ' ] :
if ' answer_choice_ids ' in vals and ' answer_choice_ids ' in vals and vals . get ( ' req_ans ' ) > len ( vals . get ( ' answer_choice_ids ' , [ ] ) ) :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " #Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d . " ) % ( len ( vals [ ' answer_choice_ids ' ] ) + 1 ) )
if vals . get ( ' required_type ' ) == ' a range ' :
if ' answer_choice_ids ' in vals :
if not vals . get ( ' minimum_req_ans ' ) or vals [ ' minimum_req_ans ' ] > len ( vals [ ' answer_choice_ids ' ] ) :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d . " ) % ( len ( vals [ ' answer_choice_ids ' ] ) + 1 ) )
if not vals . get ( ' maximum_req_ans ' ) or vals [ ' maximum_req_ans ' ] > len ( vals [ ' answer_choice_ids ' ] ) :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d . " ) % ( len ( vals [ ' answer_choice_ids ' ] ) + 1 ) )
if vals . get ( ' maximum_req_ans ' , 0 ) < = vals . get ( ' minimum_req_ans ' , 0 ) :
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( " Maximum Required Answer is greater than Minimum Required Answer. " ) )
return super ( survey_question , self ) . create ( cr , uid , vals , context )
2010-01-20 14:28:28 +00:00
2010-11-22 10:37:53 +00:00
def survey_save ( self , cr , uid , ids , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2013-10-21 09:03:19 +00:00
surv_name_wiz = self . pool . get ( ' survey.question.wiz ' )
surv_name_wiz . write ( cr , uid , [ context . get ( ' wizard_id ' , False ) ] , { ' transfer ' : True , ' page_no ' : context . get ( ' page_number ' , False ) } )
2010-01-20 14:28:28 +00:00
return {
2010-04-06 07:02:31 +00:00
' view_type ' : ' form ' ,
' view_mode ' : ' form ' ,
' res_model ' : ' survey.question.wiz ' ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
' context ' : context
}
2010-01-20 14:28:28 +00:00
2013-10-22 15:10:51 +00:00
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2010-01-20 14:28:28 +00:00
class survey_question_column_heading ( osv . osv ) :
_name = ' survey.question.column.heading '
_description = ' Survey Question Column Heading '
_rec_name = ' title '
2013-10-21 09:03:19 +00:00
_order = ' sequence '
2010-01-20 14:28:28 +00:00
2012-03-05 18:40:03 +00:00
def _get_in_visible_rating_weight ( self , cr , uid , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-04-06 07:02:31 +00:00
if context . get ( ' in_visible_rating_weight ' , False ) :
2010-01-20 14:28:28 +00:00
return context [ ' in_visible_rating_weight ' ]
return False
2013-10-21 09:03:19 +00:00
def _get_in_visible_menu_choice ( self , cr , uid , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-04-06 07:02:31 +00:00
if context . get ( ' in_visible_menu_choice ' , False ) :
2010-01-20 14:28:28 +00:00
return context [ ' in_visible_menu_choice ' ]
return False
_columns = {
2013-10-21 09:03:19 +00:00
' title ' : fields . char ( ' Column Heading ' , size = 128 , required = 1 , translate = True ) ,
' sequence ' : fields . integer ( ' Sequence ' ) ,
2010-03-26 13:27:16 +00:00
' menu_choice ' : fields . text ( ' Menu Choice ' ) ,
' rating_weight ' : fields . integer ( ' Weight ' ) ,
' question_id ' : fields . many2one ( ' survey.question ' , ' Question ' , ondelete = ' cascade ' ) ,
' in_visible_rating_weight ' : fields . boolean ( ' Is Rating Scale Invisible ?? ' ) ,
' in_visible_menu_choice ' : fields . boolean ( ' Is Menu Choice Invisible?? ' )
2010-01-20 14:28:28 +00:00
}
2013-10-21 09:03:19 +00:00
_defaults = {
' in_visible_rating_weight ' : _get_in_visible_rating_weight ,
' in_visible_menu_choice ' : _get_in_visible_menu_choice ,
2010-01-20 14:28:28 +00:00
}
2013-10-21 09:03:19 +00:00
2013-10-22 15:10:51 +00:00
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2010-01-20 14:28:28 +00:00
class survey_answer ( osv . osv ) :
_name = ' survey.answer '
_description = ' Survey Answer '
_rec_name = ' answer '
_order = ' sequence '
2010-11-22 10:37:53 +00:00
def _calc_response_avg ( self , cr , uid , ids , field_name , arg , context = None ) :
2010-01-20 14:28:28 +00:00
val = { }
2010-11-22 10:37:53 +00:00
for rec in self . browse ( cr , uid , ids , context = context ) :
2013-10-21 09:03:19 +00:00
cr . execute ( " select count(question_id), (select count(answer_id) \
2010-01-20 14:28:28 +00:00
from survey_response_answer sra , survey_response_line sa \
2013-10-21 09:03:19 +00:00
where sra . response_line_id = sa . id and sra . answer_id = % d \
2010-01-20 14:28:28 +00:00
and sa . state = ' done ' ) as tot_ans from survey_response_line \
where question_id = % d and state = ' done ' " \
% ( rec . id , rec . question_id . id ) )
res = cr . fetchone ( )
if res [ 0 ] :
avg = float ( res [ 1 ] ) * 100 / res [ 0 ]
else :
avg = 0.0
val [ rec . id ] = {
' response ' : res [ 1 ] ,
' average ' : round ( avg , 2 ) ,
}
return val
2012-03-05 18:40:03 +00:00
def _get_in_visible_answer_type ( self , cr , uid , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-04-06 07:02:31 +00:00
return context . get ( ' in_visible_answer_type ' , False )
2010-02-04 10:42:54 +00:00
2010-01-20 14:28:28 +00:00
_columns = {
2010-03-26 13:27:16 +00:00
' question_id ' : fields . many2one ( ' survey.question ' , ' Question ' , ondelete = ' cascade ' ) ,
2013-10-21 09:03:19 +00:00
' answer ' : fields . char ( ' Answer ' , size = 128 , required = 1 , translate = True ) ,
2010-03-26 13:27:16 +00:00
' sequence ' : fields . integer ( ' Sequence ' ) ,
2011-07-01 23:41:24 +00:00
' response ' : fields . function ( _calc_response_avg , string = " #Answer " , multi = ' sums ' ) ,
' average ' : fields . function ( _calc_response_avg , string = " #Avg " , multi = ' sums ' ) ,
2013-10-21 09:03:19 +00:00
' type ' : fields . selection ( [ ( ' char ' , ' Character ' ) , ( ' date ' , ' Date ' ) , ( ' datetime ' , ' Date & Time ' ) , \
( ' integer ' , ' Integer ' ) , ( ' float ' , ' Float ' ) , ( ' selection ' , ' Selection ' ) , \
( ' email ' , ' Email ' ) ] , " Type of Answer " , required = 1 ) ,
' menu_choice ' : fields . text ( ' Menu Choices ' , translate = True ) ,
2010-03-26 13:27:16 +00:00
' in_visible_answer_type ' : fields . boolean ( ' Is Answer Type Invisible?? ' )
2010-01-20 14:28:28 +00:00
}
_defaults = {
2013-10-21 09:03:19 +00:00
' type ' : ' char ' ,
' in_visible_answer_type ' : _get_in_visible_answer_type ,
2010-01-20 14:28:28 +00:00
}
2010-11-22 10:37:53 +00:00
def default_get ( self , cr , uid , fields , context = None ) :
2010-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-01-20 14:28:28 +00:00
data = super ( survey_answer , self ) . default_get ( cr , uid , fields , context )
return data
2013-10-22 15:10:51 +00:00
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
2010-01-20 14:28:28 +00:00
class survey_response ( osv . osv ) :
2013-10-22 15:10:51 +00:00
_name = " survey.response " # survrey.user_answer / user_response
2010-01-20 14:28:28 +00:00
_rec_name = ' date_create '
2013-10-21 09:03:19 +00:00
2010-01-20 14:28:28 +00:00
_columns = {
2013-10-21 09:03:19 +00:00
' date_deadline ' : fields . date ( " Deadline date " , help = " Date by which the person can respond to the survey " ) ,
' survey_id ' : fields . many2one ( ' survey ' , ' Survey ' , required = 1 , readonly = 1 , ondelete = ' restrict ' ) ,
' date_create ' : fields . datetime ( ' Create Date ' , required = 1 ) ,
' response_type ' : fields . selection ( [ ( ' manually ' , ' Manually ' ) , ( ' link ' , ' Link ' ) ] , ' Answer Type ' , required = 1 ) ,
2013-10-22 15:10:51 +00:00
' question_ids ' : fields . one2many ( ' survey.response.line ' , ' response_id ' , ' Answer ' ) , # one2many surveu.user_input.question
2013-10-21 09:03:19 +00:00
' state ' : fields . selection ( [ ( ' new ' , ' Not Started ' ) , ( ' skip ' , ' Not Finished ' ) , ( ' done ' , ' Finished ' ) , ( ' cancel ' , ' Canceled ' ) , ( ' test ' , ' Test ' ) ] , ' Status ' , readonly = True ) ,
' token ' : fields . char ( " Indentification token " , readonly = 1 ) ,
' partner_id ' : fields . many2one ( ' res.partner ' , ' Partner ' , readonly = 1 ) ,
' email ' : fields . char ( " Email " , size = 64 , readonly = 1 ) ,
2010-01-28 07:32:59 +00:00
}
_defaults = {
2013-10-21 09:03:19 +00:00
' date_create ' : datetime . now ( ) ,
' state ' : " new " ,
' response_type ' : " manually " ,
' token ' : lambda s , cr , uid , c : uuid . uuid4 ( ) ,
2010-01-20 14:28:28 +00:00
}
[IMP]:survey,crm_hr,hr_evaluation.(Ref-YSA,APA)
-Rename Defination into Definition.
-When you click on test, answer or edit survey, remove the first screen with the selection box to select the survey.
-Add survey Types in demo data: Human Resources, Customer Feeback, Supplier Selection.
-In search view of surveys, remove the vertical separator between draft and open buttons, for type field set widget=selection.
-The button for responsible=my in the search view must be default="1".
-change demo data so that some surveys belongs to admin and some to demo user.
-The browse Response report must be renamed into "Print Answers".
-Browse the answer in the screen instead of printing a PDF.
-In the history one2many, first put the date and then the user.
-I started a survey but did not finished it. so that's normal but I was not able to restart the survey (it says I already answered).
-Removed the "Que: " prefix in each report.
bzr revid: apa@tinyerp.com-20100223093223-vwhgkn8kmdo8e6mo
2010-02-23 09:32:23 +00:00
2013-10-21 09:03:19 +00:00
def action_survey_resent ( self , cr , uid , ids , context = None ) :
record = self . browse ( cr , uid , ids [ 0 ] , context = context )
context = context or { }
context . update ( {
' survey_resent_token ' : True ,
' default_partner_ids ' : record . partner_id and [ record . partner_id . id ] or [ ] ,
' default_multi_email ' : record . email or " " ,
' default_public ' : ' email_private ' ,
} )
return self . pool . get ( ' survey ' ) . action_survey_sent ( cr , uid , [ record . survey_id . id ] , context = context )
def action_print_response ( self , cr , uid , ids , context = None ) :
"""
Print Survey Answer in pdf format .
@return : Dictionary value for created survey answer report
"""
return {
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.browse.response ' ,
' datas ' : {
' model ' : ' survey.print.statistics ' ,
' form ' : {
' response_ids ' : ids ,
' orientation ' : ' vertical ' ,
' paper_size ' : ' letter ' ,
' page_number ' : 0 ,
' without_pagebreak ' : 0
}
} ,
}
def action_preview ( self , cr , uid , ids , context = None ) :
"""
Get preview response
"""
context = context or { }
self . pool . get ( ' survey ' ) . check_access_rights ( cr , uid , ' write ' )
record = self . browse ( cr , uid , ids [ 0 ] , context = context )
context . update ( {
' ir_actions_act_window_target ' : ' new ' ,
' survey_id ' : record . survey_id . id ,
' response_id ' : ids [ 0 ] ,
' readonly ' : True ,
} )
return {
' view_type ' : ' form ' ,
" view_mode " : ' form ' ,
' res_model ' : ' survey.question.wiz ' ,
' type ' : ' ir.actions.act_window ' ,
' target ' : ' new ' ,
' context ' : context
}
def action_cancel ( self , cr , uid , ids , context = None ) :
self . pool . get ( ' survey ' ) . check_access_rights ( cr , uid , ' write ' )
return self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
2010-03-04 09:16:44 +00:00
def name_get ( self , cr , uid , ids , context = None ) :
if not len ( ids ) :
return [ ]
2013-10-21 09:03:19 +00:00
reads = self . read ( cr , uid , ids , [ ' partner_id ' , ' date_create ' ] , context = context )
2010-03-04 09:16:44 +00:00
res = [ ]
for record in reads :
2013-10-21 09:03:19 +00:00
name = ( record [ ' partner_id ' ] and record [ ' partner_id ' ] [ 1 ] or ' ' ) + ' ( ' + record [ ' date_create ' ] . split ( ' . ' ) [ 0 ] + ' ) '
2010-03-04 09:16:44 +00:00
res . append ( ( record [ ' id ' ] , name ) )
return res
2010-11-23 11:31:52 +00:00
def copy ( self , cr , uid , id , default = None , context = None ) :
2013-10-21 09:03:19 +00:00
raise osv . except_osv ( _ ( ' Warning! ' ) , _ ( ' You cannot duplicate the resource! ' ) )
2013-10-22 15:10:51 +00:00
2010-01-20 14:28:28 +00:00
class survey_response_line ( osv . osv ) :
2013-10-22 15:10:51 +00:00
_name = ' survey.response.line ' # surver.user_input.question
2010-01-20 14:28:28 +00:00
_description = ' Survey Response Line '
_rec_name = ' date_create '
_columns = {
2013-10-22 15:10:51 +00:00
' response_id ' : fields . many2one ( ' survey.response ' , ' Answer ' , ondelete = ' cascade ' ) , # towards survey.uyser_intpu.question
' date_create ' : fields . datetime ( ' Create Date ' , required = 1 ) , # drop
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' done ' , ' Answered ' ) , ( ' skip ' , ' Skiped ' ) ] , ' Status ' , readonly = True ) , # drop
# add boolean skipped
2013-10-21 09:03:19 +00:00
' question_id ' : fields . many2one ( ' survey.question ' , ' Question ' , ondelete = ' restrict ' ) ,
2013-10-22 15:10:51 +00:00
' page_id ' : fields . related ( ' question_id ' , ' page_id ' , type = ' many2one ' , relation = ' survey.page ' , string = ' Page ' , ondelete = ' restrict ' ) , # ? probably not useful
' response_answer_ids ' : fields . one2many ( ' survey.response.answer ' , ' response_line_id ' , ' Answer ' ) , # survey.user_input.answer
' comment ' : fields . text ( ' Notes ' ) , # -> move in answer
' single_text ' : fields . char ( ' Text ' , size = 255 ) , # should be dropped
2010-01-20 14:28:28 +00:00
}
_defaults = {
2013-10-21 09:03:19 +00:00
' state ' : " draft " ,
2010-01-20 14:28:28 +00:00
}
class survey_response_answer ( osv . osv ) :
2013-10-22 15:10:51 +00:00
_name = ' survey.response.answer ' # survey.user_input.answer
2010-04-05 11:59:01 +00:00
_description = ' Survey Answer '
2013-10-21 09:03:19 +00:00
_rec_name = ' response_line_id '
2010-01-20 14:28:28 +00:00
_columns = {
2013-10-22 15:10:51 +00:00
' name ' : fields . integer ( ' Row Number ' ) , # ? probably drop
' response_line_id ' : fields . many2one ( ' survey.response.line ' , ' Answer ' , ondelete = ' cascade ' ) , # survey.user_input.question
' answer_id ' : fields . many2one ( ' survey.answer ' , ' Answer ' , required = 1 , ondelete = ' cascade ' ) , # survey.question.answer
' column_id ' : fields . many2one ( ' survey.question.column.heading ' , ' Column ' ) , # drop
2013-10-21 09:03:19 +00:00
' answer ' : fields . char ( ' Value ' , size = 255 ) ,
' value_choice ' : fields . char ( ' Value Choice ' , size = 255 ) ,
2010-03-26 13:27:16 +00:00
' comment ' : fields . text ( ' Notes ' ) ,
2013-10-21 09:03:19 +00:00
' comment_field ' : fields . char ( ' Comment ' , size = 255 ) ,
' value ' : fields . char ( ' Value ' , size = 255 ) ,
2010-01-20 14:28:28 +00:00
}
2013-10-21 09:03:19 +00:00
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4: