Skip to content

Commit

Permalink
[ADD] survey_operating_unit: added operating unit on survey
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed Jan 14, 2025
1 parent 31e7bcb commit 86fd8ec
Show file tree
Hide file tree
Showing 22 changed files with 980 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/survey_operating_unit/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,
)
87 changes: 87 additions & 0 deletions survey_operating_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
===========================
Survey with Operating Units
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:04005aacc73ec5d637de9d2ffa9be53915a40d365297f39f73b4ac2d66c55911
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/16.0/survey_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-16-0/operating-unit-16-0-survey_operating_unit
: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/operating-unit&target_branch=16.0
:alt: Try me on Runboat

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

This module introduces the following features:

- Adds the operating unit to the Survey.
- Adds the operating unit to the Survey Question.
- Adds the operating unit to the Survey User Input.
- Implements user's security access rules.

**Table of contents**

.. contents::
:local:

Usage
=====

This module defines the operating unit entity and the user's security rules.
Other modules extend the standard Odoo apps with the OU.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/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/operating-unit/issues/new?body=module:%20survey_operating_unit%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
~~~~~~~

* Giuseppe Borruso - Dinamiche Aziendali srl

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

* Giuseppe Borruso - Dinamiche Aziendali srl <gborruso@dinamicheaziendali.it>

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/operating-unit <https://github.com/OCA/operating-unit/tree/16.0/survey_operating_unit>`_ 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_operating_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions survey_operating_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Survey with Operating Units",
"summary": "Adds the concept of operating unit (OU) in surveys",
"version": "16.0.1.0.0",
"category": "Generic Modules/Surveys",
"author": "Giuseppe Borruso - Dinamiche Aziendali srl, Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/operating-unit",
"depends": ["survey", "operating_unit"],
"data": [
"security/survey_security.xml",
"views/survey_survey_view.xml",
"views/survey_user_input_view.xml",
],
"installable": True,
}
65 changes: 65 additions & 0 deletions survey_operating_unit/i18n/survey_operating_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * survey_operating_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-14 12:13+0000\n"
"PO-Revision-Date: 2025-01-14 12:13+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: survey_operating_unit
#: model_terms:ir.ui.view,arch_db:survey_operating_unit.survey_survey_view_kanban
msgid "<span class=\"text-muted\">Operating Unit</span>"
msgstr ""

#. module: survey_operating_unit
#. odoo-python
#: code:addons/survey_operating_unit/models/survey_question.py:0
#: code:addons/survey_operating_unit/models/survey_question_answer.py:0
#: code:addons/survey_operating_unit/models/survey_user_input.py:0
#: code:addons/survey_operating_unit/models/survey_user_input_line.py:0
#, python-format
msgid "Changing the Operating Unit is not allowed."
msgstr ""

#. module: survey_operating_unit
#: model:ir.model.fields,field_description:survey_operating_unit.field_survey_question__operating_unit_id
#: model:ir.model.fields,field_description:survey_operating_unit.field_survey_question_answer__operating_unit_id
#: model:ir.model.fields,field_description:survey_operating_unit.field_survey_survey__operating_unit_id
#: model:ir.model.fields,field_description:survey_operating_unit.field_survey_user_input__operating_unit_id
#: model:ir.model.fields,field_description:survey_operating_unit.field_survey_user_input_line__operating_unit_id
msgid "Operating Unit"
msgstr ""

#. module: survey_operating_unit
#: model:ir.model,name:survey_operating_unit.model_survey_survey
msgid "Survey"
msgstr ""

#. module: survey_operating_unit
#: model:ir.model,name:survey_operating_unit.model_survey_question_answer
msgid "Survey Label"
msgstr ""

#. module: survey_operating_unit
#: model:ir.model,name:survey_operating_unit.model_survey_question
msgid "Survey Question"
msgstr ""

#. module: survey_operating_unit
#: model:ir.model,name:survey_operating_unit.model_survey_user_input
msgid "Survey User Input"
msgstr ""

#. module: survey_operating_unit
#: model:ir.model,name:survey_operating_unit.model_survey_user_input_line
msgid "Survey User Input Line"
msgstr ""
5 changes: 5 additions & 0 deletions survey_operating_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import survey_survey
from . import survey_question_answer
from . import survey_question
from . import survey_user_input_line
from . import survey_user_input
23 changes: 23 additions & 0 deletions survey_operating_unit/models/survey_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

operating_unit_id = fields.Many2one(
related="survey_id.operating_unit_id",
store=True,
)

@api.constrains("operating_unit_id")
def _check_operating_unit_change(self):
for question in self:
if (
question.id
and question.operating_unit_id != question.survey_id.operating_unit_id
):
raise ValidationError(_("Changing the Operating Unit is not allowed."))

Check warning on line 23 in survey_operating_unit/models/survey_question.py

View check run for this annotation

Codecov / codecov/patch

survey_operating_unit/models/survey_question.py#L23

Added line #L23 was not covered by tests
23 changes: 23 additions & 0 deletions survey_operating_unit/models/survey_question_answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

operating_unit_id = fields.Many2one(
related="question_id.operating_unit_id",
store=True,
)

@api.constrains("operating_unit_id")
def _check_operating_unit_change(self):
for answer in self:
if (
answer.id
and answer.operating_unit_id != answer.question_id.operating_unit_id
):
raise ValidationError(_("Changing the Operating Unit is not allowed."))

Check warning on line 23 in survey_operating_unit/models/survey_question_answer.py

View check run for this annotation

Codecov / codecov/patch

survey_operating_unit/models/survey_question_answer.py#L23

Added line #L23 was not covered by tests
13 changes: 13 additions & 0 deletions survey_operating_unit/models/survey_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import fields, models


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

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Operating Unit",
)
24 changes: 24 additions & 0 deletions survey_operating_unit/models/survey_user_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

operating_unit_id = fields.Many2one(
related="survey_id.operating_unit_id",
store=True,
)

@api.constrains("operating_unit_id")
def _check_operating_unit_change(self):
for user_input in self:
if (
user_input.id
and user_input.operating_unit_id
!= user_input.survey_id.operating_unit_id
):
raise ValidationError(_("Changing the Operating Unit is not allowed."))
23 changes: 23 additions & 0 deletions survey_operating_unit/models/survey_user_input_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


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

operating_unit_id = fields.Many2one(
related="user_input_id.operating_unit_id",
store=True,
)

@api.constrains("operating_unit_id")
def _check_operating_unit_change(self):
for line in self:
if (
line.id
and line.operating_unit_id != line.user_input_id.operating_unit_id
):
raise ValidationError(_("Changing the Operating Unit is not allowed."))

Check warning on line 23 in survey_operating_unit/models/survey_user_input_line.py

View check run for this annotation

Codecov / codecov/patch

survey_operating_unit/models/survey_user_input_line.py#L23

Added line #L23 was not covered by tests
1 change: 1 addition & 0 deletions survey_operating_unit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Giuseppe Borruso - Dinamiche Aziendali srl <gborruso@dinamicheaziendali.it>
6 changes: 6 additions & 0 deletions survey_operating_unit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module introduces the following features:

- Adds the operating unit to the Survey.
- Adds the operating unit to the Survey Question.
- Adds the operating unit to the Survey User Input.
- Implements user's security access rules.
2 changes: 2 additions & 0 deletions survey_operating_unit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module defines the operating unit entity and the user's security rules.
Other modules extend the standard Odoo apps with the OU.
75 changes: 75 additions & 0 deletions survey_operating_unit/security/survey_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2025 Giuseppe Borruso - Dinamiche Aziendali srl
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>

<record id="ir_rule_survey_survey_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="survey.model_survey_survey" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Surveys from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>

<record id="ir_rule_survey_question_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="survey.model_survey_question" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Survey Question from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>

<record id="ir_rule_survey_question_answer_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="survey.model_survey_question_answer" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Survey Question Answer from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>

<record id="ir_rule_survey_user_input_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="survey.model_survey_user_input" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Survey User Input from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>

<record id="ir_rule_survey_user_input_line_allowed_operating_units" model="ir.rule">
<field name="model_id" ref="survey.model_survey_user_input_line" />
<field name="domain_force">['|',
('operating_unit_id', '=', False),
('operating_unit_id', 'in', user.operating_unit_ids.ids)]
</field>
<field name="name">Survey User Input Line from allowed operating units</field>
<field name="global" eval="True" />
<field eval="0" name="perm_unlink" />
<field eval="0" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="0" name="perm_create" />
</record>
</odoo>
Binary file added survey_operating_unit/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 86fd8ec

Please sign in to comment.