Skip to content

Commit

Permalink
[ADD] survey_answer_generation: New module
Browse files Browse the repository at this point in the history
TT40984
  • Loading branch information
chienandalu committed Aug 18, 2023
1 parent c40aeba commit 49adce8
Show file tree
Hide file tree
Showing 17 changed files with 696 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/survey_answer_generation/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
103 changes: 103 additions & 0 deletions survey_answer_generation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
========================
Survey answer generation
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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/15.0/survey_answer_generation
:alt: OCA/survey
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/survey-15-0/survey-15-0-survey_answer_generation
: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/15.0
:alt: Try me on Runbot

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

This module allows to prefill answers from one survey to another.

**Table of contents**

.. contents::
:local:

Configuration
=============

You can configure either a new or an existing survey.

#. Go to *Surveys* and choose an existing one or create it.
#. In the *Options* tab, *Questions* group, choose the *Next Survey*.

Now you'll have to configure the destination questions linked to this survey's questions.

For regular questions (text, numerical, date):

#. In the *Answers* tab choose the linked questions.

Usage
=====

Once the survey is configured, the users can fill them up as usual. The answers in the
next survey will be prefilled according to the linked questions.

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_answer_generation%0Aversion:%2015.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
~~~~~~~

* Tecnativa

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

* `Tecnativa <https://www.tecnativa.com>`_

* David Vidal

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.

.. |maintainer-chienandalu| image:: https://github.com/chienandalu.png?size=40px
:target: https://github.com/chienandalu
:alt: chienandalu

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-chienandalu|

This module is part of the `OCA/survey <https://github.com/OCA/survey/tree/15.0/survey_answer_generation>`_ 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_answer_generation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions survey_answer_generation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Survey answer generation",
"summary": "Pre-generate answers from another survey",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Marketing/Survey",
"website": "https://github.com/OCA/survey",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["survey"],
"data": [
"views/survey_question_views.xml",
"views/survey_survey_views.xml",
],
}
3 changes: 3 additions & 0 deletions survey_answer_generation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import survey_question
from . import survey_user_input
from . import survey_survey
27 changes: 27 additions & 0 deletions survey_answer_generation/models/survey_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class SurveyQuestion(models.Model):
_inherit = "survey.question"

next_survey_id = fields.Many2one(related="survey_id.next_survey_id")
next_survey_question_id = fields.Many2one(
comodel_name="survey.question",
domain="[('survey_id', '=', next_survey_id), ('question_type', '=', question_type)]",
help="Prefill this answer of the next survey with the answer of this one",
)


class SurveyLabel(models.Model):
_inherit = "survey.question.answer"

next_survey_question_id = fields.Many2one(
related="question_id.next_survey_question_id"
)
next_survey_question_answer_id = fields.Many2one(
comodel_name="survey.question.answer",
domain="[('question_id', '=', next_survey_question_id)]",
help="Prefill this answer of the next survey with the answer of this one",
)
9 changes: 9 additions & 0 deletions survey_answer_generation/models/survey_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2023 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class SurveySurvey(models.Model):
_inherit = "survey.survey"

next_survey_id = fields.Many2one(comodel_name="survey.survey")
31 changes: 31 additions & 0 deletions survey_answer_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class SurveyUserInput(models.Model):
_inherit = "survey.user_input"

origin_input_id = fields.Many2one(comodel_name="survey.user_input")

def _mark_done(self):
"""Generate the sale order when the survey is submitted"""
res = super()._mark_done()
if not self.survey_id.next_survey_id:
return res
next_survey_input = self.survey_id.next_survey_id.sudo()._create_answer(

Check warning on line 16 in survey_answer_generation/models/survey_user_input.py

View check run for this annotation

Codecov / codecov/patch

survey_answer_generation/models/survey_user_input.py#L16

Added line #L16 was not covered by tests
partner=self.partner_id,
email=self.email,
test_entry=self.test_entry,
origin_input_id=self.id,
)
next_answers = self.user_input_line_ids.filtered(
lambda x: x.question_id.next_survey_question_id and not x.skipped
)
# TODO: Implement suggested values
for answer in next_answers.filtered(lambda x: x.answer_type != "suggestion"):
next_survey_input.save_lines(

Check warning on line 27 in survey_answer_generation/models/survey_user_input.py

View check run for this annotation

Codecov / codecov/patch

survey_answer_generation/models/survey_user_input.py#L27

Added line #L27 was not covered by tests
answer.question_id.next_survey_question_id,
answer[f"value_{answer.answer_type}"],
)
return res

Check warning on line 31 in survey_answer_generation/models/survey_user_input.py

View check run for this annotation

Codecov / codecov/patch

survey_answer_generation/models/survey_user_input.py#L31

Added line #L31 was not covered by tests
10 changes: 10 additions & 0 deletions survey_answer_generation/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
You can configure either a new or an existing survey.

#. Go to *Surveys* and choose an existing one or create it.
#. In the *Options* tab, *Questions* group, choose the *Next Survey*.

Now you'll have to configure the destination questions linked to this survey's questions.

For regular questions (text, numerical, date):

#. In the *Answers* tab choose the linked questions.
3 changes: 3 additions & 0 deletions survey_answer_generation/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`_

* David Vidal
1 change: 1 addition & 0 deletions survey_answer_generation/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to prefill answers from one survey to another.
2 changes: 2 additions & 0 deletions survey_answer_generation/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Once the survey is configured, the users can fill them up as usual. The answers in the
next survey will be prefilled according to the linked questions.
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 49adce8

Please sign in to comment.