2010-01-20 14:28:28 +00:00
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
2010-12-08 13:59:16 +00:00
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
2010-01-20 14:28:28 +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
2010-01-20 14:28:28 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2010-03-23 05:23:09 +00:00
from osv import osv
from osv import fields
import tools
import netsvc
from tools . translate import _
2010-01-20 14:28:28 +00:00
from time import strftime
2010-09-29 08:05:01 +00:00
from datetime import datetime
from dateutil . relativedelta import relativedelta
2010-01-20 14:28:28 +00:00
import copy
2010-02-10 05:25:42 +00:00
import os
2010-01-20 14:28:28 +00:00
2010-01-27 13:55:23 +00:00
class survey_type ( osv . osv ) :
_name = ' survey.type '
_description = ' Survey Type '
_columns = {
2010-03-26 13:27:16 +00:00
' name ' : fields . char ( " Name " , size = 128 , required = 1 ) ,
' code ' : fields . char ( " Code " , size = 64 ) ,
2010-01-27 13:55:23 +00:00
}
survey_type ( )
2010-01-20 14:28:28 +00:00
class survey ( osv . osv ) :
_name = ' survey '
_description = ' Survey '
_rec_name = ' title '
2010-01-27 13:55:23 +00:00
2010-11-22 10:37:53 +00:00
def default_get ( self , cr , uid , fields , context = None ) :
2010-01-27 13:55:23 +00:00
data = super ( survey , self ) . default_get ( cr , uid , fields , context )
return data
2010-01-20 14:28:28 +00:00
_columns = {
2010-03-26 13:27:16 +00:00
' title ' : fields . char ( ' Survey Title ' , size = 128 , required = 1 ) ,
' page_ids ' : fields . one2many ( ' survey.page ' , ' survey_id ' , ' Page ' ) ,
' date_open ' : fields . datetime ( ' Survey Open Date ' , readonly = 1 ) ,
' date_close ' : fields . datetime ( ' Survey Close Date ' , readonly = 1 ) ,
2010-09-06 07:15:37 +00:00
' max_response_limit ' : fields . integer ( ' Maximum Answer Limit ' ,
help = " Set to one if survey is answerable only once " ) ,
2010-04-05 11:59:01 +00:00
' response_user ' : fields . integer ( ' Maximum Answer per User ' ,
help = " Set to one if you require only one Answer per user " ) ,
2010-03-26 13:27:16 +00:00
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' open ' , ' Open ' ) , ( ' close ' , ' Closed ' ) , ( ' cancel ' , ' Cancelled ' ) ] , ' Status ' , readonly = True ) ,
2010-09-16 11:33:51 +00:00
' responsible_id ' : fields . many2one ( ' res.users ' , ' Responsible ' , help = " User responsible for survey " ) ,
2010-03-26 13:27:16 +00:00
' tot_start_survey ' : fields . integer ( " Total Started Survey " , readonly = 1 ) ,
' tot_comp_survey ' : fields . integer ( " Total Completed Survey " , readonly = 1 ) ,
' note ' : fields . text ( ' Description ' , size = 128 ) ,
' history ' : fields . one2many ( ' survey.history ' , ' survey_id ' , ' History Lines ' , readonly = True ) ,
2010-01-20 14:28:28 +00:00
' users ' : fields . many2many ( ' res.users ' , ' survey_users_rel ' , ' sid ' , ' uid ' , ' Users ' ) ,
2010-04-05 11:59:01 +00:00
' send_response ' : fields . boolean ( ' E-mail Notification on Answer ' ) ,
2010-03-26 13:27:16 +00:00
' type ' : fields . many2one ( ' survey.type ' , ' Type ' ) ,
2010-10-15 07:02:30 +00:00
' invited_user_ids ' : fields . many2many ( ' res.users ' , ' survey_invited_user_rel ' , ' sid ' , ' uid ' , ' Invited User ' ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2010-03-26 13:27:16 +00:00
' state ' : lambda * a : " draft " ,
' tot_start_survey ' : lambda * a : 0 ,
' tot_comp_survey ' : lambda * a : 0 ,
' send_response ' : lambda * a : 1 ,
' response_user ' : lambda * a : 1 ,
2010-01-20 14:28:28 +00:00
}
def survey_draft ( self , cr , uid , ids , arg ) :
2010-03-26 13:27:16 +00:00
self . write ( cr , uid , ids , { ' state ' : ' draft ' } )
2010-01-20 14:28:28 +00:00
return True
def survey_open ( self , cr , uid , ids , arg ) :
2010-03-26 13:27:16 +00:00
self . write ( cr , uid , ids , { ' state ' : ' open ' , ' date_open ' : strftime ( " % Y- % m- %d % H: % M: % S " ) } )
2010-01-20 14:28:28 +00:00
return True
def survey_close ( self , cr , uid , ids , arg ) :
2010-03-26 13:27:16 +00:00
self . write ( cr , uid , ids , { ' state ' : ' close ' , ' date_close ' : strftime ( " % Y- % m- %d % H: % M: % S " ) } )
2010-01-20 14:28:28 +00:00
return True
def survey_cancel ( self , cr , uid , ids , arg ) :
2010-03-26 13:27:16 +00:00
self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
2010-01-20 14:28:28 +00:00
return True
2010-12-09 05:36:29 +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 )
title = current_rec . get ( ' title ' ) + ' (Copy) '
vals . update ( { ' title ' : title } )
2011-05-20 12:51:36 +00:00
vals . update ( { ' history ' : [ ] , ' tot_start_survey ' : 0 , ' tot_comp_survey ' : 0 } )
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 ,
@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 .
"""
2010-11-23 07:05:05 +00:00
if context is None :
2010-04-08 06:00:47 +00:00
context = { }
datas = { }
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 ) ]
else :
response_id = self . pool . get ( ' survey.response ' ) . search ( cr , uid , [ ( ' survey_id ' , ' = ' , ids ) ] , context = context )
datas [ ' ids ' ] = ids
2010-04-08 06:00:47 +00:00
page_setting = { ' orientation ' : ' vertical ' , ' without_pagebreak ' : 0 , ' paper_size ' : ' letter ' , ' page_number ' : 1 , ' survey_title ' : 1 }
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 ,
2010-09-13 07:07:11 +00:00
' context ' : context ,
' nodestroy ' : True ,
2010-04-08 06:00:47 +00:00
}
else :
2010-04-23 07:24:58 +00:00
2010-04-08 06:00:47 +00:00
datas [ ' form ' ] = page_setting
datas [ ' model ' ] = ' survey.print '
report = {
' type ' : ' ir.actions.report.xml ' ,
' report_name ' : ' survey.form ' ,
' datas ' : datas ,
2010-09-13 07:07:11 +00:00
' context ' : context ,
' nodestroy ' : True ,
2010-04-08 06:00:47 +00:00
}
return report
2010-01-20 14:28:28 +00:00
survey ( )
class survey_history ( osv . osv ) :
_name = ' survey.history '
_description = ' Survey History '
_rec_name = ' date '
_columns = {
2010-03-26 13:27:16 +00:00
' survey_id ' : fields . many2one ( ' survey ' , ' Survey ' ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' User ' , readonly = True ) ,
' date ' : fields . datetime ( ' Date started ' , readonly = 1 ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2010-03-26 13:27:16 +00:00
' date ' : lambda * a : datetime . datetime . now ( )
2010-01-20 14:28:28 +00:00
}
survey_history ( )
class survey_page ( osv . osv ) :
_name = ' survey.page '
_description = ' Survey Pages '
_rec_name = ' title '
_order = ' sequence '
_columns = {
2010-03-26 13:27:16 +00:00
' title ' : fields . char ( ' Page Title ' , size = 128 , required = 1 ) ,
' survey_id ' : fields . many2one ( ' survey ' , ' Survey ' , ondelete = ' cascade ' ) ,
' question_ids ' : fields . one2many ( ' survey.question ' , ' page_id ' , ' Question ' ) ,
' sequence ' : fields . integer ( ' Page Nr ' ) ,
' note ' : fields . text ( ' Description ' ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2010-03-26 13:27:16 +00:00
' sequence ' : lambda * a : 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 )
2010-03-15 10:52:27 +00:00
if context . get ( ' line_order ' , False ) :
2010-02-04 13:18:48 +00:00
if len ( context [ ' line_order ' ] [ - 1 ] ) > 2 and type ( context [ ' line_order ' ] [ - 1 ] [ 2 ] ) == type ( { } ) and context [ ' line_order ' ] [ - 1 ] [ 2 ] . has_key ( ' sequence ' ) :
2010-01-20 14:28:28 +00:00
data [ ' sequence ' ] = context [ ' line_order ' ] [ - 1 ] [ 2 ] [ ' sequence ' ] + 1
if context . has_key ( ' 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 = { }
2010-01-20 14:28:28 +00:00
search_obj = self . pool . get ( ' ir.ui.view ' )
search_id = search_obj . search ( cr , uid , [ ( ' model ' , ' = ' , ' survey.question.wiz ' ) , ( ' name ' , ' = ' , ' Survey Search ' ) ] )
surv_name_wiz = self . pool . get ( ' survey.name.wiz ' )
2010-03-15 10:52:27 +00:00
surv_name_wiz . write ( cr , uid , [ context . get ( ' sur_name_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 ' ,
' search_view_id ' : search_id [ 0 ] ,
' 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 )
title = current_rec . get ( ' title ' ) + ' (Copy) '
vals . update ( { ' title ' : title } )
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
survey_page ( )
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 \
group by question_id " ,(tuple(ids),))
2010-01-20 14:28:28 +00:00
ids1 = copy . deepcopy ( ids )
for rec in cr . fetchall ( ) :
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 = {
2010-03-26 13:27:16 +00:00
' page_id ' : fields . many2one ( ' survey.page ' , ' Survey Page ' , ondelete = ' cascade ' , required = 1 ) ,
' question ' : fields . char ( ' Question ' , size = 128 , required = 1 ) ,
' 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 ' ) ,
2010-03-26 13:27:16 +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 ' ) ,
' req_ans ' : fields . integer ( ' #Required Answer ' ) ,
' maximum_req_ans ' : fields . integer ( ' Maximum Required Answer ' ) ,
' minimum_req_ans ' : fields . integer ( ' Minimum Required Answer ' ) ,
' req_error_msg ' : fields . text ( ' Error Message ' ) ,
' allow_comment ' : fields . boolean ( ' Allow Comment Field ' ) ,
' sequence ' : fields . integer ( ' Sequence ' ) ,
2011-07-01 23:41:24 +00:00
' tot_resp ' : fields . function ( _calc_response , string = " Total Answer " ) ,
2010-03-26 13:27:16 +00:00
' survey ' : fields . related ( ' page_id ' , ' survey_id ' , type = ' many2one ' , relation = ' survey ' , string = ' Survey ' ) ,
' descriptive_text ' : fields . text ( ' Descriptive Text ' , size = 255 ) ,
' 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) ' ) ,
2010-04-06 07:02:31 +00:00
( ' multiple_choice_multiple_ans ' , ' Multiple Choice (Multiple Answer) ' ) ,
( ' matrix_of_choices_only_one_ans ' , ' Matrix of Choices (Only One Answers Per Row) ' ) ,
( ' matrix_of_choices_only_multi_ans ' , ' Matrix of Choices (Multiple Answers Per Row) ' ) ,
( ' matrix_of_drop_down_menus ' , ' Matrix of Drop-down Menus ' ) ,
( ' rating_scale ' , ' Rating Scale ' ) , ( ' single_textbox ' , ' Single Textbox ' ) ,
( ' multiple_textboxes ' , ' Multiple Textboxes ' ) ,
( ' multiple_textboxes_diff_type ' , ' Multiple Textboxes With Different Type ' ) ,
( ' comment ' , ' Comment/Essay Box ' ) ,
( ' numerical_textboxes ' , ' Numerical Textboxes ' ) , ( ' date ' , ' Date ' ) ,
( ' date_and_time ' , ' Date and Time ' ) , ( ' descriptive_text ' , ' Descriptive Text ' ) ,
( ' table ' , ' Table ' ) ,
] , ' Question Type ' , required = 1 , ) ,
2010-05-11 09:00:24 +00:00
' is_comment_require ' : fields . boolean ( ' Add Comment Field ' ) ,
2010-03-26 13:27:16 +00:00
' comment_label ' : fields . char ( ' Field Label ' , size = 255 ) ,
' 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 ' ) ,
' comment_valid_err_msg ' : fields . text ( ' Error message ' ) ,
' make_comment_field ' : fields . boolean ( ' Make Comment Field an Answer Choice ' ) ,
' make_comment_field_err_msg ' : fields . text ( ' Error message ' ) ,
2010-05-11 09:00:24 +00:00
' is_validation_require ' : fields . boolean ( ' Validate Text ' ) ,
2010-03-26 13:27:16 +00:00
' validation_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
' 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 ' ) ,
' validation_valid_err_msg ' : fields . text ( ' Error message ' ) ,
' numeric_required_sum ' : fields . integer ( ' Sum of all choices ' ) ,
' numeric_required_sum_err_msg ' : fields . text ( ' Error message ' ) ,
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 ' ) ,
' column_name ' : fields . char ( ' Column Name ' , size = 256 ) ,
' no_of_rows ' : fields . integer ( ' No of Rows ' ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
2010-03-26 13:27:16 +00:00
' sequence ' : lambda * a : 1 ,
' type ' : lambda * a : ' multiple_choice_multiple_ans ' ,
' req_error_msg ' : lambda * a : ' This question requires an answer. ' ,
' required_type ' : lambda * a : ' at least ' ,
' req_ans ' : lambda * a : 1 ,
' comment_field_type ' : lambda * a : ' char ' ,
' comment_label ' : lambda * a : ' Other (please specify) ' ,
' comment_valid_type ' : lambda * a : ' do_not_validate ' ,
' comment_valid_err_msg ' : lambda * a : ' The comment you entered is in an invalid format. ' ,
' validation_type ' : lambda * a : ' do_not_validate ' ,
' validation_valid_err_msg ' : lambda * a : ' The comment you entered is in an invalid format. ' ,
' numeric_required_sum_err_msg ' : lambda * a : ' The choices need to add up to [enter sum here]. ' ,
' make_comment_field_err_msg ' : lambda * a : ' Please enter a comment. ' ,
' in_visible_answer_type ' : lambda * a : 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 ' ] :
2010-03-26 13:27:16 +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 [ ' matrix_of_drop_down_menus ' ] :
2010-03-26 13:27:16 +00:00
val . update ( { ' in_visible_rating_weight ' : True , ' in_visible_menu_choice ' : False } )
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 ' ] :
2010-03-26 13:27:16 +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 :
2010-03-26 13:27:16 +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
def write ( self , cr , uid , ids , vals , context = None ) :
2010-03-26 13:27:16 +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 ' ] )
2010-01-20 14:28:28 +00:00
for question in questions :
col_len = len ( question [ ' column_heading_ids ' ] )
if vals . has_key ( ' column_heading_ids ' ) :
for col in vals [ ' column_heading_ids ' ] :
if type ( col [ 2 ] ) == type ( { } ) :
col_len + = 1
else :
col_len - = 1
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if vals . has_key ( ' type ' ) :
que_type = vals [ ' type ' ]
else :
que_type = question [ ' type ' ]
2010-03-15 10:52:27 +00:00
2010-03-26 13:27:16 +00:00
if que_type in [ ' matrix_of_choices_only_one_ans ' , ' matrix_of_choices_only_multi_ans ' , \
' matrix_of_drop_down_menus ' , ' rating_scale ' ] :
2010-01-20 14:28:28 +00:00
if not col_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more column heading. " ) )
2010-01-20 14:28:28 +00:00
ans_len = len ( question [ ' answer_choice_ids ' ] )
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if vals . has_key ( ' answer_choice_ids ' ) :
for ans in vals [ ' answer_choice_ids ' ] :
if type ( ans [ 2 ] ) == type ( { } ) :
ans_len + = 1
else :
ans_len - = 1
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if que_type not in [ ' descriptive_text ' , ' single_textbox ' , ' comment ' , ' table ' ] :
if not ans_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more Answer. " ) )
2010-01-20 14:28:28 +00:00
req_type = " "
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if vals . has_key ( ' required_type ' ) :
req_type = vals [ ' required_type ' ]
else :
req_type = question [ ' required_type ' ]
2010-03-15 10:52:27 +00:00
2010-03-26 13:27:16 +00:00
if que_type in [ ' multiple_choice_multiple_ans ' , ' matrix_of_choices_only_one_ans ' , \
' matrix_of_choices_only_multi_ans ' , ' matrix_of_drop_down_menus ' , \
' 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 ' ] :
if vals . has_key ( ' req_ans ' ) :
if not vals [ ' req_ans ' ] or vals [ ' req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
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 :
if not question [ ' req_ans ' ] or question [ ' req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
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
if vals . has_key ( ' minimum_req_ans ' ) :
minimum_ans = vals [ ' minimum_req_ans ' ]
if not vals [ ' minimum_req_ans ' ] or vals [ ' minimum_req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " Minimum Required Answer \
2010-03-26 13:27:16 +00:00
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
else :
minimum_ans = question [ ' minimum_req_ans ' ]
if not question [ ' minimum_req_ans ' ] or question [ ' minimum_req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " Minimum Required Answer you \
2010-03-26 13:27:16 +00:00
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 vals . has_key ( ' maximum_req_ans ' ) :
maximum_ans = vals [ ' maximum_req_ans ' ]
if not vals [ ' maximum_req_ans ' ] or vals [ ' maximum_req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " Maximum Required Answer you \
2010-03-26 13:27:16 +00:00
entered for your maximum 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 :
maximum_ans = question [ ' maximum_req_ans ' ]
if not question [ ' maximum_req_ans ' ] or question [ ' maximum_req_ans ' ] > ans_len :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " Maximum Required Answer you \
2010-03-26 13:27:16 +00:00
entered for your maximum 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 :
2010-03-29 10:30:33 +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
if question [ ' type ' ] == ' matrix_of_drop_down_menus ' and vals . has_key ( ' column_heading_ids ' ) :
for col in vals [ ' column_heading_ids ' ] :
2010-02-03 08:35:53 +00:00
if not col [ 2 ] or not col [ 2 ] . has_key ( ' menu_choice ' ) or not col [ 2 ] [ ' menu_choice ' ] :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more menu choices \
2010-03-26 13:27:16 +00:00
in column heading " ))
elif not col [ 2 ] or not col [ 2 ] . has_key ( ' menu_choice ' ) or \
col [ 2 ] [ ' menu_choice ' ] . strip ( ) == ' ' :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more menu \
2010-03-26 13:27:16 +00:00
choices in column heading ( white spaces not allowed ) " ))
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 ) :
2010-01-20 14:28:28 +00:00
minimum_ans = 0
maximum_ans = 0
if vals . has_key ( ' answer_choice_ids ' ) and not len ( vals [ ' answer_choice_ids ' ] ) :
if vals . has_key ( ' type ' ) and vals [ ' type ' ] not in [ ' descriptive_text ' , ' single_textbox ' , ' comment ' , ' table ' ] :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more answer. " ) )
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if vals . has_key ( ' column_heading_ids ' ) and not len ( vals [ ' column_heading_ids ' ] ) :
if vals . has_key ( ' type ' ) and vals [ ' type ' ] in [ ' matrix_of_choices_only_one_ans ' , ' matrix_of_choices_only_multi_ans ' , ' matrix_of_drop_down_menus ' , ' rating_scale ' ] :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more column heading. " ) )
2010-03-15 10:52:27 +00:00
2010-01-27 13:55:23 +00:00
if vals [ ' type ' ] in [ ' multiple_choice_multiple_ans ' , ' matrix_of_choices_only_one_ans ' , ' matrix_of_choices_only_multi_ans ' , ' matrix_of_drop_down_menus ' , ' rating_scale ' , ' multiple_textboxes ' , ' numerical_textboxes ' , ' date ' , ' date_and_time ' ] :
if vals . has_key ( ' is_require_answer ' ) and vals . has_key ( ' required_type ' ) and vals [ ' required_type ' ] in [ ' at least ' , ' at most ' , ' exactly ' ] :
2010-02-04 13:18:48 +00:00
if vals . has_key ( ' answer_choice_ids ' ) and vals [ ' req_ans ' ] > len ( vals [ ' answer_choice_ids ' ] ) or not vals [ ' req_ans ' ] :
2010-03-29 10:30:33 +00:00
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 ) )
2010-03-15 10:52:27 +00:00
2010-01-27 13:55:23 +00:00
if vals . has_key ( ' is_require_answer ' ) and vals . has_key ( ' required_type ' ) and vals [ ' required_type ' ] == ' a range ' :
minimum_ans = vals [ ' minimum_req_ans ' ]
maximum_ans = vals [ ' maximum_req_ans ' ]
2010-02-04 13:18:48 +00:00
if vals . has_key ( ' answer_choice_ids ' ) or vals [ ' minimum_req_ans ' ] > len ( vals [ ' answer_choice_ids ' ] ) or not vals [ ' minimum_req_ans ' ] :
2010-03-29 10:30:33 +00:00
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 ) )
2010-02-04 13:18:48 +00:00
if vals . has_key ( ' answer_choice_ids ' ) or vals [ ' maximum_req_ans ' ] > len ( vals [ ' answer_choice_ids ' ] ) or not vals [ ' maximum_req_ans ' ] :
2010-03-29 10:30:33 +00:00
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 ) )
2010-01-27 13:55:23 +00:00
if maximum_ans < = minimum_ans :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " Maximum Required Answer is greater than Minimum Required Answer " ) )
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if vals [ ' type ' ] == ' matrix_of_drop_down_menus ' :
for col in vals [ ' column_heading_ids ' ] :
2010-02-03 08:35:53 +00:00
if not col [ 2 ] or not col [ 2 ] . has_key ( ' menu_choice ' ) or not col [ 2 ] [ ' menu_choice ' ] :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more menu choices in column heading " ) )
2010-02-03 08:35:53 +00:00
elif not col [ 2 ] or not col [ 2 ] . has_key ( ' menu_choice ' ) or col [ 2 ] [ ' menu_choice ' ] . strip ( ) == ' ' :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( " You must enter one or more menu choices in column heading (white spaces not allowed) " ) )
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
res = super ( survey_question , self ) . create ( cr , uid , vals , context )
return res
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 = { }
2010-01-20 14:28:28 +00:00
search_obj = self . pool . get ( ' ir.ui.view ' )
search_id = search_obj . search ( cr , uid , [ ( ' model ' , ' = ' , ' survey.question.wiz ' ) , ( ' name ' , ' = ' , ' Survey Search ' ) ] )
surv_name_wiz = self . pool . get ( ' survey.name.wiz ' )
2010-03-15 10:52:27 +00:00
surv_name_wiz . write ( cr , uid , [ context . get ( ' sur_name_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 ' ,
' search_view_id ' : search_id [ 0 ] ,
' context ' : context
}
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_question , self ) . default_get ( cr , uid , fields , context )
2010-03-15 10:52:27 +00:00
if context . get ( ' line_order ' , False ) :
2010-02-04 13:18:48 +00:00
if len ( context [ ' line_order ' ] [ - 1 ] ) > 2 and type ( context [ ' line_order ' ] [ - 1 ] [ 2 ] ) == type ( { } ) and context [ ' line_order ' ] [ - 1 ] [ 2 ] . has_key ( ' sequence ' ) :
2010-01-20 14:28:28 +00:00
data [ ' sequence ' ] = context [ ' line_order ' ] [ - 1 ] [ 2 ] [ ' sequence ' ] + 1
2010-03-15 10:52:27 +00:00
2010-01-20 14:28:28 +00:00
if context . has_key ( ' page_id ' ) :
2010-04-06 07:02:31 +00:00
data [ ' page_id ' ] = context . get ( ' page_id ' , False )
2010-01-20 14:28:28 +00:00
return data
survey_question ( )
class survey_question_column_heading ( osv . osv ) :
_name = ' survey.question.column.heading '
_description = ' Survey Question Column Heading '
_rec_name = ' title '
2010-11-22 10:37:53 +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
2010-11-22 10:37:53 +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 = {
2010-03-26 13:27:16 +00:00
' title ' : fields . char ( ' Column Heading ' , size = 128 , required = 1 ) ,
' 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
}
_defaults = {
2010-03-26 13:27:16 +00:00
' 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
}
survey_question_column_heading ( )
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 ) :
2010-01-20 14:28:28 +00:00
cr . execute ( " select count(question_id) ,(select count(answer_id) \
from survey_response_answer sra , survey_response_line sa \
where sra . response_id = sa . id and sra . answer_id = % d \
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
2010-11-22 10:37:53 +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 ' ) ,
' answer ' : fields . char ( ' Answer ' , size = 128 , required = 1 ) ,
' 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 ' ) ,
2010-03-26 13:27:16 +00:00
' type ' : fields . selection ( [ ( ' char ' , ' Character ' ) , ( ' date ' , ' Date ' ) , ( ' datetime ' , ' Date & Time ' ) , \
2010-04-06 07:02:31 +00:00
( ' integer ' , ' Integer ' ) , ( ' float ' , ' Float ' ) , ( ' selection ' , ' Selection ' ) , \
( ' email ' , ' Email ' ) ] , " Type of Answer " , required = 1 ) ,
2010-03-26 13:27:16 +00:00
' menu_choice ' : fields . text ( ' Menu Choices ' ) ,
' in_visible_answer_type ' : fields . boolean ( ' Is Answer Type Invisible?? ' )
2010-01-20 14:28:28 +00:00
}
_defaults = {
2010-09-06 07:15:37 +00:00
# 'sequence' : lambda * a: 1,
2010-02-04 10:20:01 +00:00
' type ' : lambda * a : ' 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 )
2010-04-06 07:02:31 +00:00
if context . get ( ' line_order ' , False ) :
2010-02-04 13:18:48 +00:00
if len ( context [ ' line_order ' ] [ - 1 ] ) > 2 and type ( context [ ' line_order ' ] [ - 1 ] [ 2 ] ) == type ( { } ) and context [ ' line_order ' ] [ - 1 ] [ 2 ] . has_key ( ' sequence ' ) :
2010-01-20 14:28:28 +00:00
data [ ' sequence ' ] = context [ ' line_order ' ] [ - 1 ] [ 2 ] [ ' sequence ' ] + 1
return data
survey_answer ( )
class survey_response ( osv . osv ) :
_name = " survey.response "
_rec_name = ' date_create '
_columns = {
' survey_id ' : fields . many2one ( ' survey ' , ' Survey ' , required = 1 , ondelete = ' cascade ' ) ,
' date_create ' : fields . datetime ( ' Create Date ' , required = 1 ) ,
' user_id ' : fields . many2one ( ' res.users ' , ' User ' ) ,
2010-03-26 13:27:16 +00:00
' response_type ' : fields . selection ( [ ( ' manually ' , ' Manually ' ) , ( ' link ' , ' Link ' ) ] , \
2010-04-05 11:59:01 +00:00
' Answer Type ' , required = 1 , readonly = 1 ) ,
' question_ids ' : fields . one2many ( ' survey.response.line ' , ' response_id ' , ' Answer ' ) ,
2010-03-26 13:27:16 +00:00
' state ' : fields . selection ( [ ( ' done ' , ' Finished ' ) , ( ' skip ' , ' Not Finished ' ) ] , \
' Status ' , readonly = True ) ,
2010-01-28 07:32:59 +00:00
}
_defaults = {
' state ' : lambda * a : " skip " ,
2010-02-05 13:51:49 +00:00
' response_type ' : lambda * a : " manually " ,
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
2010-03-04 09:16:44 +00:00
def name_get ( self , cr , uid , ids , context = None ) :
if not len ( ids ) :
return [ ]
2010-12-13 06:43:09 +00:00
reads = self . read ( cr , uid , ids , [ ' user_id ' , ' date_create ' ] , context = context )
2010-03-04 09:16:44 +00:00
res = [ ]
for record in reads :
2010-05-11 10:54:56 +00:00
name = ( record [ ' user_id ' ] and record [ ' user_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 ) :
2010-03-29 10:30:33 +00:00
raise osv . except_osv ( _ ( ' Warning ! ' ) , _ ( ' You cannot duplicate the resource! ' ) )
2010-01-20 14:28:28 +00:00
survey_response ( )
class survey_response_line ( osv . osv ) :
_name = ' survey.response.line '
_description = ' Survey Response Line '
_rec_name = ' date_create '
_columns = {
2010-04-05 11:59:01 +00:00
' response_id ' : fields . many2one ( ' survey.response ' , ' Answer ' , ondelete = ' cascade ' ) ,
2010-03-26 13:27:16 +00:00
' date_create ' : fields . datetime ( ' Create Date ' , required = 1 ) ,
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' done ' , ' Answered ' ) , ( ' skip ' , ' Skiped ' ) ] , \
' Status ' , readonly = True ) ,
' question_id ' : fields . many2one ( ' survey.question ' , ' Question ' ) ,
' page_id ' : fields . related ( ' question_id ' , ' page_id ' , type = ' many2one ' , \
relation = ' survey.page ' , string = ' Page ' ) ,
2010-04-05 11:59:01 +00:00
' response_answer_ids ' : fields . one2many ( ' survey.response.answer ' , ' response_id ' , ' Answer ' ) ,
2010-03-26 13:27:16 +00:00
' response_table_ids ' : fields . one2many ( ' survey.tbl.column.heading ' , \
2010-04-05 11:59:01 +00:00
' response_table_id ' , ' Answer ' ) ,
2010-03-26 13:27:16 +00:00
' comment ' : fields . text ( ' Notes ' ) ,
' single_text ' : fields . char ( ' Text ' , size = 255 ) ,
2010-01-20 14:28:28 +00:00
}
_defaults = {
' state ' : lambda * a : " draft " ,
}
survey_response_line ( )
class survey_tbl_column_heading ( osv . osv ) :
_name = ' survey.tbl.column.heading '
_order = ' name '
_columns = {
2010-03-26 13:27:16 +00:00
' name ' : fields . integer ( ' Row Number ' ) ,
' column_id ' : fields . many2one ( ' survey.question.column.heading ' , ' Column ' ) ,
' value ' : fields . char ( ' Value ' , size = 255 ) ,
2010-04-05 11:59:01 +00:00
' response_table_id ' : fields . many2one ( ' survey.response.line ' , ' Answer ' , ondelete = ' cascade ' ) ,
2010-01-20 14:28:28 +00:00
}
survey_tbl_column_heading ( )
class survey_response_answer ( osv . osv ) :
_name = ' survey.response.answer '
2010-04-05 11:59:01 +00:00
_description = ' Survey Answer '
2010-01-20 14:28:28 +00:00
_rec_name = ' response_id '
_columns = {
2010-04-05 11:59:01 +00:00
' response_id ' : fields . many2one ( ' survey.response.line ' , ' Answer ' , ondelete = ' cascade ' ) ,
2010-03-26 13:27:16 +00:00
' answer_id ' : fields . many2one ( ' survey.answer ' , ' Answer ' , required = 1 , ondelete = ' cascade ' ) ,
' column_id ' : fields . many2one ( ' survey.question.column.heading ' , ' Column ' ) ,
' answer ' : fields . char ( ' Value ' , size = 255 ) ,
' value_choice ' : fields . char ( ' Value Choice ' , size = 255 ) ,
' comment ' : fields . text ( ' Notes ' ) ,
' comment_field ' : fields . char ( ' Comment ' , size = 255 )
2010-01-20 14:28:28 +00:00
}
survey_response_answer ( )
class res_users ( osv . osv ) :
_inherit = " res.users "
_name = " res.users "
_columns = {
' survey_id ' : fields . many2many ( ' survey ' , ' survey_users_rel ' , ' uid ' , ' sid ' , ' Groups ' ) ,
}
res_users ( )
class survey_request ( osv . osv ) :
_name = " survey.request "
_order = ' date_deadline '
2010-01-21 07:38:43 +00:00
_rec_name = ' date_deadline '
2010-01-20 14:28:28 +00:00
_columns = {
2010-03-26 13:27:16 +00:00
' date_deadline ' : fields . date ( " Deadline date " ) ,
' user_id ' : fields . many2one ( " res.users " , " User " ) ,
' email ' : fields . char ( " E-mail " , size = 64 ) ,
' survey_id ' : fields . many2one ( " survey " , " Survey " , required = 1 , ondelete = ' cascade ' ) ,
' response ' : fields . many2one ( ' survey.response ' , ' Answer ' ) ,
2011-01-06 05:34:22 +00:00
' state ' : fields . selection ( [ ( ' draft ' , ' Draft ' ) , ( ' waiting_answer ' , ' Waiting Answer ' ) , ( ' done ' , ' Done ' ) , ( ' cancel ' , ' Cancelled ' ) ] , ' State ' , readonly = 1 )
2010-01-20 14:28:28 +00:00
}
2010-01-21 07:38:43 +00:00
_defaults = {
2010-03-26 13:27:16 +00:00
' state ' : lambda * a : ' draft ' ,
2010-09-29 08:05:01 +00:00
# 'date_deadline': lambda * a : (datetime.now() + relativedelta(months=+1)).strftime("%Y-%m-%d %H:%M:%S")
2010-01-21 07:38:43 +00:00
}
def survey_req_waiting_answer ( self , cr , uid , ids , arg ) :
self . write ( cr , uid , ids , { ' state ' : ' waiting_answer ' } )
return True
2010-03-05 12:21:31 +00:00
def survey_req_draft ( self , cr , uid , ids , arg ) :
self . write ( cr , uid , ids , { ' state ' : ' draft ' } )
return True
2010-01-21 07:38:43 +00:00
def survey_req_done ( self , cr , uid , ids , arg ) :
self . write ( cr , uid , ids , { ' state ' : ' done ' } )
return True
def survey_req_cancel ( self , cr , uid , ids , arg ) :
self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
return True
def on_change_user ( self , cr , uid , ids , user_id , context = None ) :
if user_id :
user_obj = self . pool . get ( ' res.users ' )
2010-11-22 10:37:53 +00:00
user = user_obj . browse ( cr , uid , user_id , context = context )
2011-07-28 06:11:56 +00:00
return { ' value ' : { ' email ' : user . user_email } }
2010-01-21 07:38:43 +00:00
return { }
2010-01-20 14:28:28 +00:00
survey_request ( )
2010-03-04 07:19:13 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: