Skip to content

Commit

Permalink
[ADD]survey_link_base
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Dec 30, 2024
1 parent b89e426 commit f827bb8
Show file tree
Hide file tree
Showing 19 changed files with 850 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/survey_link_base/odoo/addons/survey_link_base
6 changes: 6 additions & 0 deletions setup/survey_link_base/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,
)
78 changes: 78 additions & 0 deletions survey_link_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
================
Survey Link Base
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e990148f488831cfa1259013f8a7adb0d48cb5f5a1acdf75fcd8b471580ea9b3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_link_base
: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_link_base
: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 addon creates a mixin and a wizard to enable the generation of surveys from other models.

**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_link_base%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
~~~~~~~

* Binhex

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

* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[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_link_base>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions survey_link_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import wizard
16 changes: 16 additions & 0 deletions survey_link_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Survey Link Base",
"summary": """
This addon creates a mixin and a wizard to enable the
generation of surveys from other models..""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Binhex, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/survey",
"depends": ["survey"],
"data": [
"wizard/survey_link_wizard_views.xml",
],
}
5 changes: 5 additions & 0 deletions survey_link_base/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import survey_survey
from . import survey_user_input
from . import survey_link_mixin
74 changes: 74 additions & 0 deletions survey_link_base/models/survey_link_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models, _
from datetime import timedelta


class SurveyLinkMixin(models.AbstractModel):
_name = "survey.link.mixin"

survey_count = fields.Integer(
compute="_compute_survey_count",
)

def _compute_survey_count(self):
for order in self:
order.survey_count = self.env["survey.user_input"].search_count(

Check warning on line 16 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L16

Added line #L16 was not covered by tests
[
("origin_id", "=", order.id),
("origin_model", "=", order._name),
("partner_id", "=", order.partner_id.id),
]
)

def action_view_survey(self):
self.ensure_one()
action = self.env.ref("survey.action_survey_user_input").read()[0]
action["domain"] = [

Check warning on line 27 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L25-L27

Added lines #L25 - L27 were not covered by tests
[
("origin_id", "=", self.id),
("origin_model", "=", self._name),
("partner_id", "=", self.partner_id.id),
]
]
action["context"] = {

Check warning on line 34 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L34

Added line #L34 was not covered by tests
"default_origin_id": self.id,
"default_origin_model": self._name,
"default_partner_id": self.partner_id.id,
"default_survey_id": self._get_default_survey(),
}
return action

Check warning on line 40 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L40

Added line #L40 was not covered by tests

# Override this method if you need to add a default survey.
def get_default_survey(self):
return False

Check warning on line 44 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L44

Added line #L44 was not covered by tests

def get_share_link(self):
survey_link_wizard = self.env["survey.link.wizard"].create(

Check warning on line 47 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L47

Added line #L47 was not covered by tests
{
"origin_id": self.id,
"origin_model": self._name,
"partner_id": self.partner_id.id,
"date_deadline": fields.Date.today() + timedelta(days=5),
"survey_id": self.get_default_survey(),
}
)

return survey_link_wizard.share_link if survey_link_wizard else False

Check warning on line 57 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L57

Added line #L57 was not covered by tests

def action_survey_link_wizard(self):
self.ensure_one()
return {

Check warning on line 61 in survey_link_base/models/survey_link_mixin.py

View check run for this annotation

Codecov / codecov/patch

survey_link_base/models/survey_link_mixin.py#L60-L61

Added lines #L60 - L61 were not covered by tests
"type": "ir.actions.act_window",
"name": _("Survey Share Link"),
"res_model": "survey.link.wizard",
"view_mode": "form",
"target": "new",
"context": {
"default_origin_id": self.id,
"default_origin_model": self._name,
"default_partner_id": self.partner_id.id,
"default_date_deadline": fields.Date.today(),
"default_survey_id": self.get_default_survey(),
},
}
34 changes: 34 additions & 0 deletions survey_link_base/models/survey_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models


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

def _create_answer(
self,
user=False,
partner=False,
email=False,
test_entry=False,
origin_id=False,
origin_model=False,
check_attempts=True,
**additional_vals
):
user_inputs = super()._create_answer(
user=user,
partner=partner,
email=email,
test_entry=test_entry,
**additional_vals
)
vals = {}
if origin_id:
vals["origin_id"] = origin_id
if origin_model:
vals["origin_model"] = origin_model
if vals:
user_inputs.write(vals)
return user_inputs
10 changes: 10 additions & 0 deletions survey_link_base/models/survey_user_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


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

origin_model = fields.Char("Origin Model")
origin_id = fields.Integer("Origin ID")
3 changes: 3 additions & 0 deletions survey_link_base/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[email protected]>
1 change: 1 addition & 0 deletions survey_link_base/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This addon creates a mixin and a wizard to enable the generation of surveys from other models.
Binary file added survey_link_base/static/description/icon.png
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 f827bb8

Please sign in to comment.