Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] fieldservice_survey: add new module #1155

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions fieldservice_survey/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
===================
Fieldservice Survey
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f30f866be07068c593eb0ccaa0c5a07a84560d05d580608d4a172e14d178650b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Ffield--service-lightgray.png?logo=github
:target: https://github.com/OCA/field-service/tree/14.0/fieldservice_survey
:alt: OCA/field-service
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/field-service-14-0/field-service-14-0-fieldservice_survey
: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/field-service&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module introduces enhanced survey functionalities in the Field Service module, streamlining the process of collecting and analyzing feedback for service orders. Users can seamlessly navigate to Field Service, access settings, and select a customized FSM Order Survey Template. When generating a new order, the system prompts users to submit a survey, facilitating efficient data collection.

The module further extends capabilities by incorporating an intuitive "Survey Answer" button within the order interface. This button provides users with the flexibility to either view comprehensive statistics derived from survey responses or directly edit the survey for any necessary adjustments.

With the Field Service Survey Enhancements module, businesses can effortlessly manage and optimize their survey processes, gaining valuable insights into service performance and customer satisfaction.

**Table of contents**

.. contents::
:local:

Usage
=====

* Navigate to Field Service
* Go to Settings
* Choose a FSM Order Survey Template
* Generate a new order
* Submit Survey
* Access the "Survey Answer" button in the order to either view the statistics or edit the survey.

Known issues / Roadmap
======================

* Improve survey data integrity by updating the fsm_order_person_id field in response to changes in the field service order's person_id.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/field-service/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/field-service/issues/new?body=module:%20fieldservice_survey%0Aversion:%2014.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
~~~~~~~

