diff --git a/fieldservice_repair_order_template/README.rst b/fieldservice_repair_order_template/README.rst new file mode 100644 index 0000000000..64d0f7b7db --- /dev/null +++ b/fieldservice_repair_order_template/README.rst @@ -0,0 +1,93 @@ +===================================== +Field Service - Repair Order Template +===================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1fa494028821edda6f8b8f695134172bc0e47ba4bbe77c28bef63f47b1b0727d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Ffield--service-lightgray.png?logo=github + :target: https://github.com/OCA/field-service/tree/17.0/fieldservice_repair_order_template + :alt: OCA/field-service +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/field-service-17-0/field-service-17-0-fieldservice_repair_order_template + :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/field-service&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Use the **Repair Order Templates** to pre-fill some fields on the +generated repair orders. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to **Field Service > Master Data > Templates** and select the desired +**Repair Order Template**. + +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 +------------ + +- `Camptocamp `__: + + - Iván Todorovich + +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-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px + :target: https://github.com/ivantodorovich + :alt: ivantodorovich + +Current `maintainer `__: + +|maintainer-ivantodorovich| + +This module is part of the `OCA/field-service `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/fieldservice_repair_order_template/__init__.py b/fieldservice_repair_order_template/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_repair_order_template/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_repair_order_template/__manifest__.py b/fieldservice_repair_order_template/__manifest__.py new file mode 100644 index 0000000000..08aa5a117a --- /dev/null +++ b/fieldservice_repair_order_template/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Field Service - Repair Order Template", + "summary": "Use Repair Order Templates when creating a repair orders", + "version": "17.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["ivantodorovich"], + "website": "https://github.com/OCA/field-service", + "license": "AGPL-3", + "category": "Field Service", + "depends": [ + "fieldservice_repair", + "repair_order_template", + ], + "data": [ + "views/fsm_template.xml", + ], +} diff --git a/fieldservice_repair_order_template/models/__init__.py b/fieldservice_repair_order_template/models/__init__.py new file mode 100644 index 0000000000..211b05b481 --- /dev/null +++ b/fieldservice_repair_order_template/models/__init__.py @@ -0,0 +1,2 @@ +from . import fsm_order +from . import fsm_template diff --git a/fieldservice_repair_order_template/models/fsm_order.py b/fieldservice_repair_order_template/models/fsm_order.py new file mode 100644 index 0000000000..f8085d8675 --- /dev/null +++ b/fieldservice_repair_order_template/models/fsm_order.py @@ -0,0 +1,40 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class FSMOrder(models.Model): + _inherit = "fsm.order" + + @api.model_create_multi + def create(self, vals_list): + # OVERRIDE to apply the repair order template on the related repair order + records = super().create(vals_list) + records._apply_repair_order_template() + return records + + def write(self, vals): + # OVERRIDE to apply the repair order template on the related repair order + res = super().write(vals) + if "template_id" in vals: + self._apply_repair_order_template() + return res + + def _onchange_template_id(self): + res = super()._onchange_template_id() + self._apply_repair_order_template() + return res + + def _apply_repair_order_template(self): + """Apply the Repair Order Template on the related repair order""" + for rec in self: + if ( + rec.repair_id + and rec.repair_id.state == "draft" + and rec.template_id.repair_order_template_id + ): + rec.repair_id.repair_order_template_id = ( + rec.template_id.repair_order_template_id + ) + rec.repair_id._onchange_repair_order_template_id() diff --git a/fieldservice_repair_order_template/models/fsm_template.py b/fieldservice_repair_order_template/models/fsm_template.py new file mode 100644 index 0000000000..ed04fb12a7 --- /dev/null +++ b/fieldservice_repair_order_template/models/fsm_template.py @@ -0,0 +1,15 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FSMTemplate(models.Model): + _inherit = "fsm.template" + + repair_order_template_id = fields.Many2one( + comodel_name="repair.order.template", + string="Repair Order Template", + help="If set, this template will be used to create the repair order.", + ) + type_internal = fields.Selection(related="type_id.internal_type") diff --git a/fieldservice_repair_order_template/pyproject.toml b/fieldservice_repair_order_template/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_repair_order_template/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_repair_order_template/readme/CONFIGURE.md b/fieldservice_repair_order_template/readme/CONFIGURE.md new file mode 100644 index 0000000000..d7173f6605 --- /dev/null +++ b/fieldservice_repair_order_template/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +Go to **Field Service > Master Data > Templates** and select the desired +**Repair Order Template**. + diff --git a/fieldservice_repair_order_template/readme/CONTRIBUTORS.md b/fieldservice_repair_order_template/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..7f045ba5f1 --- /dev/null +++ b/fieldservice_repair_order_template/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Camptocamp](https://camptocamp.com/): + + - Iván Todorovich \<\> diff --git a/fieldservice_repair_order_template/readme/DESCRIPTION.md b/fieldservice_repair_order_template/readme/DESCRIPTION.md new file mode 100644 index 0000000000..9cfa3e816a --- /dev/null +++ b/fieldservice_repair_order_template/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Use the **Repair Order Templates** to pre-fill some fields on the generated +repair orders. diff --git a/fieldservice_repair_order_template/static/description/index.html b/fieldservice_repair_order_template/static/description/index.html new file mode 100644 index 0000000000..9962ef6891 --- /dev/null +++ b/fieldservice_repair_order_template/static/description/index.html @@ -0,0 +1,435 @@ + + + + + +Field Service - Repair Order Template + + + +
+

