[IMP] survey: change spaces
bzr revid: chm@openerp.com-20130215145428-5g8wx69q2pma7s0m
This commit is contained in:
+182
-209
@@ -2,28 +2,28 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
|
||||
# Copyright (C) 2004-TODAY OpenERP S.A. <http: //www.openerp.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# This program is free software: you can redistribute it and / or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
# MERCHANTABILITY or FITNESS F OR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License f or m or e details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http: //www.gnu. or g/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import copy
|
||||
from time import strftime
|
||||
imp or t copy
|
||||
from time imp or t strftime
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp.osv imp or t fields, osv
|
||||
from openerp.tools.translate imp or t _
|
||||
|
||||
|
||||
class survey_type(osv.osv):
|
||||
@@ -55,54 +55,54 @@ class survey(osv.osv):
|
||||
help="Set to one if survey is answerable only once"),
|
||||
'response_partner': fields.integer('Maximum Answer per partner',
|
||||
help="Set to one if you require only one Answer per partner"),
|
||||
'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'),('close', 'Closed') ], 'Status', readonly=True),
|
||||
'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible for survey"),
|
||||
'state': fields.selection([('open', 'Open'), ('cancel', 'Cancelled'), ('close', 'Closed')], 'Status', readonly=True),
|
||||
'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible f or survey"),
|
||||
'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),
|
||||
'partner_id': fields.many2many('res.partner', 'survey_partner_rel', 'sid', 'partner_id', 'Partners'),
|
||||
'send_response': fields.boolean('Email Notification on Answer'),
|
||||
'type': fields.many2one('survey.type', 'Type'),
|
||||
'color': fields.integer('Color Index'),
|
||||
'col or ': fields.integer('Col or Index'),
|
||||
}
|
||||
_defaults = {
|
||||
'state': lambda * a: "open",
|
||||
'tot_start_survey': lambda * a: 0,
|
||||
'tot_comp_survey': lambda * a: 0,
|
||||
'send_response': lambda * a: 1,
|
||||
'response_partner': lambda * a:1,
|
||||
'response_partner': lambda * a: 1,
|
||||
'date_open': fields.datetime.now,
|
||||
}
|
||||
|
||||
def survey_open(self, cr, uid, ids, arg):
|
||||
self.write(cr, uid, ids, {'state': 'open', 'date_open': strftime("%Y-%m-%d %H:%M:%S")})
|
||||
self.write(cr, uid, ids, {'state': 'open', 'date_open': strftime("%Y-%m-%d %H: %M: %S")})
|
||||
return True
|
||||
|
||||
def survey_close(self, cr, uid, ids, arg):
|
||||
self.write(cr, uid, ids, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H:%M:%S") })
|
||||
self.write(cr, uid, ids, {'state': 'close', 'date_close': strftime("%Y-%m-%d %H: %M: %S")})
|
||||
return True
|
||||
|
||||
def survey_cancel(self, cr, uid, ids, arg):
|
||||
self.write(cr, uid, ids, {'state': 'cancel' })
|
||||
self.write(cr, uid, ids, {'state': 'cancel'})
|
||||
return True
|
||||
|
||||
def copy(self, cr, uid, ids, default=None, context=None):
|
||||
vals = {}
|
||||
current_rec = self.read(cr, uid, ids, context=context)
|
||||
title = _("%s (copy)") % (current_rec.get('title'))
|
||||
vals.update({'title':title})
|
||||
vals.update({'tot_start_survey':0,'tot_comp_survey':0})
|
||||
vals.update({'title': title})
|
||||
vals.update({'tot_start_survey': 0, 'tot_comp_survey': 0})
|
||||
return super(survey, self).copy(cr, uid, ids, vals, context=context)
|
||||
|
||||
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).
|
||||
If response is available then print this response otherwise print survey f or m(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 cr: the current row, from the database curs or ,
|
||||
@param uid: the current user’s ID f or security checks,
|
||||
@param ids: List of Survey IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
@return : Dictionary value for print survey form.
|
||||
@param context: A st and ard dictionary f or contextual values
|
||||
@return: Dictionary value f or print survey f or m.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -111,65 +111,66 @@ class survey(osv.osv):
|
||||
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)
|
||||
response_id = self.pool.get('survey.response').search(cr, uid, [('survey_id', '=', ids)], context=context)
|
||||
datas['ids'] = ids
|
||||
page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
|
||||
report = {}
|
||||
page_setting = {' or ientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
|
||||
rep or t = {}
|
||||
if response_id and response_id[0]:
|
||||
context.update({'survey_id': datas['ids']})
|
||||
datas['form'] = page_setting
|
||||
datas['f or m'] = page_setting
|
||||
datas['model'] = 'survey.print.answer'
|
||||
report = {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'survey.browse.response',
|
||||
rep or t = {
|
||||
'type': 'ir.actions.rep or t.xml',
|
||||
'rep or t_name': 'survey.browse.response',
|
||||
'datas': datas,
|
||||
'context' : context,
|
||||
'nodestroy':True,
|
||||
'context': context,
|
||||
'nodestroy': True,
|
||||
}
|
||||
else:
|
||||
|
||||
datas['form'] = page_setting
|
||||
datas['f or m'] = page_setting
|
||||
datas['model'] = 'survey.print'
|
||||
report = {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'survey.form',
|
||||
rep or t = {
|
||||
'type': 'ir.actions.rep or t.xml',
|
||||
'rep or t_name': 'survey.f or m',
|
||||
'datas': datas,
|
||||
'context' : context,
|
||||
'nodestroy':True,
|
||||
'context': context,
|
||||
'nodestroy': True,
|
||||
}
|
||||
return report
|
||||
return rep or t
|
||||
|
||||
def fill_survey(self, cr, uid, ids, context=None):
|
||||
sur_obj = self.read(cr, uid, ids,['title', 'page_ids'], context=context)
|
||||
for sur in sur_obj:
|
||||
sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context)
|
||||
f or sur in sur_obj:
|
||||
name = sur['title']
|
||||
pages = sur['page_ids']
|
||||
if not pages:
|
||||
raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.'))
|
||||
context.update({'active':False,'survey_id': ids[0]})
|
||||
context.update({'active': False, 'survey_id': ids[0]})
|
||||
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'inline',
|
||||
'name': name,
|
||||
'context': context
|
||||
}
|
||||
|
||||
def test_survey(self, cr, uid, ids, context=None):
|
||||
sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context)
|
||||
for sur in sur_obj:
|
||||
sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context)
|
||||
f or sur in sur_obj:
|
||||
name = sur['title']
|
||||
pages = sur['page_ids']
|
||||
if not pages:
|
||||
raise osv.except_osv(_('Warning!'), _('This survey has no pages defined. Please define pages first.'))
|
||||
context.update({'active':False,'survey_id': ids[0]})
|
||||
context.update({'active': False, 'survey_id': ids[0]})
|
||||
|
||||
context.update({'ir_actions_act_window_target': 'new'})
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'inline',
|
||||
@@ -178,8 +179,8 @@ class survey(osv.osv):
|
||||
}
|
||||
|
||||
def edit_survey(self, cr, uid, ids, context=None):
|
||||
sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context)
|
||||
for sur in sur_obj:
|
||||
sur_obj = self.read(cr, uid, ids, ['title', 'page_ids'], context=context)
|
||||
f or sur in sur_obj:
|
||||
name = sur['title']
|
||||
pages = sur['page_ids']
|
||||
if not pages:
|
||||
@@ -188,8 +189,8 @@ class survey(osv.osv):
|
||||
|
||||
context.update({'ir_actions_act_window_target': 'new'})
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
@@ -201,11 +202,11 @@ class survey(osv.osv):
|
||||
'''
|
||||
This function opens a window to compose an email, with the survey template message loaded by default
|
||||
'''
|
||||
assert len(ids) == 1, 'This option should only be used for a single id at a time.'
|
||||
assert len(ids) == 1, 'This option should only be used f or 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:
|
||||
except ValueErr or :
|
||||
template_id = False
|
||||
ctx = dict(context)
|
||||
|
||||
@@ -219,8 +220,8 @@ class survey(osv.osv):
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.mail.compose.message',
|
||||
'target': 'new',
|
||||
'context': ctx,
|
||||
@@ -233,7 +234,7 @@ class survey_page(osv.osv):
|
||||
_name = 'survey.page'
|
||||
_description = 'Survey Pages'
|
||||
_rec_name = 'title'
|
||||
_order = 'sequence'
|
||||
_ or der = 'sequence'
|
||||
_columns = {
|
||||
'title': fields.char('Page Title', size=128, required=1),
|
||||
'survey_id': fields.many2one('survey', 'Survey', ondelete='cascade'),
|
||||
@@ -249,24 +250,21 @@ class survey_page(osv.osv):
|
||||
if context is None:
|
||||
context = {}
|
||||
data = super(survey_page, self).default_get(cr, uid, fields, context)
|
||||
if context.has_key('survey_id'):
|
||||
if context.get('survey_id'):
|
||||
data['survey_id'] = context.get('survey_id', False)
|
||||
return data
|
||||
|
||||
def survey_save(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
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')
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page_no' : context.get('page_number',0) })
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', 0)})
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
#'search_view_id': search_id[0],
|
||||
'context': context
|
||||
}
|
||||
|
||||
@@ -274,7 +272,7 @@ class survey_page(osv.osv):
|
||||
vals = {}
|
||||
current_rec = self.read(cr, uid, ids, context=context)
|
||||
title = _("%s (copy)") % (current_rec.get('title'))
|
||||
vals.update({'title':title})
|
||||
vals.update({'title': title})
|
||||
return super(survey_page, self).copy(cr, uid, ids, vals, context=context)
|
||||
|
||||
survey_page()
|
||||
@@ -284,7 +282,7 @@ class survey_question(osv.osv):
|
||||
_name = 'survey.question'
|
||||
_description = 'Survey Question'
|
||||
_rec_name = 'question'
|
||||
_order = 'sequence'
|
||||
_ or der = 'sequence'
|
||||
|
||||
def _calc_response(self, cr, uid, ids, field_name, arg, context=None):
|
||||
if len(ids) == 0:
|
||||
@@ -292,45 +290,45 @@ class survey_question(osv.osv):
|
||||
val = {}
|
||||
cr.execute("select question_id, count(id) as Total_response from \
|
||||
survey_response_line where state='done' and question_id IN %s\
|
||||
group by question_id" ,(tuple(ids),))
|
||||
group by question_id", (tuple(ids), ))
|
||||
ids1 = copy.deepcopy(ids)
|
||||
for rec in cr.fetchall():
|
||||
f or rec in cr.fetchall():
|
||||
ids1.remove(rec[0])
|
||||
val[rec[0]] = int(rec[1])
|
||||
for id in ids1:
|
||||
f or id in ids1:
|
||||
val[id] = 0
|
||||
return val
|
||||
|
||||
_columns = {
|
||||
'page_id': fields.many2one('survey.page', 'Survey Page', ondelete='cascade', required=1),
|
||||
'question': fields.char('Question', size=128, required=1),
|
||||
'question': fields.char('Question', size=128, required=1),
|
||||
'answer_choice_ids': fields.one2many('survey.answer', 'question_id', 'Answer'),
|
||||
'is_require_answer': fields.boolean('Require Answer to Question'),
|
||||
'required_type': fields.selection([('all','All'), ('at least','At Least'), ('at most','At Most'), ('exactly','Exactly'), ('a range','A Range')], 'Respondent must answer'),
|
||||
'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'),
|
||||
'req_err or _msg': fields.text('Err or Message'),
|
||||
'allow_comment': fields.boolean('Allow Comment Field'),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'tot_resp': fields.function(_calc_response, string="Total Answer"),
|
||||
'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)'),
|
||||
('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)'),
|
||||
('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,),
|
||||
'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)'),
|
||||
('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)'),
|
||||
('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, ),
|
||||
'is_comment_require': fields.boolean('Add Comment Field'),
|
||||
'comment_label': fields.char('Field Label', size = 255),
|
||||
'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.'''),
|
||||
('must_be_specific_length', 'Must Be Specific Length'),
|
||||
@@ -345,15 +343,15 @@ class survey_question(osv.osv):
|
||||
'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'),
|
||||
'comment_valid_err_msg': fields.text('Err or message'),
|
||||
'make_comment_field': fields.boolean('Make Comment Field an Answer Choice'),
|
||||
'make_comment_field_err_msg': fields.text('Error message'),
|
||||
'make_comment_field_err_msg': fields.text('Err or message'),
|
||||
'is_validation_require': fields.boolean('Validate Text'),
|
||||
'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'),\
|
||||
'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'), \
|
||||
('must_be_email_address', 'Must Be An Email Address')\
|
||||
], 'Text Validation'),
|
||||
'validation_minimum_no': fields.integer('Minimum number'),
|
||||
@@ -362,31 +360,31 @@ class survey_question(osv.osv):
|
||||
'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'),
|
||||
'validation_valid_err_msg': fields.text('Err or message'),
|
||||
'numeric_required_sum': fields.integer('Sum of all choices'),
|
||||
'numeric_required_sum_err_msg': fields.text('Error message'),
|
||||
'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (Forced Ranking)'),
|
||||
'numeric_required_sum_err_msg': fields.text('Err or message'),
|
||||
'rating_allow_one_column_require': fields.boolean('Allow Only One Answer per Column (F or ced Ranking)'),
|
||||
'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),
|
||||
'column_name': fields.char('Column Name', size=256),
|
||||
'no_of_rows': fields.integer('No of Rows'),
|
||||
}
|
||||
_defaults = {
|
||||
'sequence': lambda * a: 1,
|
||||
'type': lambda * a: 'multiple_choice_multiple_ans',
|
||||
'req_error_msg': lambda * a: 'This question requires an answer.',
|
||||
'req_err or _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.',
|
||||
'comment_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.',
|
||||
'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.',
|
||||
'validation_valid_err_msg': lambda * a: 'The comment you entered is in an invalid f or mat.',
|
||||
'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
|
||||
}
|
||||
|
||||
@@ -402,101 +400,76 @@ class survey_question(osv.osv):
|
||||
return {'value': val}
|
||||
|
||||
if type in ['rating_scale']:
|
||||
val.update({'in_visible_rating_weight':False, 'in_visible_menu_choice':True})
|
||||
val.update({'in_visible_rating_weight': False, 'in_visible_menu_choice': True})
|
||||
return {'value': val}
|
||||
|
||||
elif type in ['single_textbox']:
|
||||
val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':True})
|
||||
val.update({'in_visible_rating_weight': True, 'in_visible_menu_choice': True})
|
||||
return {'value': val}
|
||||
|
||||
else:
|
||||
val.update({'in_visible_rating_weight':True, 'in_visible_menu_choice':True,\
|
||||
'in_visible_answer_type':True})
|
||||
val.update({'in_visible_rating_weight': True, 'in_visible_menu_choice': True, \
|
||||
'in_visible_answer_type': True})
|
||||
return {'value': val}
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
questions = self.read(cr,uid, ids, ['answer_choice_ids', 'type', 'required_type',\
|
||||
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'])
|
||||
for question in questions:
|
||||
f or 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
|
||||
f or col in vals.get('column_heading_ids', []):
|
||||
if type(col[2]) == type({}):
|
||||
col_len += 1
|
||||
else:
|
||||
col_len -= 1
|
||||
|
||||
if vals.has_key('type'):
|
||||
que_type = vals['type']
|
||||
else:
|
||||
que_type = question['type']
|
||||
que_type = vals.get('type', question['type'])
|
||||
|
||||
if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale']:
|
||||
if not col_len:
|
||||
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]))
|
||||
raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.') % (question['question'], question['page_id'][1]))
|
||||
ans_len = len(question['answer_choice_ids'])
|
||||
|
||||
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
|
||||
f or ans in vals.get('answer_choice_ids', []):
|
||||
if type(ans[2]) == type({}):
|
||||
ans_len += 1
|
||||
else:
|
||||
ans_len -= 1
|
||||
|
||||
if que_type not in ['descriptive_text', 'single_textbox', 'comment','table']:
|
||||
if que_type not in ['descriptive_text', 'single_textbox', 'comment', 'table']:
|
||||
if not ans_len:
|
||||
raise osv.except_osv(_('Warning!'),_('You must enter one or more Answers for question "%s" of page %s.') % (question['question'], question['page_id'][1]))
|
||||
req_type = ""
|
||||
raise osv.except_osv(_('Warning!'), _('You must enter one or m or e Answers f or question "%s" of page %s.') % (question['question'], question['page_id'][1]))
|
||||
|
||||
if vals.has_key('required_type'):
|
||||
req_type = vals['required_type']
|
||||
else:
|
||||
req_type = question['required_type']
|
||||
req_type = vals.get('required_type', question['required_type'])
|
||||
|
||||
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']:
|
||||
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']:
|
||||
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:
|
||||
raise osv.except_osv(_('Warning!'),_("#Required Answer you entered \
|
||||
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 \
|
||||
is greater than the number of answer. \
|
||||
Please use a number that is smaller than %d.") % (ans_len + 1))
|
||||
else:
|
||||
if not question['req_ans'] or question['req_ans'] > ans_len:
|
||||
raise osv.except_osv(_('Warning!'),_("#Required Answer you entered is \
|
||||
if not question['req_ans'] or question['req_ans'] > ans_len:
|
||||
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.") % (ans_len + 1))
|
||||
|
||||
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:
|
||||
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))
|
||||
else:
|
||||
minimum_ans = question['minimum_req_ans']
|
||||
if not question['minimum_req_ans'] or question['minimum_req_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))
|
||||
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:
|
||||
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.") % (ans_len + 1))
|
||||
else:
|
||||
maximum_ans = question['maximum_req_ans']
|
||||
if not question['maximum_req_ans'] or question['maximum_req_ans'] > ans_len:
|
||||
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.") % (ans_len + 1))
|
||||
error = False
|
||||
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))
|
||||
if maximum_ans <= minimum_ans:
|
||||
raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater \
|
||||
raise osv.except_osv(_('Warning!'), _("Maximum Required Answer is greater \
|
||||
than Minimum Required Answer"))
|
||||
|
||||
return super(survey_question, self).write(cr, uid, ids, vals, context=context)
|
||||
@@ -505,28 +478,28 @@ class survey_question(osv.osv):
|
||||
minimum_ans = 0
|
||||
maximum_ans = 0
|
||||
page = self.pool.get('survey.page').browse(cr, uid, vals['page_id'], context=context).title
|
||||
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']:
|
||||
raise osv.except_osv(_('Warning!'),_('You must enter one or more answers for question "%s" of page %s .') % (vals['question'], page))
|
||||
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']:
|
||||
raise osv.except_osv(_('Warning!'), _('You must enter one or m or e answers f or question "%s" of page %s .') % (vals['question'], page))
|
||||
|
||||
if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']):
|
||||
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', 'rating_scale']:
|
||||
raise osv.except_osv(_('Warning!'),_('You must enter one or more column headings for question "%s" of page %s.')% (vals['question'], page))
|
||||
raise osv.except_osv(_('Warning!'), _('You must enter one or m or e column headings f or question "%s" of page %s.')% (vals['question'], page))
|
||||
|
||||
if vals['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['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.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']:
|
||||
if vals.has_key('answer_choice_ids') and vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']:
|
||||
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))
|
||||
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.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']
|
||||
if vals.has_key('answer_choice_ids') or vals['minimum_req_ans'] > len(vals['answer_choice_ids']) or not vals['minimum_req_ans']:
|
||||
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))
|
||||
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 vals.has_key('answer_choice_ids') or vals['maximum_req_ans'] > len(vals['answer_choice_ids']) or not vals['maximum_req_ans']:
|
||||
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))
|
||||
raise osv.except_osv(_('Warning!'), _("Maximum Required Answer you entered f or 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 maximum_ans <= minimum_ans:
|
||||
raise osv.except_osv(_('Warning!'),_("Maximum Required Answer is greater than Minimum Required Answer."))
|
||||
raise osv.except_osv(_('Warning!'), _("Maximum Required Answer is greater than Minimum Required Answer."))
|
||||
|
||||
res = super(survey_question, self).create(cr, uid, vals, context)
|
||||
return res
|
||||
@@ -535,12 +508,12 @@ class survey_question(osv.osv):
|
||||
if context is None:
|
||||
context = {}
|
||||
search_obj = self.pool.get('ir.ui.view')
|
||||
search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
|
||||
search_id = search_obj.search(cr, uid, [('model', '=', 'survey.question.wiz'), ('name', '=', 'Survey Search')])
|
||||
surv_name_wiz = self.pool.get('survey.name.wiz')
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page_no' : context.get('page_number',False) })
|
||||
surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'transfer': True, 'page_no': context.get('page_number', False)})
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'f or m',
|
||||
'view_mode': 'f or m',
|
||||
'res_model': 'survey.question.wiz',
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
@@ -570,7 +543,7 @@ class survey_question_column_heading(osv.osv):
|
||||
if context.get('in_visible_rating_weight', False):
|
||||
return context['in_visible_rating_weight']
|
||||
return False
|
||||
def _get_in_visible_menu_choice(self,cr, uid, context=None):
|
||||
def _get_in_visible_menu_choice(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context.get('in_visible_menu_choice', False):
|
||||
@@ -596,15 +569,15 @@ class survey_answer(osv.osv):
|
||||
_name = 'survey.answer'
|
||||
_description = 'Survey Answer'
|
||||
_rec_name = 'answer'
|
||||
_order = 'sequence'
|
||||
_ or der = 'sequence'
|
||||
|
||||
def _calc_response_avg(self, cr, uid, ids, field_name, arg, context=None):
|
||||
val = {}
|
||||
for rec in self.browse(cr, uid, ids, context=context):
|
||||
cr.execute("select count(question_id) ,(select count(answer_id) \
|
||||
f or rec in self.browse(cr, uid, ids, context=context):
|
||||
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 \
|
||||
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()
|
||||
@@ -629,16 +602,16 @@ class survey_answer(osv.osv):
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'response': fields.function(_calc_response_avg, string="#Answer", multi='sums'),
|
||||
'average': fields.function(_calc_response_avg, string="#Avg", multi='sums'),
|
||||
'type': fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),\
|
||||
('integer','Integer'),('float','Float'),('selection','Selection'),\
|
||||
('email','Email')], "Type of Answer",required=1),
|
||||
'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'),
|
||||
'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??')
|
||||
}
|
||||
_defaults = {
|
||||
# 'sequence' : lambda * a: 1,
|
||||
'type' : lambda * a: 'char',
|
||||
'in_visible_answer_type':_get_in_visible_answer_type,
|
||||
# 'sequence': lambda * a: 1,
|
||||
'type': lambda * a: 'char',
|
||||
'in_visible_answer_type': _get_in_visible_answer_type,
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
@@ -655,32 +628,32 @@ class survey_response(osv.osv):
|
||||
_rec_name = 'date_create'
|
||||
_columns = {
|
||||
'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='cascade'),
|
||||
'date_create' : fields.datetime('Create Date', required=1),
|
||||
'response_type' : fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1),
|
||||
'question_ids' : fields.one2many('survey.response.line', 'response_id', 'Answer'),
|
||||
'state' : fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True),
|
||||
'survey_id': fields.many2one('survey', 'Survey', required=1, readonly=1, ondelete='cascade'),
|
||||
'date_create': fields.datetime('Create Date', required=1),
|
||||
'response_type': fields.selection([('manually', 'Manually'), ('link', 'Link')], 'Answer Type', required=1),
|
||||
'question_ids': fields.one2many('survey.response.line', 'response_id', 'Answer'),
|
||||
'state': fields.selection([('new', 'Not Started'), ('skip', 'Not Finished'), ('done', 'Finished')], 'Status', readonly=True),
|
||||
'token': fields.char("Indentification token", readonly=1),
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner', readonly=1),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', readonly=1),
|
||||
'email': fields.char("Email", size=64, readonly=1),
|
||||
}
|
||||
_defaults = {
|
||||
'state' : lambda * a: "new",
|
||||
'response_type' : lambda * a: "manually",
|
||||
'state': lambda * a: "new",
|
||||
'response_type': lambda * a: "manually",
|
||||
}
|
||||
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
if not len(ids):
|
||||
return []
|
||||
reads = self.read(cr, uid, ids, ['partner_id','date_create'], context=context)
|
||||
reads = self.read(cr, uid, ids, ['partner_id', 'date_create'], context=context)
|
||||
res = []
|
||||
for record in reads:
|
||||
name = (record['partner_id'] and record['partner_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')'
|
||||
res.append((record['id'], name))
|
||||
f or rec or d in reads:
|
||||
name = (rec or d['partner_id'] and rec or d['partner_id'][1] or '') + ' (' + rec or d['date_create'].split('.')[0] + ')'
|
||||
res.append((rec or d['id'], name))
|
||||
return res
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
raise osv.except_osv(_('Warning!'),_('You cannot duplicate the resource!'))
|
||||
raise osv.except_osv(_('Warning!'), _('You cannot duplicate the resource!'))
|
||||
|
||||
survey_response()
|
||||
|
||||
@@ -692,7 +665,7 @@ class survey_response_line(osv.osv):
|
||||
_columns = {
|
||||
'response_id': fields.many2one('survey.response', 'Answer', ondelete='cascade'),
|
||||
'date_create': fields.datetime('Create Date', required=1),
|
||||
'state': fields.selection([('draft', 'Draft'), ('done', 'Answered'),('skip', 'Skiped')],\
|
||||
'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', \
|
||||
@@ -704,7 +677,7 @@ class survey_response_line(osv.osv):
|
||||
'single_text': fields.char('Text', size=255),
|
||||
}
|
||||
_defaults = {
|
||||
'state' : lambda * a: "draft",
|
||||
'state': lambda * a: "draft",
|
||||
}
|
||||
|
||||
survey_response_line()
|
||||
@@ -712,7 +685,7 @@ survey_response_line()
|
||||
|
||||
class survey_tbl_column_heading(osv.osv):
|
||||
_name = 'survey.tbl.column.heading'
|
||||
_order = 'name'
|
||||
_ or der = 'name'
|
||||
_columns = {
|
||||
'name': fields.integer('Row Number'),
|
||||
'column_id': fields.many2one('survey.question.column.heading', 'Column'),
|
||||
@@ -730,7 +703,7 @@ class survey_response_answer(osv.osv):
|
||||
_columns = {
|
||||
'response_id': fields.many2one('survey.response.line', 'Answer', ondelete='cascade'),
|
||||
'answer_id': fields.many2one('survey.answer', 'Answer', required=1, ondelete='cascade'),
|
||||
'column_id': fields.many2one('survey.question.column.heading','Column'),
|
||||
'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'),
|
||||
@@ -748,4 +721,4 @@ class res_partner(osv.osv):
|
||||
}
|
||||
res_partner()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim: exp and tab: smartindent: tabstop=4: softtabstop=4: shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user