summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2020-03-16 16:01:24 +0000
committerAurélien Warnon <awa@odoo.com>2020-03-31 10:44:00 +0000
commit42cac02d17d29d6b4c80aaf1736a36f9a34cf228 (patch)
treebf5a0ae628283e7b2eee72a910d375a19fd23d60
parent1e693d0de426121f12dcf0a90065e6b36de3b003 (diff)
[IMP] website_event_questions: allow analyzing attendees answers to event questions
This commit adds necessary views and actions for users to be able to conveniently analyze attendees answers. - A graph view showing counts of each suggestions for simple_choice questions - A pivot view showing registrations vs answers for simple_choice questions - A tree view showing textual answers values for text_box questions (Tree view is also available for simple_choice) LINKS PR #45497 Task 2189529
-rw-r--r--addons/website_event_questions/__manifest__.py1
-rw-r--r--addons/website_event_questions/models/event_question.py13
-rw-r--r--addons/website_event_questions/models/event_registration.py1
-rw-r--r--addons/website_event_questions/views/event_registration_answer_views.xml55
-rw-r--r--addons/website_event_questions/views/event_views.xml1
5 files changed, 71 insertions, 0 deletions
diff --git a/addons/website_event_questions/__manifest__.py b/addons/website_event_questions/__manifest__.py
index 0ab6e0f7267..c0c913a28ee 100644
--- a/addons/website_event_questions/__manifest__.py
+++ b/addons/website_event_questions/__manifest__.py
@@ -9,6 +9,7 @@
'data': [
'views/assets.xml',
'views/event_views.xml',
+ 'views/event_registration_answer_views.xml',
'views/event_registration_views.xml',
'views/event_question_views.xml',
'views/event_templates.xml',
diff --git a/addons/website_event_questions/models/event_question.py b/addons/website_event_questions/models/event_question.py
index 117cc0a2303..0eee8eef37b 100644
--- a/addons/website_event_questions/models/event_question.py
+++ b/addons/website_event_questions/models/event_question.py
@@ -40,6 +40,19 @@ class EventQuestion(models.Model):
raise UserError(_("You cannot change the question type of a question that already has answers!"))
return super(EventQuestion, self).write(vals)
+ def action_view_question_answers(self):
+ """ Allow analyzing the attendees answers to event questions in a convenient way:
+ - A graph view showing counts of each suggestions for simple_choice questions
+ (Along with secondary pivot and tree views)
+ - A tree view showing textual answers values for text_box questions. """
+ self.ensure_one()
+ action = self.env.ref('website_event_questions.action_event_registration_report').read()[0]
+ action['domain'] = [('question_id', '=', self.id)]
+ if self.question_type == 'simple_choice':
+ action['views'] = [(False, 'graph'), (False, 'pivot'), (False, 'tree')]
+ elif self.question_type == 'text_box':
+ action['views'] = [(False, 'tree')]
+ return action
class EventQuestionAnswer(models.Model):
""" Contains suggested answers to a 'simple_choice' event.question. """
diff --git a/addons/website_event_questions/models/event_registration.py b/addons/website_event_questions/models/event_registration.py
index 5bb81b48703..eac70dd75f6 100644
--- a/addons/website_event_questions/models/event_registration.py
+++ b/addons/website_event_questions/models/event_registration.py
@@ -17,6 +17,7 @@ class EventRegistrationAnswer(models.Model):
question_id = fields.Many2one('event.question', required=True, ondelete='cascade')
registration_id = fields.Many2one('event.registration', required=True, ondelete='cascade')
+ partner_id = fields.Many2one('res.partner', related='registration_id.partner_id')
event_id = fields.Many2one('event.event', related='registration_id.event_id')
question_type = fields.Selection(related='question_id.question_type')
value_answer_id = fields.Many2one('event.question.answer', string="Suggested answer")
diff --git a/addons/website_event_questions/views/event_registration_answer_views.xml b/addons/website_event_questions/views/event_registration_answer_views.xml
new file mode 100644
index 00000000000..fac4cd9d05b
--- /dev/null
+++ b/addons/website_event_questions/views/event_registration_answer_views.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="event_registration_answer_view_search" model="ir.ui.view">
+ <field name="name">event.registration.answer.view.search</field>
+ <field name="model">event.registration.answer</field>
+ <field name="arch" type="xml">
+ <search>
+ <field name="value_text_box" />
+ <field name="value_answer_id" />
+ <field name="question_id" />
+ </search>
+ </field>
+ </record>
+
+ <record id="event_registration_answer_view_tree" model="ir.ui.view">
+ <field name="name">event.registration.answer.view.tree</field>
+ <field name="model">event.registration.answer</field>
+ <field name="arch" type="xml">
+ <tree string="Answer Breakdown" create="0">
+ <field name="registration_id" optional="show" />
+ <field name="partner_id" optional="hide" />
+ <field name="question_id" optional="show" />
+ <field name="value_text_box" />
+ <field name="value_answer_id" string="Selected answer" />
+ </tree>
+ </field>
+ </record>
+
+ <record id="event_registration_answer_view_graph" model="ir.ui.view">
+ <field name="name">event.registration.answer.view.graph</field>
+ <field name="model">event.registration.answer</field>
+ <field name="arch" type="xml">
+ <graph string="Answer Breakdown">
+ <field name="value_answer_id" />
+ </graph>
+ </field>
+ </record>
+
+ <record id="event_registration_answer_view_pivot" model="ir.ui.view">
+ <field name="name">event.registration.answer.view.pivot</field>
+ <field name="model">event.registration.answer</field>
+ <field name="arch" type="xml">
+ <pivot string="Answer Breakdown">
+ <field name="registration_id" type="row"/>
+ <field name="value_answer_id" type="col"/>
+ </pivot>
+ </field>
+ </record>
+
+ <record id="action_event_registration_report" model="ir.actions.act_window">
+ <field name="name">Answer Breakdown</field>
+ <field name="res_model">event.registration.answer</field>
+ <field name="view_mode">search,tree,graph,pivot</field>
+ </record>
+</odoo>
diff --git a/addons/website_event_questions/views/event_views.xml b/addons/website_event_questions/views/event_views.xml
index 9be84b95c2f..d42565f51b2 100644
--- a/addons/website_event_questions/views/event_views.xml
+++ b/addons/website_event_questions/views/event_views.xml
@@ -44,6 +44,7 @@
<field name="question_type" string="Type" />
<field name="answer_ids" widget="many2many_tags"
attrs="{'invisible': [('question_type', '!=', 'simple_choice')]}" />
+ <button name="action_view_question_answers" type="object" class="fa fa-bar-chart p-0" title="Answer Breakdown" />
</tree>
<!-- Need to repeat the whole tree form here to be able to create answers properly
Without this, the sub-fields of answer_ids are unknown to the web framework.