[IMP] survey: in progress

bzr revid: chm@openerp.com-20130219163041-4spv2xve8kymham8
This commit is contained in:
Christophe Matthieu
2013-02-19 17:30:41 +01:00
parent 145f161e2a
commit 4b81cf6e8d
3 changed files with 45 additions and 69 deletions
+33 -48
View File
@@ -138,62 +138,41 @@ class survey(osv.osv):
}
return report
def _check_valid(self, cr, uid, ids, context=None):
sur_browse = self.browse(cr, uid, ids[0], context=context)
if not sur_browse.page_ids:
raise osv.except_osv(_('Warning!'), _('This survey has no question defined or has no pages defined. Please define the questions and answers first.'))
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:
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]})
self._check_valid(cr, uid, ids, context=context)
return {
'view_type': 'form',
'view_mode': 'form',
'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:
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({'ir_actions_act_window_target': 'new'})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'survey.question.wiz',
'type': 'ir.actions.act_window',
'target': 'inline',
'name': name,
'context': context
}
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:
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({'survey_id': ids[0]})
context.update({'ir_actions_act_window_target': 'new'})
id = ids[0]
context.update({'active': False, 'survey_id': id})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'survey.question.wiz',
'type': 'ir.actions.act_window',
'target': 'new',
'name': name,
'name': self.browse(cr, uid, id, context=context).title,
'context': context
}
def edit_survey(self, cr, uid, ids, context=None):
id = ids[0]
context.update({
'active': False,
'survey_id': id,
'edit': True,
'ir_actions_act_window_target': 'new'
})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'survey.question.wiz',
'type': 'ir.actions.act_window',
'target': 'new',
'name': self.browse(cr, uid, id, context=context).title,
'context': context
}
@@ -201,6 +180,12 @@ class survey(osv.osv):
'''
This function opens a window to compose an email, with the survey template message loaded by default
'''
self._check_valid(cr, uid, ids, context=context)
survey_browse = self.pool.get('survey').browse(cr, uid, ids, context=context)[0]
if survey_browse.state not in ["open", "restricted"]:
raise osv.except_osv(_('Warning!'), _("You cannot send invitations because the survey is not open."))
assert len(ids) == 1, 'This option should only be used for a single id at a time.'
ir_model_data = self.pool.get('ir.model.data')
try:
+10 -16
View File
@@ -32,7 +32,6 @@
</header>
<sheet>
<div class="oe_button_box oe_right">
<button name="test_survey" states="draft,open,restricted,close,cancel" string="Test Survey" type="object" icon="gtk-new" context="{'survey_id': active_id}" attrs="{'invisible':[('id','=',0)]}"/>
<button name="action_print_survey" states="draft,open,restricted,close,cancel" string="Print Answer" type="object"/>
<button name="edit_survey" states="draft,open,restricted,close,cancel"
string="Edit Survey" type="object" context="{'active':True,'edit' : True,'survey_id': active_id}"/>
@@ -245,9 +244,6 @@
<field name="tot_start_survey" string="Started"/>
<field name="tot_comp_survey" string="Completed"/>
<field name="state"/>
<button name="test_survey" states="open,draft,close,cancel"
string="Test Survey" type="object" icon="gtk-new"
context="{'survey_id': active_id}"/>
<button name="fill_survey" states="open"
string="Answer Survey" type="object" icon="gtk-execute" context="{'survey_id': active_id}" attrs="{'invisible':[('state','!=','open')]}"/>
<button name="action_print_survey" states="open,draft,close,cancel"
@@ -306,25 +302,23 @@
<div class="oe_kanban_content">
<h3 class="oe_kanban_ellipsis"><t t-esc="record.title.raw_value.toString()"></t></h3>
<div>
<span class="oe_kanban_right">
<a t-if="record.state.raw_value === 'draft'" title="Draft" class="oe_kanban_status"> </a>
<a t-if="record.state.raw_value === 'open'" title="Open freely" class="oe_kanban_status_green"> </a>
<a t-if="record.state.raw_value === 'restricted'" title="Restricted invitation" class="oe_kanban_status_darkgreen"> </a>
<a t-if="record.state.raw_value === 'close'" title="Close" class="oe_kanban_status_red"> </a>
<a t-if="record.state.raw_value === 'cancel'" title="Cancelled" class="oe_kanban_status_red"> </a>
</span>
Answers: <field name="tot_comp_survey"/>
<t t-if="record.max_response_limit.raw_value > 0"> / <field name="max_response_limit"/></t>
</div>
<br/>
<ul>
<t t-set="open" t-value="record.state.raw_value === 'open' or record.state.raw_value === 'restricted'"/>
<li t-if="widget.view.is_action_enabled('edit')"><a type="edit">Configuration</a></li>
<li t-if="widget.view.is_action_enabled('edit')"><a name="edit_survey" string="Edit Survey" type="object" context="{'active':True,'edit' : True}">Edit Survey</a></li>
<li t-if="widget.view.is_action_enabled('edit')"><a name="test_survey" type="object">Test Survey</a></li>
<li t-if="widget.view.is_action_enabled('edit')"><a name="action_survey_sent" type="object">Send invite by email</a></li>
<li>
<span class="oe_kanban_right">
<a t-if="record.state.raw_value === 'draft'" title="Draft" class="oe_kanban_status"> </a>
<a t-if="record.state.raw_value === 'open'" title="Open freely" class="oe_kanban_status_green"> </a>
<a t-if="record.state.raw_value === 'restricted'" title="Restricted invitation" class="oe_kanban_status_darkgreen"> </a>
<a t-if="record.state.raw_value === 'close'" title="Close" class="oe_kanban_status_red"> </a>
<a t-if="record.state.raw_value === 'cancel'" title="Cancelled" class="oe_kanban_status_red"> </a>
</span>
<a name="fill_survey" type="object">Answer Survey</a>
</li>
<li t-if="widget.view.is_action_enabled('edit')"><a t-att-style="!open?'color:#aaaaaa;':''" name="action_survey_sent" type="object">Send invite by email</a></li>
<li><a t-att-style="!open?'color:#aaaaaa;':''" name="fill_survey" type="object">Answer Survey</a></li>
<li t-if="widget.view.is_action_enabled('edit')"><a>Analysis</a></li>
</ul>
</div>
+2 -5
View File
@@ -244,7 +244,7 @@ class survey_question_wiz(osv.osv_memory):
res['response_id'] = response_id
res['state'] = 'new'
else:
elif not context.get('edit'):
response_ids = sur_response_obj.search(cr, uid, [('survey_id', '=', survey_id), '|', ("token", "=", context.get("survey_token", None)), ('partner_id', '=', pid)], context=context, limit=1, order="date_deadline DESC")
if not response_ids:
res['error_message'] = _("You do not have access to this survey.")
@@ -257,7 +257,7 @@ class survey_question_wiz(osv.osv_memory):
else:
res['error_message'] = _("You do not have access to this survey.")
if survey_browse.state not in ["open", "restricted"]:
if not context.get('edit') and survey_browse.state not in ["open", "restricted"]:
res['error_message'] = _("You cannot answer because the survey is not open.")
return res
@@ -339,9 +339,6 @@ class survey_question_wiz(osv.osv_memory):
if sur_name_read.page == "next" or sur_name_rec.page_no == -1:
if total_pages > sur_name_rec.page_no + 1:
if not active and not sur_name_rec.page_no + 1 and survey_browse.state not in ["open", "restricted"]:
raise osv.except_osv(_('Warning!'), _("You cannot answer because the survey is not open."))
if survey_browse.max_response_limit and survey_browse.max_response_limit <= survey_browse.tot_start_survey and not sur_name_rec.page_no + 1:
survey_obj.write(cr, uid, survey_id, {'state': 'close', 'date_close': datetime.now()})