Skip to content

Commit

Permalink
Added survey_question_type_nps and survey_xlsx modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed Dec 18, 2024
1 parent 00e617c commit 067e200
Show file tree
Hide file tree
Showing 33 changed files with 1,887 additions and 0 deletions.
76 changes: 76 additions & 0 deletions survey_question_type_nps/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
========================
Survey nps question type
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:76a27f032c62a377e23304d132148f6d4670e4db5bb689ad9e60f0b5cd3262cb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/16.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-16-0/survey-16-0-survey_question_type_nps
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/survey&target_branch=16.0
:alt: Try me on Runboat

|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 <https://github.com/OCA/survey/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_question_type_nps%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Souheil Bejaoui <[email protected]>

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 <https://github.com/OCA/survey/tree/16.0/survey_question_type_nps>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions survey_question_type_nps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions survey_question_type_nps/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
},
}
112 changes: 112 additions & 0 deletions survey_question_type_nps/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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: 2024-11-18 10:06+0000\n"
"Last-Translator: mymage <[email protected]>\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 5.6.2\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 ""
"<i class=\"fa fa-frown-o fa-2x text-danger\" title=\"face1\"/>\n"
" <i class=\"fa fa-frown-o fa-2x text-danger\" "
"title=\"face2\"/>\n"
" <i class=\"fa fa-frown-o fa-2x text-danger\" "
"title=\"face3\"/>\n"
" <i class=\"fa fa-meh-o fa-2x text-warning\" "
"title=\"face4\"/>\n"
" <i class=\"fa fa-smile-o fa-2x text-success\" "
"title=\"face5\"/>"
msgstr ""
"<i class=\"fa fa-frown-o fa-2x text-danger\" title=\"viso1\"/>\n"
" <i class=\"fa fa-frown-o fa-2x text-danger\" title="
"\"viso2\"/>\n"
" <i class=\"fa fa-frown-o fa-2x text-danger\" title="
"\"viso3\"/>\n"
" <i class=\"fa fa-meh-o fa-2x text-warning\" title=\"viso4"
"\"/>\n"
" <i class=\"fa fa-smile-o fa-2x text-success\" title="
"\"viso5\"/>"

#. module: survey_question_type_nps
#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.avg_nps
msgid ""
"<span class=\"badge text-bg-secondary only_left_radius px-2 pt-1\">Average </"
"span>"
msgstr ""
"<span class=\"badge text-bg-secondary only_left_radius px-2 pt-1\""
">Media</span>"

#. module: survey_question_type_nps
#. odoo-python
#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0
#, python-format
msgid "Answer is not in the right range"
msgstr "La risposta non è nell'intervallo corretto"

#. module: survey_question_type_nps
#: model_terms:ir.ui.view,arch_db:survey_question_type_nps.avg_nps
msgid "Average"
msgstr "Media"

#. 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 "Punteggio NPS"

#. module: survey_question_type_nps
#. odoo-python
#: code:addons/survey_question_type_nps/models/survey_user_input_line.py:0
#, python-format
msgid "NPS rate question must have numeric answer"
msgstr "La domanda valutazione NPS deve avere una risposta numerica"

#. module: survey_question_type_nps
#: model:ir.model.fields,field_description:survey_question_type_nps.field_survey_question__question_type
msgid "Question Type"
msgstr "Tipo di domanda"

#. 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 "Valorizza NPS"

#~ msgid "Display Name"
#~ msgstr "Nome visualizzato"

#~ msgid "ID"
#~ msgstr "ID"

#~ msgid "Last Modified on"
#~ msgstr "Ultima modifica il"
2 changes: 2 additions & 0 deletions survey_question_type_nps/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import survey_question
from . import survey_user_input_line
63 changes: 63 additions & 0 deletions survey_question_type_nps/models/survey_question.py
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions survey_question_type_nps/models/survey_user_input_line.py
Original file line number Diff line number Diff line change
@@ -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"))
1 change: 1 addition & 0 deletions survey_question_type_nps/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Souheil Bejaoui <[email protected]>
1 change: 1 addition & 0 deletions survey_question_type_nps/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module add NPS rating question type for survey page
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 067e200

Please sign in to comment.