diff --git a/survey_record_generation/README.rst b/survey_record_generation/README.rst new file mode 100644 index 0000000..e03d218 --- /dev/null +++ b/survey_record_generation/README.rst @@ -0,0 +1,146 @@ +======================== +Survey record generation +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:03eeb5c11b7d8330051c416331c84103b2641351fdc1d0a1bad43acd09501a33 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_record_generation + :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_record_generation + :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 allows to generate any record from surveys answers. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +In several cases we want to use survey application to create records. +Website form application give the same possibility but the design is integrated on the web site. +Futhermore this module add other functionnalities like "duplicate" check, or creation of several interconnected records + +Typical use case : Information request form + +#. Submitting the form will create a contact (partner) only if it does not already exist in the database. +#. Submitting the form will also create a crm opportunity linked to previously created partner + + + +Configuration +============= + +Record generation configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. |Image of record creation list| image:: https://raw.githubusercontent.com/OCA/survey/16.0/survey_record_generation/static/description/record-creations.png + +#. Go to the the survey +#. In *Record creation* tab add a new line +#. Set a name for created record, select the Model of the record (eg: Prospect) +#. Add a field configuration. So for each field : + + .. |Image of record creation fields| image:: https://raw.githubusercontent.com/OCA/survey/16.0/survey_record_generation/static/description/record-creation-customer.png + + #. You can check "unicity constraint" to prevent duplicates. + In case of duplicates and if other record use this record to fill a m2o field, the founded record will be used + #. You can configure explicitly where Odoo should retrieve the value of field : + * **fixed**: To set explicit value + * **question**: If value come from user's answer + For m2o or m2m links, question should be configured before. See Question answers configuration section below. + * **other created record**: If value come from other created record (m2o case only) + + + +Question answers configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In a survey question : to configure value of choices + +.. |Question answers| image:: https://raw.githubusercontent.com/OCA/survey/16.0/survey_record_generation/static/description/question-answers.png + +#. Configure a multiple choice question +#. Select value type associated to answer: + * **Value** > eg: to fill a selection field + * **Record** > to fill m2o or m2m field +#. In case of *record* type: + #. Select referenced model + #. You can directly fill answers (eventualy with help of the domain field) + #. Or create new answers and set associated record +#. In case of *value* type: + #. Add new selectable answers and set associated value + + +Usage +===== + +When a survey is properly configured, once it is submited by a user, records should be created. + +To find records generated from a participation go to: + +#. Survey > participation +#. Click on **# Generated records** button (top-right) + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Elabore + +Contributors +~~~~~~~~~~~~ + +* `Elabore `_ + + * Clément Thomas + +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_record_generation/models/survey_user_input.py b/survey_record_generation/models/survey_user_input.py index dd31ec9..19e4857 100644 --- a/survey_record_generation/models/survey_user_input.py +++ b/survey_record_generation/models/survey_user_input.py @@ -1,10 +1,36 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import models, fields class SurveyUserInput(models.Model): _inherit = "survey.user_input" + generated_record_ids = fields.One2many('survey.generated.record', 'user_input_id', 'Generated records') + generated_records_count = fields.Integer("Attempts Count", compute='_compute_generated_records_count') + + def _compute_generated_records_count(self): + for user_input in self: + user_input.generated_records_count = len(user_input.generated_record_ids) + + + def action_redirect_to_generated_records(self): + self.ensure_one() + + action = self.env['ir.actions.act_window']._for_xml_id('survey_record_generation.survey_generated_record_action') + """ context = dict(self.env.context or {}) + + context['create'] = False + context['search_default_survey_id'] = self.survey_id.id + context['search_default_group_by_survey'] = False + if self.partner_id: + context['search_default_partner_id'] = self.partner_id.id + elif self.email: + context['search_default_email'] = self.email + + action['context'] = context """ + + return action + def _mark_done(self): # generate records for user_input in self: @@ -58,13 +84,25 @@ class SurveyUserInput(models.Model): else: # Create record record = self.env[model].create(vals) - + # Link generated records to user input + self.env['survey.generated.record'].create({ + 'survey_record_creation_name':record_creation.name, + 'survey_record_creation_id':record_creation.id, + 'user_input_id':user_input.id, + "created_record_id":"%s,%s" % (model,record.id) + }) + created_records[record_creation.id] = record + + # update linked records for field_to_update in fields_to_update: record_to_update = created_records[field_to_update.survey_record_creation_id.id] linked_record = created_records[field_to_update.other_created_record_id.id] record_to_update.write({field_to_update.field_id.name:linked_record.id}) + + + return super()._mark_done() diff --git a/survey_record_generation/readme/CONFIGURE.rst b/survey_record_generation/readme/CONFIGURE.rst new file mode 100644 index 0000000..99d1c5c --- /dev/null +++ b/survey_record_generation/readme/CONFIGURE.rst @@ -0,0 +1,40 @@ +Record generation configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. |Image of record creation list| image:: ../static/description/record-creations.png + +#. Go to the the survey +#. In *Record creation* tab add a new line +#. Set a name for created record, select the Model of the record (eg: Prospect) +#. Add a field configuration. So for each field : + + .. |Image of record creation fields| image:: ../static/description/record-creation-customer.png + + #. You can check "unicity constraint" to prevent duplicates. + In case of duplicates and if other record use this record to fill a m2o field, the founded record will be used + #. You can configure explicitly where Odoo should retrieve the value of field : + * **fixed**: To set explicit value + * **question**: If value come from user's answer + For m2o or m2m links, question should be configured before. See Question answers configuration section below. + * **other created record**: If value come from other created record (m2o case only) + + + +Question answers configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In a survey question : to configure value of choices + +.. |Question answers| image:: ../static/description/question-answers.png + +#. Configure a multiple choice question +#. Select value type associated to answer: + * **Value** > eg: to fill a selection field + * **Record** > to fill m2o or m2m field +#. In case of *record* type: + #. Select referenced model + #. You can directly fill answers (eventualy with help of the domain field) + #. Or create new answers and set associated record +#. In case of *value* type: + #. Add new selectable answers and set associated value + diff --git a/survey_record_generation/readme/CONTEXT.rst b/survey_record_generation/readme/CONTEXT.rst new file mode 100644 index 0000000..6887590 --- /dev/null +++ b/survey_record_generation/readme/CONTEXT.rst @@ -0,0 +1,10 @@ +In several cases we want to use survey application to create records. +Website form application give the same possibility but the design is integrated on the web site. +Futhermore this module add other functionnalities like "duplicate" check, or creation of several interconnected records + +Typical use case : Information request form + +#. Submitting the form will create a contact (partner) only if it does not already exist in the database. +#. Submitting the form will also create a crm opportunity linked to previously created partner + + diff --git a/survey_record_generation/readme/CONTRIBUTORS.rst b/survey_record_generation/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..ed90ebe --- /dev/null +++ b/survey_record_generation/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Elabore `_ + + * Clément Thomas \ No newline at end of file diff --git a/survey_record_generation/readme/DESCRIPTION.rst b/survey_record_generation/readme/DESCRIPTION.rst new file mode 100644 index 0000000..2f732ef --- /dev/null +++ b/survey_record_generation/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to generate any record from surveys answers. \ No newline at end of file diff --git a/survey_record_generation/readme/USAGE.rst b/survey_record_generation/readme/USAGE.rst new file mode 100644 index 0000000..6c9047c --- /dev/null +++ b/survey_record_generation/readme/USAGE.rst @@ -0,0 +1,6 @@ +When a survey is properly configured, once it is submited by a user, records should be created. + +To find records generated from a participation go to: + +#. Survey > participation +#. Click on **# Generated records** button (top-right) diff --git a/survey_record_generation/static/description/index.html b/survey_record_generation/static/description/index.html new file mode 100644 index 0000000..8c697d4 --- /dev/null +++ b/survey_record_generation/static/description/index.html @@ -0,0 +1,526 @@ + + + + + +Survey record generation + + + +
+

