diff --git a/helpdesk_mgmt_stage_validation/README.rst b/helpdesk_mgmt_stage_validation/README.rst new file mode 100644 index 0000000000..e06f72ef5f --- /dev/null +++ b/helpdesk_mgmt_stage_validation/README.rst @@ -0,0 +1,99 @@ +================================ +Helpdesk Ticket Stage Validation +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5d936cd9571b9a6a9218317dcc9a8d0ccf0aa6cf87060637d02109f2abb9319b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fhelpdesk-lightgray.png?logo=github + :target: https://github.com/OCA/helpdesk/tree/17.0/helpdesk_mgmt_stage_validation + :alt: OCA/helpdesk +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/helpdesk-17-0/helpdesk-17-0-helpdesk_mgmt_stage_validation + :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/helpdesk&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +As the stage of a helpdesk ticket document progresses, it may be +important for specific fields of the document be completed. + +For example, when a helpdesk ticket enters the 'Complete' stage, the +fields for 'Actual End Date' and/or 'Resolution Notes' should be set. + +This module allows you to raise a Validation Error if the designated +fields are not set when moving to a new stage. Since stages can be used +for helpdesk ticket, workers, locations, or equipments, this logic is +available to be applied to each document type. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +- Go to Helpdesk > Configuration > Stages +- Create or select a stage +- Select one or more fields to be validated + +Usage +===== + +- Follow steps outlined in Configuration. +- User will receive validation error if a field is not set when + attempting to move to a new stage. + +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 +------- + +* Camptocamp + +Contributors +------------ + +- Bojan Anchev + +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/helpdesk `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/helpdesk_mgmt_stage_validation/__init__.py b/helpdesk_mgmt_stage_validation/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/helpdesk_mgmt_stage_validation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/helpdesk_mgmt_stage_validation/__manifest__.py b/helpdesk_mgmt_stage_validation/__manifest__.py new file mode 100644 index 0000000000..a60a14d9d0 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Helpdesk Ticket Stage Validation", + "summary": "Validate input data when reaching a Helpdesk Ticket stage", + "version": "17.0.1.0.0", + "category": "After-Sales", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/helpdesk", + "depends": ["helpdesk_mgmt"], + "data": ["views/helpdesk_ticket_stage.xml"], + "license": "AGPL-3", +} diff --git a/helpdesk_mgmt_stage_validation/i18n/helpdesk_mgmt_stage_validation.pot b/helpdesk_mgmt_stage_validation/i18n/helpdesk_mgmt_stage_validation.pot new file mode 100644 index 0000000000..2f34b8eee0 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/i18n/helpdesk_mgmt_stage_validation.pot @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * helpdesk_mgmt_stage_validation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \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: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket__display_name +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__display_name +msgid "Display Name" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__validate_field_ids +msgid "Fields to Validate" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model,name:helpdesk_mgmt_stage_validation.model_helpdesk_ticket +msgid "Helpdesk Ticket" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model,name:helpdesk_mgmt_stage_validation.model_helpdesk_ticket_stage +msgid "Helpdesk Ticket Stage" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket__id +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__id +msgid "ID" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket____last_update +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage____last_update +msgid "Last Modified on" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,help:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__validate_field_ids +msgid "Select fields which must be set on the document in this stage" +msgstr "" + +#. module: helpdesk_mgmt_stage_validation +#: code:addons/helpdesk_mgmt_stage_validation/models/helpdesk_ticket.py:0 +#: code:addons/helpdesk_mgmt_stage_validation/tests/test_helpdesk_ticket_stage_validation.py:0 +#, python-format +msgid "" +"Ticket %s can't be moved to the stage %s until the following fields are set:" +" %s." +msgstr "" diff --git a/helpdesk_mgmt_stage_validation/i18n/it.po b/helpdesk_mgmt_stage_validation/i18n/it.po new file mode 100644 index 0000000000..02f625e12d --- /dev/null +++ b/helpdesk_mgmt_stage_validation/i18n/it.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * helpdesk_mgmt_stage_validation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-29 16:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket__display_name +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__display_name +msgid "Display Name" +msgstr "Nome visualizzato" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__validate_field_ids +msgid "Fields to Validate" +msgstr "Campi da validare" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model,name:helpdesk_mgmt_stage_validation.model_helpdesk_ticket +msgid "Helpdesk Ticket" +msgstr "Ticket assistenza clienti" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model,name:helpdesk_mgmt_stage_validation.model_helpdesk_ticket_stage +msgid "Helpdesk Ticket Stage" +msgstr "Fase ticket assistenza clienti" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket__id +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__id +msgid "ID" +msgstr "ID" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket____last_update +#: model:ir.model.fields,field_description:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: helpdesk_mgmt_stage_validation +#: model:ir.model.fields,help:helpdesk_mgmt_stage_validation.field_helpdesk_ticket_stage__validate_field_ids +msgid "Select fields which must be set on the document in this stage" +msgstr "" +"Selezionare i campi che devono essere compilati nel documento in questa fase" + +#. module: helpdesk_mgmt_stage_validation +#: code:addons/helpdesk_mgmt_stage_validation/models/helpdesk_ticket.py:0 +#: code:addons/helpdesk_mgmt_stage_validation/tests/test_helpdesk_ticket_stage_validation.py:0 +#, python-format +msgid "" +"Ticket %s can't be moved to the stage %s until the following fields are set:" +" %s." +msgstr "" +"Il ticket %s non può essere spostato alla fase %s finché i sequenti campi " +"non sono impostati: %s." diff --git a/helpdesk_mgmt_stage_validation/models/__init__.py b/helpdesk_mgmt_stage_validation/models/__init__.py new file mode 100644 index 0000000000..c2de6ad377 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/models/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import ( + helpdesk_ticket, + helpdesk_ticket_stage, +) diff --git a/helpdesk_mgmt_stage_validation/models/helpdesk_ticket.py b/helpdesk_mgmt_stage_validation/models/helpdesk_ticket.py new file mode 100644 index 0000000000..3fad36a0b8 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/models/helpdesk_ticket.py @@ -0,0 +1,41 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class HelpdeskTicket(models.Model): + _inherit = "helpdesk.ticket" + + def _check_ticket_has_empty_fields(self): + self.ensure_one() + error_message = False + field_ids = self.stage_id.validate_field_ids + field_names = [x.name for x in field_ids] + values = self.read(field_names) + fields = [ + field.field_description for field in field_ids if not values[0][field.name] + ] + fields = ", ".join(fields) + if fields: + error_message = _( + f"Ticket {self.name} can't be moved to the stage " + f"{self.stage_id.name} until the following fields are set: {fields}." + ) + return error_message + + def _validate_stage_fields_error_message(self): + error_message = [] + for record in self: + message = record._check_ticket_has_empty_fields() + if message: + error_message.append(message) + return error_message + + @api.constrains("stage_id") + def _validate_stage_fields(self): + message = self._validate_stage_fields_error_message() + if message: + message = "\n".join(message) + raise ValidationError(message) diff --git a/helpdesk_mgmt_stage_validation/models/helpdesk_ticket_stage.py b/helpdesk_mgmt_stage_validation/models/helpdesk_ticket_stage.py new file mode 100644 index 0000000000..d707ba8292 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/models/helpdesk_ticket_stage.py @@ -0,0 +1,15 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class HelpdeskTicketStage(models.Model): + _inherit = "helpdesk.ticket.stage" + + validate_field_ids = fields.Many2many( + "ir.model.fields", + string="Fields to Validate", + help="Select fields which must be set on the document in this stage", + domain='[("model", "=", "helpdesk.ticket")]', + ) diff --git a/helpdesk_mgmt_stage_validation/pyproject.toml b/helpdesk_mgmt_stage_validation/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/helpdesk_mgmt_stage_validation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/helpdesk_mgmt_stage_validation/readme/CONFIGURE.md b/helpdesk_mgmt_stage_validation/readme/CONFIGURE.md new file mode 100644 index 0000000000..4cf0fb8aad --- /dev/null +++ b/helpdesk_mgmt_stage_validation/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +- Go to Helpdesk \> Configuration \> Stages +- Create or select a stage +- Select one or more fields to be validated diff --git a/helpdesk_mgmt_stage_validation/readme/CONTRIBUTORS.md b/helpdesk_mgmt_stage_validation/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..2be296829f --- /dev/null +++ b/helpdesk_mgmt_stage_validation/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Bojan Anchev \<\> diff --git a/helpdesk_mgmt_stage_validation/readme/DESCRIPTION.md b/helpdesk_mgmt_stage_validation/readme/DESCRIPTION.md new file mode 100644 index 0000000000..c16d407a27 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/readme/DESCRIPTION.md @@ -0,0 +1,10 @@ +As the stage of a helpdesk ticket document progresses, it may be +important for specific fields of the document be completed. + +For example, when a helpdesk ticket enters the 'Complete' stage, the +fields for 'Actual End Date' and/or 'Resolution Notes' should be set. + +This module allows you to raise a Validation Error if the designated +fields are not set when moving to a new stage. Since stages can be used +for helpdesk ticket, workers, locations, or equipments, this logic is +available to be applied to each document type. diff --git a/helpdesk_mgmt_stage_validation/readme/USAGE.md b/helpdesk_mgmt_stage_validation/readme/USAGE.md new file mode 100644 index 0000000000..c92d6ab280 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/readme/USAGE.md @@ -0,0 +1,3 @@ +- Follow steps outlined in Configuration. +- User will receive validation error if a field is not set when + attempting to move to a new stage. diff --git a/helpdesk_mgmt_stage_validation/static/description/icon.png b/helpdesk_mgmt_stage_validation/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/helpdesk_mgmt_stage_validation/static/description/icon.png differ diff --git a/helpdesk_mgmt_stage_validation/static/description/index.html b/helpdesk_mgmt_stage_validation/static/description/index.html new file mode 100644 index 0000000000..78c719e33e --- /dev/null +++ b/helpdesk_mgmt_stage_validation/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Helpdesk Ticket Stage Validation + + + +
+

