diff --git a/setup/survey_question_type_nps/odoo/addons/survey_question_type_nps b/setup/survey_question_type_nps/odoo/addons/survey_question_type_nps new file mode 120000 index 00000000..0fd5890c --- /dev/null +++ b/setup/survey_question_type_nps/odoo/addons/survey_question_type_nps @@ -0,0 +1 @@ +../../../../survey_question_type_nps \ No newline at end of file diff --git a/setup/survey_question_type_nps/setup.py b/setup/survey_question_type_nps/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/survey_question_type_nps/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/survey_question_type_nps/README.rst b/survey_question_type_nps/README.rst new file mode 100644 index 00000000..a3f5ebe7 --- /dev/null +++ b/survey_question_type_nps/README.rst @@ -0,0 +1,73 @@ +======================== +Survey nps question type +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github + :target: https://github.com/OCA/survey/tree/14.0/survey_question_type_nps + :alt: OCA/survey +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/survey-14-0/survey-14-0-survey_question_type_nps + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/200/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module add NPS rating question type for survey page + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/survey `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/survey_question_type_nps/__init__.py b/survey_question_type_nps/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/survey_question_type_nps/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_question_type_nps/__manifest__.py b/survey_question_type_nps/__manifest__.py new file mode 100644 index 00000000..c12ab813 --- /dev/null +++ b/survey_question_type_nps/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Survey nps question type", + "summary": """ + This module add nps rating as question type for survey page""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/survey", + "depends": ["survey"], + "data": ["views/survey_question.xml", "views/survey_template.xml"], + "demo": [], + "assets": { + "survey.survey_assets": [ + "survey_question_type_nps/static/src/js/survey.js", + "survey_question_type_nps/static/src/scss/parameters.scss", + "survey_question_type_nps/static/src/scss/survey.scss", + ], + }, +} diff --git a/survey_question_type_nps/i18n/it.po b/survey_question_type_nps/i18n/it.po new file mode 100644 index 00000000..5b13d32d --- /dev/null +++ b/survey_question_type_nps/i18n/it.po @@ -0,0 +1,101 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_question_type_nps +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-05-29 15:09+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.nps_rate +msgid "10" +msgstr "10" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.survey_question_form +msgid "" +"\n" +" \n" +" \n" +" \n" +" " +msgstr "" + +#. module: survey_question_type_nps +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#, python-format +msgid "Answer is not in the right range" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__display_name +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input__display_name +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__id +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input__id +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__id +msgid "ID" +msgstr "ID" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question____last_update +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input____last_update +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.avg_nps +msgid "NPS Average" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields.selection,name:survey_question_type_nps.selection__survey_question__question_type__nps_rate +msgid "NPS Rating" +msgstr "" + +#. module: survey_question_type_nps +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#, python-format +msgid "NPS rate question must have numeric answer" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__question_type +msgid "Question Type" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_question +msgid "Survey Question" +msgstr "Domanda sondaggio" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_user_input +msgid "Survey User Input" +msgstr "Risposta utente al sondaggio" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_user_input_line +msgid "Survey User Input Line" +msgstr "Riga risposta utente al sondaggio" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__value_nps +msgid "Value Nps" +msgstr "" diff --git a/survey_question_type_nps/i18n/survey_question_type_nps.pot b/survey_question_type_nps/i18n/survey_question_type_nps.pot new file mode 100644 index 00000000..2687d8b8 --- /dev/null +++ b/survey_question_type_nps/i18n/survey_question_type_nps.pot @@ -0,0 +1,98 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_question_type_nps +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.nps_rate +msgid "10" +msgstr "" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.survey_question_form +msgid "" +"\n" +" \n" +" \n" +" \n" +" " +msgstr "" + +#. module: survey_question_type_nps +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#, python-format +msgid "Answer is not in the right range" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__display_name +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input__display_name +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__display_name +msgid "Display Name" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__id +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input__id +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__id +msgid "ID" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question____last_update +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input____last_update +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: survey_question_type_nps +#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.avg_nps +msgid "NPS Average" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields.selection,name:survey_question_type_nps.selection__survey_question__question_type__nps_rate +msgid "NPS Rating" +msgstr "" + +#. module: survey_question_type_nps +#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0 +#, python-format +msgid "NPS rate question must have numeric answer" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__question_type +msgid "Question Type" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_question +msgid "Survey Question" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_user_input +msgid "Survey User Input" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model,name:survey_question_type_nps.model_survey_user_input_line +msgid "Survey User Input Line" +msgstr "" + +#. module: survey_question_type_nps +#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_user_input_line__value_nps +msgid "Value Nps" +msgstr "" diff --git a/survey_question_type_nps/models/__init__.py b/survey_question_type_nps/models/__init__.py new file mode 100644 index 00000000..948dcfaf --- /dev/null +++ b/survey_question_type_nps/models/__init__.py @@ -0,0 +1,2 @@ +from . import survey_question +from . import survey_user_input_line diff --git a/survey_question_type_nps/models/survey_question.py b/survey_question_type_nps/models/survey_question.py new file mode 100644 index 00000000..85fd10da --- /dev/null +++ b/survey_question_type_nps/models/survey_question.py @@ -0,0 +1,63 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import collections + +from odoo import fields, models, tools + + +class SurveyQuestion(models.Model): + + _inherit = "survey.question" + + question_type = fields.Selection(selection_add=[("nps_rate", "NPS Rating")]) + + def _get_stats_summary_data(self, user_input_lines): + stats = super()._get_stats_summary_data(user_input_lines) + if self.question_type in ["nps_rate"]: + stats.update(self._get_stats_summary_data_numerical(user_input_lines)) + all_nps = user_input_lines.filtered( + lambda line: not line.skipped + and line.question_id.question_type == "nps_rate" + ).mapped("value_numerical_box") + stats.update( + { + "common_lines": collections.Counter( + user_input_lines.filtered(lambda line: not line.skipped).mapped( + "value_numerical_box" + ) + ).most_common(5), + "right_inputs_count": len( + user_input_lines.filtered( + lambda line: line.answer_is_correct + ).mapped("user_input_id") + ), + "average_nps": round(sum(all_nps) / len(all_nps), 2) + if all_nps + else 0.0, + } + ) + return stats + + def validate_nps_rate(self, post, answer_tag): + self.ensure_one() + errors = {} + answer = post[answer_tag].strip() + # Empty answer to mandatory question + if self.constr_mandatory and not answer: + errors.update({answer_tag: self.constr_error_msg}) + # Checks if user input is a number + if answer: + try: + floatanswer = float(answer) + except ValueError: + errors.update({answer_tag: "This is not a number"}) + return errors + # Answer is not in the right range + with tools.ignore(Exception): + # 0 answer to mandatory question + if self.constr_mandatory: + if floatanswer == 0: + errors.update({answer_tag: self.constr_error_msg}) + if not (0 <= floatanswer <= 10): + errors.update({answer_tag: "Answer is not in the right range"}) + return errors diff --git a/survey_question_type_nps/models/survey_user_input_line.py b/survey_question_type_nps/models/survey_user_input_line.py new file mode 100644 index 00000000..443d3650 --- /dev/null +++ b/survey_question_type_nps/models/survey_user_input_line.py @@ -0,0 +1,64 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class SurveyUserInput(models.Model): + _inherit = "survey.user_input" + + def save_lines(self, question, answer, comment=None): + old_answers = self.env["survey.user_input.line"].search( + [("user_input_id", "=", self.id), ("question_id", "=", question.id)] + ) + + if question.question_type in ["nps_rate"]: + return self._save_line_simple_answer(question, old_answers, answer) + else: + return super(SurveyUserInput, self).save_lines( + question, answer, comment=comment + ) + + def _get_line_answer_values(self, question, answer, answer_type): + vals = super(SurveyUserInput, self)._get_line_answer_values( + question, answer, answer_type + ) + if answer_type == "nps_rate" and answer: + value = float(answer) + nps = 1 if value >= 9 else -1 if value <= 6 else 0 + vals.update( + { + "value_numerical_box": float(answer), + "answer_type": "numerical_box", + "value_nps": nps, + } + ) + vals.pop("value_nps_rate") + return vals + + +class SurveyUserInputLine(models.Model): + + _inherit = "survey.user_input.line" + + value_nps = fields.Integer() + + @api.constrains("question_id", "answer_type", "value_numerical_box") + def _check_nps_rate_answer(self): + for rec in self: + if rec.question_id.question_type == "nps_rate": + if not rec.answer_type: + continue + if rec.answer_type != "numerical_box": + raise ValidationError( + _("NPS rate question must have numeric answer") + ) + if rec.question_id.constr_mandatory and not ( + 0 < rec.value_numerical_box <= 10 + ): + raise ValidationError(_("Answer is not in the right range")) + if not rec.question_id.constr_mandatory and not ( + 0 <= rec.value_numerical_box <= 10 + ): + raise ValidationError(_("Answer is not in the right range")) diff --git a/survey_question_type_nps/readme/CONTRIBUTORS.rst b/survey_question_type_nps/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..50e6298d --- /dev/null +++ b/survey_question_type_nps/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/survey_question_type_nps/readme/DESCRIPTION.rst b/survey_question_type_nps/readme/DESCRIPTION.rst new file mode 100644 index 00000000..dfae97be --- /dev/null +++ b/survey_question_type_nps/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module add NPS rating question type for survey page diff --git a/survey_question_type_nps/static/description/icon.png b/survey_question_type_nps/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/survey_question_type_nps/static/description/icon.png differ diff --git a/survey_question_type_nps/static/description/index.html b/survey_question_type_nps/static/description/index.html new file mode 100644 index 00000000..67b19a57 --- /dev/null +++ b/survey_question_type_nps/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Survey nps question type + + + +
+