* Escodoo

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

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>

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/field-service <https://github.com/OCA/field-service/tree/14.0/fieldservice_survey>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions fieldservice_survey/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import wizard
from . import controllers
28 changes: 28 additions & 0 deletions fieldservice_survey/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Fieldservice Survey",
"summary": """
This module enable integration the fieldservice app with survey""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": [
"fieldservice",
"survey",
],
"data": [
"security/res_groups.xml",
"security/ir.model.access.csv",
"views/res_config_settings.xml",
"views/survey_survey.xml",
"views/survey_user_input.xml",
"views/fsm_order.xml",
"views/survey_templates_statistics.xml",
"data/fsm_order_survey_data.xml",
"data/mail_data.xml",
"wizard/fsm_order_survey_submit.xml",
],
}
1 change: 1 addition & 0 deletions fieldservice_survey/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
129 changes: 129 additions & 0 deletions fieldservice_survey/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright 2023 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, http
from odoo.exceptions import AccessDenied
from odoo.http import request
from odoo.osv import expression

from odoo.addons.survey.controllers.main import Survey

FSM_ORDER_ID = "fsm_order_id"
PARTNER_ID = "partner_id"
FSM_ORDER_PERSON_ID = "fsm_order_person_id"


class FsmOrderSurveySurvey(Survey):
def _get_user_input_domain(self, survey, line_filter_domain, **post):
user_input_domain = super()._get_user_input_domain(

Check warning on line 18 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L18

Added line #L18 was not covered by tests
survey, line_filter_domain, **post
)

fsm_order_id = post.get(FSM_ORDER_ID)

Check warning on line 22 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L22

Added line #L22 was not covered by tests
if not fsm_order_id:
return user_input_domain

Check warning on line 24 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L24

Added line #L24 was not covered by tests

try:
fsm_order = request.env["fsm.order"].sudo().browse(int(fsm_order_id))
except ValueError:
raise AccessDenied(_("Invalid FSM Order ID"))

Check warning on line 29 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L26-L29

Added lines #L26 - L29 were not covered by tests

user = request.env.user
partner = user.partner_id
person = request.env["fsm.person"].search([(PARTNER_ID, "=", partner.id)])

Check warning on line 33 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L31-L33

Added lines #L31 - L33 were not covered by tests

if user.has_group("fieldservice_survey.group_fsm_survey_user"):
return expression.AND(

Check warning on line 36 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L36

Added line #L36 was not covered by tests
[[("fsm_order_id", "=", fsm_order.id)], user_input_domain]
)

if partner.id in fsm_order.partner_submitted_answer_survey_ids.ids:
return expression.AND(

Check warning on line 41 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L41

Added line #L41 was not covered by tests
[
[FSM_ORDER_ID, "=", fsm_order.id],
[FSM_ORDER_PERSON_ID, "=", person.id],
],
user_input_domain,
)

raise AccessDenied(_("You do not have access to this FSM Order Survey"))

Check warning on line 49 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L49

Added line #L49 was not covered by tests

@http.route(
"/fsm_order/<int:fsm_order_id>/results", type="http", auth="user", website=True
)
def survey_results(self, fsm_order_id, **post):
try:
fsm_order = request.env["fsm.order"].sudo().browse(fsm_order_id)
except ValueError:
raise AccessDenied(_("Invalid FSM Order ID"))

Check warning on line 58 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L55-L58

Added lines #L55 - L58 were not covered by tests

if (
fsm_order.person_id.partner_id == request.env.user.partner_id
and not request.env.user.has_group(
"fieldservice_survey.group_fsm_survey_user"
)
):

return request.render(

Check warning on line 67 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L67

Added line #L67 was not covered by tests
"http_routing.http_error",
{
"status_code": "Forbidden",
"status_message": "You don't have access to this survey "
"related to your FSM Order.",
},
)

user = request.env.user
partner = user.partner_id
person = request.env["fsm.person"].search([(PARTNER_ID, "=", partner.id)])
survey_sudo = None
answer = None

Check warning on line 80 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L76-L80

Added lines #L76 - L80 were not covered by tests

if user.has_group(
"fieldservice_survey.group_fsm_survey_user"
) or user.has_group("base.group_system"):
survey_sudo = (

Check warning on line 85 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L85

Added line #L85 was not covered by tests
request.env["survey.user_input"]
.sudo()
.search([(FSM_ORDER_ID, "=", fsm_order.id)], limit=1)
.survey_id
)

if partner.id in fsm_order.partner_submitted_answer_survey_ids.ids:
answer = (

Check warning on line 93 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L93

Added line #L93 was not covered by tests
request.env["survey.user_input"]
.sudo()
.search(
[
(FSM_ORDER_ID, "=", fsm_order.id),
(FSM_ORDER_PERSON_ID, "=", person.id),
],
limit=1,
)
)

if answer:
survey_sudo = answer.survey_id

Check warning on line 106 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L106

Added line #L106 was not covered by tests

if not survey_sudo:
raise AccessDenied(_("No survey found for the given FSM Order"))

Check warning on line 109 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L109

Added line #L109 was not covered by tests

post["fsm_order_id"] = fsm_order_id
user_input_lines_sudo, search_filters = self._extract_filters_data(

Check warning on line 112 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L111-L112

Added lines #L111 - L112 were not covered by tests
survey_sudo, post
)
survey_data = survey_sudo._prepare_statistics(user_input_lines_sudo)
question_and_page_data = survey_sudo.question_and_page_ids._prepare_statistics(

Check warning on line 116 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L115-L116

Added lines #L115 - L116 were not covered by tests
user_input_lines_sudo
)

template_values = {

Check warning on line 120 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L120

Added line #L120 was not covered by tests
"survey": survey_sudo,
"question_and_page_data": question_and_page_data,
"survey_data": survey_data,
"search_filters": search_filters,
"search_finished": "true",
"fsm_order_id": fsm_order_id,
}

return request.render("survey.survey_page_statistics", template_values)

Check warning on line 129 in fieldservice_survey/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_survey/controllers/main.py#L129

Added line #L129 was not covered by tests
Loading
Loading