Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] [ADD] survey_operating_unit: added operating unit on survey #734

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[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/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
30 changes: 30 additions & 0 deletions survey_operating_unit/models/survey_survey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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"

def _default_operating_unit(self):
if (
self.env.user.default_operating_unit_id.sudo().company_id
in self.env.companies
):
return self.env.user.default_operating_unit_id
else:
# find an OU of the main active company
for ou in self.env.user.assigned_operating_unit_ids:
if ou.sudo().company_id in self.env.company:
return ou

Check warning on line 20 in survey_operating_unit/models/survey_survey.py

View check run for this annotation

Codecov / codecov/patch

survey_operating_unit/models/survey_survey.py#L20

Added line #L20 was not covered by tests
# find an OU of any active company
for ou in self.env.user.assigned_operating_unit_ids:
if ou.sudo().company_id in self.env.companies:
return ou

Check warning on line 24 in survey_operating_unit/models/survey_survey.py

View check run for this annotation

Codecov / codecov/patch

survey_operating_unit/models/survey_survey.py#L24

Added line #L24 was not covered by tests

operating_unit_id = fields.Many2one(
comodel_name="operating.unit",
string="Operating Unit",
default=lambda self: self._default_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 <[email protected]>
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.
Loading
Loading