[FIX] survey: correct osv_memory model to respect proper Model relationships + some cleanup

bzr revid: odo@openerp.com-20110927202843-d7yj3na2e9nkn8wp
This commit is contained in:
Olivier Dony 2011-09-27 22:28:43 +02:00
parent 674f3d794e
commit 5f91274850
8 changed files with 25 additions and 233 deletions

View File

@ -1281,6 +1281,7 @@
<field name="responsible_id" ref="base.user_demo"/>
<field name="max_response_limit">20</field>
<field name="type" ref="survey_type2"/>
<field name="state">open</field>
<field name="response_user">5</field>
</record>
</data>

View File

@ -144,8 +144,8 @@
Give answer of the survey, Run "Answer a Survey" wizard and select the survey and press on start button then run the selected survey.
-
!python {model: survey.name.wiz}: |
ids = self.create(cr, uid, {'survey_id': ref("survey_partner_0")})
self.action_next(cr, uid, [ids], context)
id = self.create(cr, uid, {'survey_id': ref("survey_partner_0")})
self.action_next(cr, uid, [id], context)
-
Give answer of the first and second page in "Partner Feedback" suvey.
-

View File

@ -40,14 +40,6 @@ class survey_question_wiz(osv.osv_memory):
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
"""
Fields View Get method :- generate the new view and display the survey pages of selected survey.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param view_id : view id of the current object.
@param view_type : which type of view is create. like :- form, tree ,search etc...
@param context: A standard dictionary for contextual values
@return : Dictionary value for created view of particular survey pages.
"""
result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \
@ -88,7 +80,7 @@ class survey_question_wiz(osv.osv_memory):
if not survey_id:
# Try one more time to find it
if sur_name_rec and sur_name_rec.survey_id:
survey_id = sur_name_rec.survey_id[0]
survey_id = sur_name_rec.survey_id.id
else:
# raise osv.except_osv(_('Error!'), _("Cannot locate survey for the question wizard!"))
# If this function is called without a survey_id in
@ -398,10 +390,10 @@ class survey_question_wiz(osv.osv_memory):
sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'})
if sur_rec.send_response:
survey_data = survey_obj.browse(cr, uid, int(survey_id))
survey_data = survey_obj.browse(cr, uid, survey_id)
response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response']
context.update({'response_id':response_id})
report = self.create_report(cr, uid, [int(survey_id)], 'report.survey.browse.response', survey_data.title,context)
report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context)
attachments = {}
file = open(addons.get_module_resource('survey', 'report') + survey_data.title + ".pdf")
file_data = ""
@ -445,15 +437,6 @@ class survey_question_wiz(osv.osv_memory):
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
"""
If any user give answer of survey then last create report of this answer and if 'E-mail Notification on Answer' set True in survey then send mail on responsible person of this survey and attach survey answer report in pdf format.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param res_ids: List of survey answer IDs,
@param report_name: name of the report,
@param file_name: To give file name of the report,
@param context: A standard dictionary for contextual values,
@return : Dictionary value for created report with file nameself.
"""
if not report_name or not res_ids:
return (False, Exception('Report name and Resources ids are required !!!'))
@ -474,13 +457,6 @@ class survey_question_wiz(osv.osv_memory):
def default_get(self, cr, uid, fields_list, context=None):
"""
Assign Default value in particular field. If Browse Answers wizard run then read the value into database and Assigne to a particular fields.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields_list: List of fields of current view,
@param context: A standard dictionary for contextual values,
@return : Dictionary value for fields list with value.
"""
value = {}
if context is None:
@ -556,13 +532,6 @@ class survey_question_wiz(osv.osv_memory):
def create(self, cr, uid, vals, context=None):
"""
Create the Answer of survey and store in survey.response object, and if set validation of question then check the value of question if value is wrong then raise the exception.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param vals: Values,
@param context: A standard dictionary for contextual values
@return : True.
"""
if context is None: context = {}
if context.has_key('active') and context.get('active',False):
@ -600,8 +569,8 @@ class survey_question_wiz(osv.osv_memory):
#click first time on next button then increemnet on total start suvey
if not sur_name_read['store_ans']:
his_id = self.pool.get('survey.history').create(cr, uid, {'user_id': uid, \
'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id']})
survey_id = int(sur_name_read['survey_id']) # This is a selection field (a string).
'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id'][0]})
survey_id = sur_name_read['survey_id'][0]
sur_rec = survey_obj.read(cr, uid, survey_id)
survey_obj.write(cr, uid, survey_id, {'tot_start_survey' : sur_rec['tot_start_survey'] + 1})
if context.has_key('cur_id'):
@ -1017,13 +986,6 @@ class survey_question_wiz(osv.osv_memory):
def action_new_question(self,cr, uid, ids, context=None):
"""
New survey.Question form.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open new survey.Qestion form.
"""
if context is None:
context = {}
@ -1045,13 +1007,6 @@ class survey_question_wiz(osv.osv_memory):
def action_new_page(self, cr, uid, ids, context=None):
"""
New survey.Page form.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open new survey.page form.
"""
if context is None:
context = {}
@ -1073,13 +1028,6 @@ class survey_question_wiz(osv.osv_memory):
def action_edit_page(self,cr, uid, ids, context=None):
"""
Edit survey.page.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Edit survey.page form.
"""
if context is None:
context = {}
@ -1102,13 +1050,6 @@ class survey_question_wiz(osv.osv_memory):
def action_delete_page(self,cr, uid, ids, context=None):
"""
Delete survey.page.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open next survey.page form, but delete the selected page.
"""
if context is None:
context = {}
@ -1135,13 +1076,6 @@ class survey_question_wiz(osv.osv_memory):
def action_edit_question(self,cr, uid, ids, context=None):
"""
Edit survey.question.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Edit survey.question form.
"""
if context is None:
context = {}
@ -1164,13 +1098,6 @@ class survey_question_wiz(osv.osv_memory):
def action_delete_question(self,cr, uid, ids, context=None):
"""
Delete survey.question.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open same survey.page form, but delete the selected survey.question in current survey.page.
"""
if context is None:
context = {}
@ -1198,13 +1125,6 @@ class survey_question_wiz(osv.osv_memory):
def action_forward_previous(self, cr, uid, ids, context=None):
"""
Goes to previous Survey Answer.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Previous Answer form.
"""
if context is None:
context = {}
@ -1230,13 +1150,6 @@ class survey_question_wiz(osv.osv_memory):
def action_forward_next(self, cr, uid, ids, context=None):
"""
Goes to Next Survey Answer.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Next Answer form.
"""
if context is None:
context = {}
@ -1262,13 +1175,6 @@ class survey_question_wiz(osv.osv_memory):
def action_next(self, cr, uid, ids, context=None):
"""
Goes to Next page.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Next survey.page form.
"""
if context is None:
context = {}
@ -1289,13 +1195,6 @@ class survey_question_wiz(osv.osv_memory):
def action_previous(self, cr, uid, ids, context=None):
"""
Goes to previous page.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.question.wiz IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Open Previous survey.page form.
"""
if context is None:
context = {}

