-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
27 changed files
with
1,013 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/survey_partner_representative/odoo/addons/survey_partner_representative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../survey_partner_representative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
============================= | ||
Survey Partner Representative | ||
============================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:32924103c7ee99139f60cb1d89ae02a2085ced8d944a379da91f5d3a2426cf11 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_partner_representative | ||
: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_partner_representative | ||
: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=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
Do surveys on behalf of others. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
When we have the modules ``survey_contact_generation``, | ||
``survey_sale_generation`` or ``survey_crm_generation`` a salesman or a | ||
portal users could want to act as a representative of another using the | ||
surveys that generate those documents as an entry point. | ||
|
||
Configuration | ||
============= | ||
|
||
Users that can make surveys on behalf of others need to have the | ||
*Representative on surveys* special permission. | ||
|
||
If you want to allow that a survey is filled on behalf of others by the | ||
authorized users: | ||
|
||
1. Go to *Surveys > Surveys* and choose the survey you want to | ||
configure. | ||
2. Go to the *Options* tab and in the *Candidates* section set the | ||
*Allow Partner Representing* option on. | ||
|
||
Usage | ||
===== | ||
|
||
A user acting on behalf of other can start a new survey from the share | ||
link: | ||
|
||
- On the survey backend form, click on *Share* and copy the survey URL. | ||
- Paste it in your browser and fill the survey with needed data. | ||
|
||
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_partner_representative%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_partner_representative>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Survey Partner Representative", | ||
"summary": "Fill the survey on behalf of others", | ||
"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": [ | ||
"security/survey_partner_representative_security.xml", | ||
"views/survey_survey_views.xml", | ||
"views/survey_user_input_views.xml", | ||
], | ||
"demo": ["demo/survey_partner_representative_demo.xml"], | ||
"assets": { | ||
"web.assets_tests": [ | ||
"/survey_partner_representative/static/tests/survey_representative_tour.esm.js", | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo.http import request | ||
|
||
from odoo.addons.survey.controllers.main import Survey | ||
|
||
|
||
class Survey(Survey): | ||
def _check_validity( | ||
self, survey_token, answer_token, ensure_token=True, check_partner=True | ||
): | ||
"""Avoid partner mismatching error""" | ||
survey_sudo, _answer_sudo = self._fetch_from_access_token( | ||
survey_token, answer_token | ||
) | ||
if survey_sudo.allow_partner_representing and request.env.user.has_group( | ||
"survey_partner_representative.partner_representative" | ||
): | ||
check_partner = False | ||
return super()._check_validity( | ||
survey_token, answer_token, ensure_token, check_partner | ||
) |
43 changes: 43 additions & 0 deletions
43
survey_partner_representative/demo/survey_partner_representative_demo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record model="survey.survey" id="survey_representative_demo"> | ||
<field name="title">Meal preferences</field> | ||
<field name="access_token">80e5f1e2-1a9d-4c51-8e23-4abc7534</field> | ||
<field name="access_mode">public</field> | ||
<field name="users_can_go_back" eval="True" /> | ||
</record> | ||
<record model="survey.question" id="survey_representative_q0"> | ||
<field name="survey_id" ref="survey_representative_demo" /> | ||
<field name="sequence">0</field> | ||
<field name="title">Name</field> | ||
<field name="question_type">char_box</field> | ||
<field name="constr_mandatory" eval="True" /> | ||
</record> | ||
<record model="survey.question" id="survey_representative_q1"> | ||
<field name="survey_id" ref="survey_representative_demo" /> | ||
<field name="sequence">1</field> | ||
<field name="title">Email</field> | ||
<field name="question_type">char_box</field> | ||
</record> | ||
<record model="survey.question" id="survey_representative_q5"> | ||
<field name="survey_id" ref="survey_representative_demo" /> | ||
<field name="sequence">4</field> | ||
<field name="title">What would you like for dinner?</field> | ||
<field name="question_type">simple_choice</field> | ||
</record> | ||
<record model="survey.question.answer" id="survey_representative_q5_sug1"> | ||
<field name="question_id" ref="survey_representative_q5" /> | ||
<field name="sequence">1</field> | ||
<field name="value">Meat</field> | ||
</record> | ||
<record model="survey.question.answer" id="survey_representative_q5_sug2"> | ||
<field name="question_id" ref="survey_representative_q5" /> | ||
<field name="sequence">2</field> | ||
<field name="value">Fish</field> | ||
</record> | ||
<record model="survey.question.answer" id="survey_representative_q5_sug3"> | ||
<field name="question_id" ref="survey_representative_q5" /> | ||
<field name="sequence">3</field> | ||
<field name="value">Vegan</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import survey_representative_mixin | ||
from . import survey_survey | ||
from . import survey_user_input |
29 changes: 29 additions & 0 deletions
29
survey_partner_representative/models/survey_representative_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class SurveyRepresentativeMixin(models.AbstractModel): | ||
"""This abstract is handy when we have a generated record that is linked to a | ||
user input. This way, we can compute the represetative partner right away""" | ||
|
||
_name = "survey.representative.mixin" | ||
_description = "Use this mixin in models that have a linked survey input" | ||
|
||
survey_user_input_id = fields.Many2one( | ||
comodel_name="survey.user_input", readonly=True | ||
) | ||
survey_representative_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
compute="_compute_survey_representative_partner_id", | ||
store=True, | ||
readonly=False, | ||
) | ||
|
||
@api.depends("survey_user_input_id") | ||
def _compute_survey_representative_partner_id(self): | ||
"""Users can set the field independently of the answer, but the answer rules""" | ||
for record in self: | ||
record.survey_representative_partner_id = ( | ||
self.survey_user_input_id.representative_partner_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2024 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" | ||
|
||
allow_partner_representing = fields.Boolean( | ||
help="A user with the proper permissions, could do the survey on behalf of other" | ||
) | ||
|
||
def _create_answer(self, *args, **kwargs): | ||
"""Inject the context so the partner representation is only done on a normal | ||
survey workflow""" | ||
if self.allow_partner_representing: | ||
self = self.with_context(survey_partner_representative=True) | ||
return super()._create_answer(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class SurveyUserInput(models.Model): | ||
_inherit = "survey.user_input" | ||
|
||
representative_partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
help="This partner filled this survey on behalf of other", | ||
readonly=True, | ||
) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
"""Remove the user information so the survey is made anonymously""" | ||
answers = super().create(vals_list) | ||
if ( | ||
self.env.context.get("survey_partner_representative") | ||
and self.env.user.has_group( | ||
"survey_partner_representative.partner_representative" | ||
) | ||
and all(answers.survey_id.mapped("allow_partner_representing")) | ||
): | ||
answers.partner_id = False | ||
answers.email = False | ||
answers.nickname = False | ||
answers.representative_partner_id = self.env.user.partner_id | ||
return answers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Users that can make surveys on behalf of others need to have the | ||
*Representative on surveys* special permission. | ||
|
||
If you want to allow that a survey is filled on behalf of others by the authorized users: | ||
|
||
1. Go to *Surveys > Surveys* and choose the survey you want to configure. | ||
2. Go to the *Options* tab and in the *Candidates* section set the *Allow Partner Representing* | ||
option on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
When we have the modules `survey_contact_generation`, `survey_sale_generation` or | ||
`survey_crm_generation` a salesman or a portal users could want to act as a | ||
representative of another using the surveys that generate those documents as an entry | ||
point. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- [Tecnativa](https://www.tecnativa.com) | ||
|
||
- David Vidal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Do surveys on behalf of others. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
A user acting on behalf of other can start a new survey from the share link: | ||
|
||
- On the survey backend form, click on *Share* and copy the survey URL. | ||
- Paste it in your browser and fill the survey with needed data. |
9 changes: 9 additions & 0 deletions
9
survey_partner_representative/security/survey_partner_representative_security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 Tecnativa - David Vidal | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="partner_representative" model="res.groups"> | ||
<field name="name">Representative on surveys</field> | ||
<field name="category_id" ref="base.module_category_hidden" /> | ||
</record> | ||
</odoo> |
Oops, something went wrong.