from tools.translate import _
from time import strftime
-import datetime
+from datetime import datetime
+from dateutil.relativedelta import relativedelta
import copy
-from mx.DateTime import *
import os
class survey_type(osv.osv):
'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),
- 'max_response_limit': fields.integer('Maximum Answer Limit'),
+ 'max_response_limit': fields.integer('Maximum Answer Limit',
+ help="Set to one if survey is answerable only once"),
'response_user': fields.integer('Maximum Answer per User',
help="Set to one if you require only one Answer per user"),
'state': fields.selection([('draft', 'Draft'), ('open', 'Open'), ('close', 'Closed'), ('cancel', 'Cancelled')], 'Status', readonly=True),
- 'responsible_id': fields.many2one('res.users', 'Responsible'),
+ 'responsible_id': fields.many2one('res.users', 'Responsible', help="User responsible for 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),
'users': fields.many2many('res.users', 'survey_users_rel', 'sid', 'uid', 'Users'),
'send_response': fields.boolean('E-mail Notification on Answer'),
'type': fields.many2one('survey.type', 'Type'),
+ 'invited_user_ids': fields.many2many('res.users', 'survey_invited_user_rel', 'sid', 'uid', 'Invited User'),
}
_defaults = {
'state': lambda * a: "draft",
if not context:
context = {}
datas = {}
- response_id = self.pool.get('survey.response').search(cr, uid, [('survey_id','=', ids)], context=context)
+ 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
page_setting = {'orientation': 'vertical', 'without_pagebreak': 0, 'paper_size': 'letter', 'page_number': 1, 'survey_title': 1}
report = {}
- datas['ids'] = ids
- if response_id:
+ if response_id and response_id[0]:
context.update({'survey_id': datas['ids']})
datas['form'] = page_setting
datas['model'] = 'survey.print.answer'
'type': 'ir.actions.report.xml',
'report_name': 'survey.browse.response',
'datas': datas,
- 'nodestroy': True,
- 'context' : context
+ 'context' : context,
+ 'nodestroy':True,
}
else:
+
datas['form'] = page_setting
datas['model'] = 'survey.print'
report = {
'type': 'ir.actions.report.xml',
'report_name': 'survey.form',
'datas': datas,
+ 'context' : context,
'nodestroy':True,
- 'context' : context
}
return report
-
survey()
class survey_history(osv.osv):
return {}
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" % ",".join(map(str, map(int, ids))))
+ survey_response_line where state='done' and question_id IN %s\
+ group by question_id" ,(tuple(ids),))
ids1 = copy.deepcopy(ids)
for rec in cr.fetchall():
ids1.remove(rec[0])
'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'),
- 'is_require_answer': fields.boolean('Require Answer to Question (optional)'),
+ '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'),
'req_ans': fields.integer('#Required Answer'),
'maximum_req_ans': fields.integer('Maximum Required Answer'),
('date_and_time','Date and Time'),('descriptive_text','Descriptive Text'),
('table','Table'),
], 'Question Type', required=1,),
- 'is_comment_require': fields.boolean('Add Comment Field (optional)'),
+ 'is_comment_require': fields.boolean('Add Comment Field'),
'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.'''),
'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'),
- 'is_validation_require': fields.boolean('Validate Text (optional)'),
+ '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'),\
'in_visible_answer_type': fields.boolean('Is Answer Type Invisible??')
}
_defaults = {
- 'sequence' : lambda * a: 1,
+# 'sequence' : lambda * a: 1,
'type' : lambda * a: 'char',
'in_visible_answer_type':_get_in_visible_answer_type,
}
reads = self.read(cr, uid, ids, ['user_id','date_create'], context)
res = []
for record in reads:
- name = record['user_id'][1] + ' (' + record['date_create'].split('.')[0] + ')'
+ name = (record['user_id'] and record['user_id'][1] or '' )+ ' (' + record['date_create'].split('.')[0] + ')'
res.append((record['id'], name))
return res
}
_defaults = {
'state': lambda * a: 'draft',
- 'date_deadline': lambda * a : (now() + RelativeDateTime(months=+1)).strftime("%Y-%m-%d %H:%M:%S")
+# 'date_deadline': lambda * a : (datetime.now() + relativedelta(months=+1)).strftime("%Y-%m-%d %H:%M:%S")
}
def survey_req_waiting_answer(self, cr, uid, ids, arg):
self.write(cr, uid, ids, { 'state' : 'waiting_answer'})