[IMP] survey: rename and improve statistics fields
Purpose is to clean a bit those fields. A field holding the number of send invitations is added as well as a button. It allows to directly jump on answer linked to an invite which helps dealing with private surveys. This commit is linked to task ID 1935176 and PR #30689 .
This commit is contained in:
@@ -54,9 +54,9 @@ class Survey(models.Model):
|
||||
users_can_signup = fields.Boolean('Users can signup', compute='_compute_users_can_signup')
|
||||
public_url = fields.Char("Public link", compute="_compute_survey_url")
|
||||
# statistics
|
||||
tot_sent_survey = fields.Integer("Number of sent surveys", compute="_compute_survey_statistic")
|
||||
tot_start_survey = fields.Integer("Number of started surveys", compute="_compute_survey_statistic")
|
||||
tot_comp_survey = fields.Integer("Number of completed surveys", compute="_compute_survey_statistic")
|
||||
invite_count = fields.Integer("Invite", compute="_compute_survey_statistic")
|
||||
answer_count = fields.Integer("Started", compute="_compute_survey_statistic")
|
||||
answer_done_count = fields.Integer("Completed", compute="_compute_survey_statistic")
|
||||
|
||||
_sql_constraints = [
|
||||
('access_token_unique', 'unique(access_token)', 'Access token should be unique')
|
||||
@@ -68,19 +68,22 @@ class Survey(models.Model):
|
||||
for survey in self:
|
||||
survey.users_can_signup = signup_allowed
|
||||
|
||||
@api.multi
|
||||
@api.depends('user_input_ids.state', 'user_input_ids.test_entry')
|
||||
def _compute_survey_statistic(self):
|
||||
stat = dict.fromkeys(self.ids, {'invite_count': 0, 'answer_count': 0, 'answer_done_count': 0})
|
||||
UserInput = self.env['survey.user_input']
|
||||
base_domain = ['&', ('survey_id', 'in', self.ids), ('test_entry', '!=', True)]
|
||||
|
||||
sent_survey = UserInput.search(expression.AND([base_domain, [('input_type', '=', 'link')]]))
|
||||
start_survey = UserInput.search(expression.AND([base_domain, ['|', ('state', '=', 'skip'), ('state', '=', 'done')]]))
|
||||
complete_survey = UserInput.search(expression.AND([base_domain, [('state', '=', 'done')]]))
|
||||
read_group_res = UserInput.read_group(base_domain, ['input_type', 'state'], ['survey_id', 'input_type', 'state'], lazy=False)
|
||||
for item in read_group_res:
|
||||
stat[item['survey_id'][0]]['answer_count'] += item['__count']
|
||||
if item['state'] == 'done':
|
||||
stat[item['survey_id'][0]]['answer_done_count'] += item['__count']
|
||||
if item['input_type'] == 'link':
|
||||
stat[item['survey_id'][0]]['invite_count'] += item['__count']
|
||||
|
||||
for survey in self:
|
||||
survey.tot_sent_survey = len(sent_survey.filtered(lambda user_input: user_input.survey_id == survey))
|
||||
survey.tot_start_survey = len(start_survey.filtered(lambda user_input: user_input.survey_id == survey))
|
||||
survey.tot_comp_survey = len(complete_survey.filtered(lambda user_input: user_input.survey_id == survey))
|
||||
survey.update(stat[survey.id])
|
||||
|
||||
def _compute_survey_url(self):
|
||||
""" Computes a public URL for the survey """
|
||||
@@ -406,7 +409,7 @@ class Survey(models.Model):
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_survey_user_input(self):
|
||||
def action_survey_user_input_completed(self):
|
||||
action_rec = self.env.ref('survey.action_survey_user_input_notest')
|
||||
action = action_rec.read()[0]
|
||||
ctx = dict(self.env.context)
|
||||
@@ -414,3 +417,13 @@ class Survey(models.Model):
|
||||
'search_default_completed': 1})
|
||||
action['context'] = ctx
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def action_survey_user_input_invite(self):
|
||||
action_rec = self.env.ref('survey.action_survey_user_input_notest')
|
||||
action = action_rec.read()[0]
|
||||
ctx = dict(self.env.context)
|
||||
ctx.update({'search_default_survey_id': self.ids[0],
|
||||
'search_default_invite': 1})
|
||||
action['context'] = ctx
|
||||
return action
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Survey">
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="tot_start_survey" invisible="1"/>
|
||||
<field name="is_closed" invisible="1"/>
|
||||
<header>
|
||||
<button name="action_test_survey" string="Test" type="object" attrs="{'invisible': [('id', '=', False)]}"/>
|
||||
@@ -18,11 +17,18 @@
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="action_survey_user_input"
|
||||
<button name="action_survey_user_input_invite"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
attrs="{'invisible': [('access_mode', '=', 'public')]}"
|
||||
icon="fa-envelope-o">
|
||||
<field string="Invitations" name="invite_count" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="action_survey_user_input_completed"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o">
|
||||
<field string="Answers" name="tot_comp_survey" widget="statinfo"/>
|
||||
<field string="Answers" name="answer_done_count" widget="statinfo"/>
|
||||
</button>
|
||||
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
|
||||
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
|
||||
@@ -82,9 +88,9 @@
|
||||
<field name="active" invisible="1"/>
|
||||
<field name="title" />
|
||||
<field name="stage_id" />
|
||||
<field name="tot_sent_survey" string="Invitations sent" />
|
||||
<field name="tot_start_survey" string="Started" />
|
||||
<field name="tot_comp_survey" string="Completed" />
|
||||
<field name="invite_count"/>
|
||||
<field name="answer_count"/>
|
||||
<field name="answer_done_count"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -95,9 +101,7 @@
|
||||
<kanban default_group_by="stage_id">
|
||||
<field name="stage_id" />
|
||||
<field name="title" />
|
||||
<field name="tot_sent_survey" />
|
||||
<field name="tot_start_survey" />
|
||||
<field name="tot_comp_survey" />
|
||||
<field name="answer_done_count" />
|
||||
<field name="color" />
|
||||
<field name="access_mode"/>
|
||||
<field name="activity_ids" />
|
||||
@@ -129,8 +133,8 @@
|
||||
<a type="object" name="action_send_survey">Share &amp; Invite</a>
|
||||
</li>
|
||||
<li>
|
||||
<t t-if="record.tot_start_survey.raw_value > 0"><a name="action_result_survey" type="object">Analyze Answers</a> <span t-if="record.tot_start_survey.raw_value > 0">(<field name="tot_start_survey" />)</span></t>
|
||||
<t t-if="record.tot_start_survey.raw_value <= 0"><a style="color: #aaaaaa;">Analyze Answers</a></t>
|
||||
<t t-if="record.answer_done_count.raw_value > 0"><a name="action_result_survey" type="object">Analyze Answers</a> <span t-if="record.answer_done_count.raw_value > 0">(<field name="answer_done_count" />)</span></t>
|
||||
<t t-if="record.answer_done_count.raw_value <= 0"><a style="color: #aaaaaa;">Analyze Answers</a></t>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<filter string="Partially Completed" name="partially_completed" domain="[('state', '=', 'skip')]"/>
|
||||
<filter string="New" name="new" domain="[('state', '=', 'new')]"/>
|
||||
<separator/>
|
||||
<filter string="Invite" name="invite" domain="[('input_type', '=', 'link')]"/>
|
||||
<separator/>
|
||||
<filter string="Test Entries" name="test" domain="[('test_entry','=', True)]"/>
|
||||
<group expand="0" string="Group By">
|
||||
<filter name="group_by_survey" string="Survey" domain="[]" context="{'group_by': 'survey_id'}"/>
|
||||
|
||||
Reference in New Issue
Block a user