Survey record generation

+ + +

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

+

This module allows to generate any record from surveys answers.

+

Table of contents

+ +
+

Use Cases / Context

+

In several cases we want to use survey application to create records. +Website form application give the same possibility but the design is integrated on the web site. +Futhermore this module add other functionnalities like “duplicate” check, or creation of several interconnected records

+

Typical use case : Information request form

+
    +
  1. Submitting the form will create a contact (partner) only if it does not already exist in the database.
  2. +
  3. Submitting the form will also create a crm opportunity linked to previously created partner
  4. +
+
+
+

Configuration

+
+

Record generation configuration

+
    +
  1. Go to the the survey

    +
  2. +
  3. In Record creation tab add a new line

    +
  4. +
  5. Set a name for created record, select the Model of the record (eg: Prospect)

    +
  6. +
  7. Add a field configuration. So for each field :

    +
    +
      +
    1. +
      You can check “unicity constraint” to prevent duplicates.
      +
      In case of duplicates and if other record use this record to fill a m2o field, the founded record will be used
      +
      +
    2. +
    3. +
      You can configure explicitly where Odoo should retrieve the value of field :
      +
        +
      • fixed: To set explicit value
      • +
      • +
        question: If value come from user’s answer
        +
        For m2o or m2m links, question should be configured before. See Question answers configuration section below.
        +
        +
      • +
      • other created record: If value come from other created record (m2o case only)
      • +
      +
      +
      +
    4. +
    +
    +
  8. +
+
+
+

Question answers configuration

+

In a survey question : to configure value of choices

+
    +
  1. Configure a multiple choice question
  2. +
  3. +
    Select value type associated to answer:
    +
      +
    • Value > eg: to fill a selection field
    • +
    • Record > to fill m2o or m2m field
    • +
    +
    +
    +
  4. +
  5. +
    In case of record type:
    +
      +
    1. Select referenced model
    2. +
    3. You can directly fill answers (eventualy with help of the domain field)
    4. +
    5. Or create new answers and set associated record
    6. +
    +
    +
    +
  6. +
  7. +
    In case of value type:
    +
      +
    1. Add new selectable answers and set associated value
    2. +
    +
    +
    +
  8. +
+
+
+
+

Usage

+

When a survey is properly configured, once it is submited by a user, records should be created.

+

To find records generated from a participation go to:

+
    +
  1. Survey > participation
  2. +
  3. Click on # Generated records button (top-right)
  4. +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Elabore
  • +
+
+
+

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_record_generation/static/description/question-answers.png b/survey_record_generation/static/description/question-answers.png new file mode 100644 index 0000000..50d6e02 Binary files /dev/null and b/survey_record_generation/static/description/question-answers.png differ diff --git a/survey_record_generation/static/description/record-creation-customer.png b/survey_record_generation/static/description/record-creation-customer.png new file mode 100644 index 0000000..8fc8feb Binary files /dev/null and b/survey_record_generation/static/description/record-creation-customer.png differ diff --git a/survey_record_generation/static/description/record-creations.png b/survey_record_generation/static/description/record-creations.png new file mode 100644 index 0000000..03a7c27 Binary files /dev/null and b/survey_record_generation/static/description/record-creations.png differ