View File

@ -24,26 +24,9 @@ from osv import fields
class survey_browse_answer(osv.osv_memory):
_name = 'survey.browse.answer'
def _get_survey(self, cr, uid, context=None):
"""
Set the value in survey_id field,
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param context: A standard dictionary for contextual values,
@return : Tuple in list with values.
"""
surv_obj = self.pool.get("survey")
surv_resp_obj = self.pool.get("survey.response")
result = []
for sur in surv_obj.browse(cr, uid, surv_obj.search(cr, uid, [])):
if surv_resp_obj.search(cr, uid, [('survey_id', '=', sur.id)]):
result.append((sur.id, sur.title))
return result
_columns = {
'survey_id': fields.selection(_get_survey, "Survey", required="1"),
'survey_id': fields.many2one('survey', "Survey", required="1"),
'response_id': fields.many2one("survey.response", "Survey Answers", help="If this field is empty, all answers of the selected survey will be print."),
}
@ -51,13 +34,6 @@ class survey_browse_answer(osv.osv_memory):
"""
Open Browse Response wizard. if you select only survey_id then this wizard open with all response_ids and
if you select survey_id and response_id then open the particular response of the survey.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of survey.browse.answer IDs,
@param context: A standard dictionary for contextual values,
@return : Dictionary value for Open the browse answer wizard.
"""
if context is None: context = {}
record = self.read(cr, uid, ids, [])
@ -66,8 +42,8 @@ class survey_browse_answer(osv.osv_memory):
res_id = [(record.get('response_id') and record['response_id'][0])]
else:
sur_response_obj = self.pool.get('survey.response')
res_id = sur_response_obj.search(cr, uid, [('survey_id', '=',int(record['survey_id']))])
context.update({'active' : True,'survey_id' : record['survey_id'], 'response_id' : res_id, 'response_no' : 0})
res_id = sur_response_obj.search(cr, uid, [('survey_id', '=', record['survey_id'][0])])
context.update({'active' : True,'survey_id' : record['survey_id'][0], 'response_id' : res_id, 'response_no' : 0})
search_obj = self.pool.get('ir.ui.view')
search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
return {

View File

@ -27,8 +27,7 @@ from tools.translate import _
class survey_print(osv.osv_memory):
_name = 'survey.print'
_columns = {
'survey_ids': fields.many2many('survey','survey_print_survey_rel',\
'survey_id','print_id', "Survey", required="1"),
'survey_ids': fields.many2many('survey', string="Survey", required="1"),
'orientation' : fields.selection([('vertical','Portrait(Vertical)'),\
('horizontal','Landscape(Horizontal)')], 'Orientation'),
'paper_size' : fields.selection([('letter','Letter (8.5" x 11")'),\

View File

@ -26,20 +26,12 @@ from tools.translate import _
class survey_print_statistics(osv.osv_memory):
_name = 'survey.print.statistics'
_columns = {
'survey_ids': fields.many2many('survey','survey_print_statistics_survey_rel','survey_id',\
'print_id', "Survey", required="1"),
'survey_ids': fields.many2many('survey', string="Survey", required="1"),
}
def action_next(self, cr, uid, ids, context=None):
"""
Print Survey Statistics in pdf format.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Survey statistics IDs
@param context: A standard dictionary for contextual values
@return: Dictionary value for created survey statistics report
"""
if context is None:
context = {}

View File

@ -26,71 +26,8 @@ from tools.translate import _
class survey_name_wiz(osv.osv_memory):
_name = 'survey.name.wiz'
def default_get(self, cr, uid, fields, context=None):
"""
Set the default value in survey_id field. if open this wizard in survey form then set the default value in survey_id = active survey id.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of Survey statistics IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for created survey statistics report
"""
if context is None:
context = {}
data = super(survey_name_wiz, self).default_get(cr, uid, fields, context)
if context.has_key('survey_id'):
data['survey_id'] = context.get('survey_id',False)
return data
def _get_survey(self, cr, uid, context=None):
"""
Set the value In survey_id field.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Survey statistics IDs
@param context: A standard dictionary for contextual values
@return: Dictionary value for created survey statistics report
"""
surv_obj = self.pool.get("survey")
result = []
if context.has_key('survey_id'):
for sur in surv_obj.browse(cr, uid, [context.get('survey_id',False)]):
result.append((sur.id, sur.title))
return result
survey_user_group_id = self.pool.get('res.groups').search(cr, uid, [('name', '=', 'Survey / User')])
group_id = self.pool.get('res.groups').search(cr, uid, [('name', 'in', ('Tools / Manager','Tools / User','Survey / User'))])
user_obj = self.pool.get('res.users')
user_rec = user_obj.read(cr, uid, uid, ['groups_id', 'survey_id'], context)
if survey_user_group_id:
if survey_user_group_id == user_rec['groups_id']:
for sur in surv_obj.browse(cr, uid, surv_obj.search(cr, uid, [])):
if sur.state == 'open':
u_list = []
for use in sur.invited_user_ids:
u_list.append(use.id)
if uid in u_list:
result.append((sur.id, sur.title))
return result
for sur in surv_obj.browse(cr, uid, surv_obj.search(cr, uid, [])):
if sur.state == 'open':
res = False
for i in group_id:
if i in user_rec['groups_id']:
res = True
break
elif sur.id in user_rec['survey_id']:
res = True
break
if res:
result.append((sur.id, sur.title))
return result
_columns = {
'survey_id': fields.selection(_get_survey, "Survey", required="1"),
'survey_id': fields.many2one('survey', 'Survey', required=True, ondelete='cascade'),
'page_no': fields.integer('Page Number'),
'note': fields.text("Description"),
'page': fields.char('Page Position',size = 12),
@ -99,10 +36,11 @@ class survey_name_wiz(osv.osv_memory):
'response': fields.char('Answer',size=16)
}
_defaults = {
'page_no': lambda * a: - 1,
'page': lambda * a: 'next',
'transfer': lambda * a: 1,
'response': lambda * a: 0,
'page_no': -1,
'page': 'next',
'transfer': 1,
'response': 0,
'survey_id': lambda self,cr,uid,context:context.get('survey_id',False),
}
def action_next(self, cr, uid, ids, context=None):
@ -110,30 +48,22 @@ class survey_name_wiz(osv.osv_memory):
Start the survey, Increment in started survey field but if set the max_response_limit of
survey then check the current user how many times start this survey. if current user max_response_limit
is reach then this user can not start this survey(Raise Exception).
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Survey IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for open survey question wizard.
"""
survey_obj = self.pool.get('survey')
search_obj = self.pool.get('ir.ui.view')
if context is None: context = {}
this = self.browse(cr, uid, ids, context=context)[0]
survey_id = int(this.survey_id) # This is a selection field (a string).
survey_id = this.survey_id.id
context.update({'survey_id': survey_id, 'sur_name_id': this.id})
cr.execute('select count(id) from survey_history where user_id=%s\
and survey_id=%s' % (uid,survey_id))
res = cr.fetchone()[0]
user_limit = survey_obj.read(cr, uid, survey_id, ['response_user'])['response_user']
if user_limit and res >= user_limit:
sur_rec = survey_obj.browse(cr,uid,survey_id,context=context)
if sur_rec.response_user and res >= sur_rec.response_user:
raise osv.except_osv(_('Warning !'),_("You can not give response for this survey more than %s times") % (user_limit))
sur_rec = survey_obj.browse(cr,uid,ids,context=context)[0]
if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey:
raise osv.except_osv(_('Warning !'),_("You can not give more response. Please contact the author of this survey for further assistance."))
@ -152,16 +82,10 @@ class survey_name_wiz(osv.osv_memory):
def on_change_survey(self, cr, uid, ids, survey_id, context=None):
"""
on change event of survey_id field, if note is available in selected survey then display this note in note fields.
@param ids: List of Survey IDs
@param survey_id: Id of Survey
@param context: A standard dictionary for contextual values
@return : Dictionary values of notes fields.
"""
if not survey_id:
return {}
notes = self.pool.get('survey').read(cr, uid, survey_id, ['note'])['note']
return {'value': {'note': notes}}
survey_name_wiz()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -15,7 +15,8 @@
<separator colspan="4" string="Select Survey" />
<newline />
<field name="survey_id" colspan="4"
on_change="on_change_survey(survey_id)" width="250"/>
on_change="on_change_survey(survey_id)" width="250"
domain="[('state','=','open')]"/>
<group col="1" colspan="4"
attrs="{'readonly': [('survey_id','=',False)]}">
<separator colspan="4" string="Survey Details" />