Survey nps question type

+ + +

Beta License: AGPL-3 OCA/survey Translate me on Weblate Try me on Runbot

+

This module add NPS rating question type for survey page

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/survey project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/survey_question_type_nps/static/src/js/survey.js b/survey_question_type_nps/static/src/js/survey.js new file mode 100644 index 00000000..e541a170 --- /dev/null +++ b/survey_question_type_nps/static/src/js/survey.js @@ -0,0 +1,36 @@ +/* Copyright 2018 ACSONE SA/NV +License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).*/ +odoo.define("survey_question_type_nps", function (require) { + "use strict"; + var SurveyFormWidget = require("survey.form"); + SurveyFormWidget.include({ + events: _.extend({}, SurveyFormWidget.prototype.events, { + "click .nps_rate > label": "_onClickNPSLabel", + }), + _onClickNPSLabel: function (event) { + if (this.readonly) { + return; + } + var target = event.target; + var label_items = $(target).parent().find("label"); + var value = label_items.length - $(target).index(); + label_items.removeClass("checked"); + $(target).addClass("checked"); + var $input = $(target).parent().find("input"); + $input.val(value); + // We will trigger the change in order to make it compatible with conditional. + // If it is not installed, it has no effects + $input.trigger("change"); + }, + _prepareSubmitValues: function (formData, params) { + this._super.apply(this, arguments); + this.$("[data-question-type]").each(function () { + switch ($(this).data("questionType")) { + case "nps_rate": + params[this.name] = this.value; + break; + } + }); + }, + }); +}); diff --git a/survey_question_type_nps/static/src/scss/parameters.scss b/survey_question_type_nps/static/src/scss/parameters.scss new file mode 100644 index 00000000..f6d4b105 --- /dev/null +++ b/survey_question_type_nps/static/src/scss/parameters.scss @@ -0,0 +1,3 @@ +/* survey.scss parameters */ +$nps-widget-background-color: #fff; +$nps-widget-color: #0a0a0a; diff --git a/survey_question_type_nps/static/src/scss/survey.scss b/survey_question_type_nps/static/src/scss/survey.scss new file mode 100644 index 00000000..465180ed --- /dev/null +++ b/survey_question_type_nps/static/src/scss/survey.scss @@ -0,0 +1,51 @@ +/* Copyright 2018 ACSONE SA/NV +License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +.nps_rate_widget { + margin-left: 10px; +} +.nps_rate_widget > input { + display: none; +} +.nps_rate_widget > label { + font: 20px Arial, sans-serif; + + width: 2em; + height: 2em; + box-sizing: initial; + + background: $nps-widget-background-color; + border: 0.15em solid $nps-widget-color; + color: $nps-widget-color; + text-align: center; + border-radius: 50%; + + line-height: 2em; + box-sizing: content-box; + + float: right; + cursor: pointer; + margin: 10px; + + @include media-breakpoint-down(md) { + font: 16px Arial, sans-serif; + + width: 1.5em; + height: 1.5em; + box-sizing: initial; + text-align: center; + border-radius: 50%; + + line-height: 1.5em; + box-sizing: content-box; + + float: right; + cursor: pointer; + margin: 3px; + } +} +.nps_rate > label:hover, +.nps_rate_widget .checked { + color: $nps-widget-background-color; + background: $nps-widget-color; +} diff --git a/survey_question_type_nps/tests/__init__.py b/survey_question_type_nps/tests/__init__.py new file mode 100644 index 00000000..df7702e6 --- /dev/null +++ b/survey_question_type_nps/tests/__init__.py @@ -0,0 +1 @@ +from . import test_survey diff --git a/survey_question_type_nps/tests/test_survey.py b/survey_question_type_nps/tests/test_survey.py new file mode 100644 index 00000000..76257a32 --- /dev/null +++ b/survey_question_type_nps/tests/test_survey.py @@ -0,0 +1,110 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError + +from odoo.addons.survey.tests import common + + +class TestSurvey(common.SurveyCase): + def setUp(self): + super(TestSurvey, self).setUp() + User = self.env["res.users"].with_context(**{"no_reset_password": True}) + (group_survey_user, group_employee) = ( + self.ref("survey.group_survey_user"), + self.ref("base.group_user"), + ) + self.survey_manager = User.create( + { + "name": "Maria Riera", + "login": "Riera", + "email": "maria.riera@example.com", + "groups_id": [ + ( + 6, + 0, + [ + self.ref("survey.group_survey_manager"), + group_survey_user, + group_employee, + ], + ) + ], + } + ) + self.survey1 = ( + self.env["survey.survey"] + .with_user(self.survey_manager) + .create({"title": "S0", "page_ids": [(0, 0, {"title": "P0"})]}) + ) + self.page1 = ( + self.env["survey.question"] + .with_user(self.survey_manager) + .create( + { + "title": "First page", + "survey_id": self.survey1.id, + "sequence": 1, + "is_page": True, + } + ) + ) + self.user_input1 = ( + self.env["survey.user_input"] + .with_user(self.survey_manager) + .create( + { + "survey_id": self.survey1.id, + "partner_id": self.survey_manager.partner_id.id, + } + ) + ) + self.question1 = ( + self.env["survey.question"] + .with_user(self.survey_manager) + .create( + { + "title": "Test NPS Rate", + "page_id": self.page1.id, + "question_type": "nps_rate", + "validation_required": True, + } + ) + ) + self.answer_tag1 = "{}_{}_{}".format( + self.survey1.id, + self.page1.id, + self.question1.id, + ) + self._type_match["nps_rate"] = ("numerical_box", "value_numerical_box") + + def test_01_question_nps_rate_with_error_values(self): + error_results = [ + ("aaa", "This is not a number"), + ("-1", "Answer is not in the right range"), + ("11", "Answer is not in the right range"), + ] + for i in range(len(error_results)): + self.assertEqual( + self.question1.validate_nps_rate( + {self.answer_tag1: error_results[i][0]}, self.answer_tag1 + ), + {self.answer_tag1: error_results[i][1]}, + ) + + def test_02_question_nps_rate_with_valid_values(self): + for i in ("0", "6", "8"): + self.user_input1.save_lines(question=self.question1, answer=i) + self.assertEqual( + self.user_input1.user_input_line_ids.filtered( + lambda r: r.question_id == self.question1 + ).value_numerical_box, + float(i), + ) + + def test_03_question_nps_rate_with_constr_mandatory(self): + self.question1.constr_mandatory = True + with self.assertRaises(ValidationError): + self.user_input1.save_lines(question=self.question1, answer="0") + with self.assertRaises(ValidationError): + self.user_input1.save_lines(question=self.question1, answer="11") diff --git a/survey_question_type_nps/views/survey_question.xml b/survey_question_type_nps/views/survey_question.xml new file mode 100644 index 00000000..f4c2fe51 --- /dev/null +++ b/survey_question_type_nps/views/survey_question.xml @@ -0,0 +1,22 @@ + + + + + survey.question.form + survey.question + + + + +
+ + + + + +
+
+
+
+
diff --git a/survey_question_type_nps/views/survey_template.xml b/survey_question_type_nps/views/survey_template.xml new file mode 100644 index 00000000..38cda740 --- /dev/null +++ b/survey_question_type_nps/views/survey_template.xml @@ -0,0 +1,124 @@ + + + + + + + + +