Field Service - Repair Order Template

+ + +

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

+

Use the Repair Order Templates to pre-fill some fields on the +generated repair orders.

+

Table of contents

+ +
+

Configuration

+

Go to Field Service > Master Data > Templates and select the desired +Repair Order Template.

+
+
+

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

+ +
+
+

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.

+

Current maintainer:

+

ivantodorovich

+

This module is part of the OCA/field-service project on GitHub.

+

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

+
+
+
+ + diff --git a/fieldservice_repair_order_template/tests/__init__.py b/fieldservice_repair_order_template/tests/__init__.py new file mode 100644 index 0000000000..456903b51a --- /dev/null +++ b/fieldservice_repair_order_template/tests/__init__.py @@ -0,0 +1 @@ +from . import test_repair_order_template diff --git a/fieldservice_repair_order_template/tests/test_repair_order_template.py b/fieldservice_repair_order_template/tests/test_repair_order_template.py new file mode 100644 index 0000000000..3533403abd --- /dev/null +++ b/fieldservice_repair_order_template/tests/test_repair_order_template.py @@ -0,0 +1,97 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import timedelta + +from odoo import fields +from odoo.tests import Form, TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +class TestRepairOrderTemplate(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + cls.env.user.groups_id += cls.env.ref("fieldservice.group_fsm_template") + cls.repair_template = cls.env.ref( + "repair_order_template.repair_order_template_demo" + ) + cls.template = cls.env["fsm.template"].create( + { + "name": "Test Template", + "type_id": cls.env.ref("fieldservice_repair.fsm_order_type_repair").id, + "repair_order_template_id": cls.repair_template.id, + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Product A", "type": "product"} + ) + cls.lot = cls.env["stock.lot"].create( + { + "name": "sn11", + "product_id": cls.product.id, + "company_id": cls.env.company.id, + } + ) + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.env["stock.quant"].with_context(inventory_mode=True).create( + { + "product_id": cls.product.id, + "inventory_quantity": 10, + "lot_id": cls.lot.id, + "location_id": cls.stock_location.id, + } + ).action_apply_inventory() + cls.equipment = cls.env["fsm.equipment"].create( + { + "name": "test equipment", + "product_id": cls.product.id, + "lot_id": cls.lot.id, + "current_stock_location_id": cls.env.ref( + "stock.stock_location_stock" + ).id, + } + ) + cls.order_vals = { + "type": cls.env.ref("fieldservice_repair.fsm_order_type_repair").id, + "location_id": cls.env.ref("fieldservice.test_location").id, + "equipment_id": cls.equipment.id, + "date_start": fields.Datetime.today(), + "date_end": fields.Datetime.today() + timedelta(hours=1), + "request_early": fields.Datetime.today(), + } + + def test_repair_order_template_on_create(self): + order = self.env["fsm.order"].create( + dict(self.order_vals, template_id=self.template.id) + ) + self.assertEqual(order.repair_id.repair_order_template_id, self.repair_template) + self.assertEqual(len(order.repair_id.move_ids), 2) + + def test_repair_order_template_on_write(self): + order = self.env["fsm.order"].create(self.order_vals) + with Form(order) as order_form: + order_form.template_id = self.template + self.assertEqual(order.repair_id.repair_order_template_id, self.repair_template) + self.assertEqual(len(order.repair_id.move_ids), 2) + + def test_repair_order_template_with_onchange_template_flow(self): + """Test the flow when the type is inferred from the template + + This case is the one implemented in fieldservice_recurring. In the future, + the onchange should move to a computed method and this should not be required + anymore. + """ + order_vals = self.order_vals.copy() + order_vals.pop("type", None) + order = self.env["fsm.order"].create( + dict(order_vals, template_id=self.template.id) + ) + order._onchange_template_id() + self.assertEqual( + order.type, self.env.ref("fieldservice_repair.fsm_order_type_repair") + ) + self.assertEqual(order.repair_id.repair_order_template_id, self.repair_template) + self.assertEqual(len(order.repair_id.move_ids), 2) diff --git a/fieldservice_repair_order_template/views/fsm_template.xml b/fieldservice_repair_order_template/views/fsm_template.xml new file mode 100644 index 0000000000..9a093a6854 --- /dev/null +++ b/fieldservice_repair_order_template/views/fsm_template.xml @@ -0,0 +1,23 @@ + + + + + + fsm.template + + + + + + + + + +