Helpdesk Ticket Stage Validation

+ + +

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

+

As the stage of a helpdesk ticket document progresses, it may be +important for specific fields of the document be completed.

+

For example, when a helpdesk ticket enters the ‘Complete’ stage, the +fields for ‘Actual End Date’ and/or ‘Resolution Notes’ should be set.

+

This module allows you to raise a Validation Error if the designated +fields are not set when moving to a new stage. Since stages can be used +for helpdesk ticket, workers, locations, or equipments, this logic is +available to be applied to each document type.

+

Table of contents

+ +
+

Configuration

+
    +
  • Go to Helpdesk > Configuration > Stages
  • +
  • Create or select a stage
  • +
  • Select one or more fields to be validated
  • +
+
+
+

Usage

+
    +
  • Follow steps outlined in Configuration.
  • +
  • User will receive validation error if a field is not set when +attempting to move to a new stage.
  • +
+
+
+

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

+
    +
  • Camptocamp
  • +
+
+ +
+

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/helpdesk project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/helpdesk_mgmt_stage_validation/tests/__init__.py b/helpdesk_mgmt_stage_validation/tests/__init__.py new file mode 100644 index 0000000000..be050ba111 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_helpdesk_ticket_stage_validation diff --git a/helpdesk_mgmt_stage_validation/tests/test_helpdesk_ticket_stage_validation.py b/helpdesk_mgmt_stage_validation/tests/test_helpdesk_ticket_stage_validation.py new file mode 100644 index 0000000000..64bac0be21 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/tests/test_helpdesk_ticket_stage_validation.py @@ -0,0 +1,66 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, fields +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestHelpdeskStageValidation(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env["base"].with_context(**DISABLED_MAIL_CONTEXT).env + cls.stage = cls.env["helpdesk.ticket.stage"] + cls.helpdesk_ticket = cls.env["helpdesk.ticket"] + cls.ir_model_fields = cls.env["ir.model.fields"] + # Get some fields to use in the stages + cls.ticket_field = cls.ir_model_fields.search( + [("model", "=", "helpdesk.ticket"), ("name", "=", "assigned_date")] + ) + cls.stage_ticket_default = cls.stage.create( + { + "name": "Helpdesk Ticket Stage Default", + } + ) + cls.stage_ticket_assigned = cls.stage.create( + { + "name": "Helpdesk Ticket Assigned", + "validate_field_ids": [(6, 0, [cls.ticket_field.id])], + } + ) + cls.ticket = cls.helpdesk_ticket.create( + { + "name": "Helpdesk Ticket", + "description": "Helpdesk Ticket Description", + "stage_id": cls.stage_ticket_default.id, + } + ) + + def get_validate_message(self, ticket, stage): + validate_message = False + field_ids = stage.validate_field_ids + field_names = [x.name for x in field_ids] + values = ticket.read(field_names) + fields = [ + field.field_description for field in field_ids if not values[0][field.name] + ] + fields = ", ".join(fields) + if fields: + validate_message = _( + f"Ticket {ticket.name} can't be moved to the stage " + f"{stage.name} until the following fields are set: {fields}." + ) + return validate_message + + def test_helpdesk_ticket_stage_validation(self): + validate_message = self.get_validate_message( + self.ticket, self.stage_ticket_assigned + ) + with self.assertRaisesRegex(ValidationError, validate_message): + self.ticket.write({"stage_id": self.stage_ticket_assigned.id}) + self.ticket.write({"assigned_date": fields.datetime.now()}) + self.ticket.write({"stage_id": self.stage_ticket_assigned.id}) + self.assertEqual(self.ticket.stage_id, self.stage_ticket_assigned) diff --git a/helpdesk_mgmt_stage_validation/views/helpdesk_ticket_stage.xml b/helpdesk_mgmt_stage_validation/views/helpdesk_ticket_stage.xml new file mode 100644 index 0000000000..bc26fc9060 --- /dev/null +++ b/helpdesk_mgmt_stage_validation/views/helpdesk_ticket_stage.xml @@ -0,0 +1,13 @@ + + + + helpdesk.ticket.stage + + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..a4fa049d23 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-helpdesk_mgmt @ git+https://github.com/OCA/helpdesk.git@refs/pull/638/head#subdirectory=helpdesk_mgmt