diff --git a/fieldservice_agreement_repair/README.rst b/fieldservice_agreement_repair/README.rst new file mode 100644 index 0000000000..c919b3494a --- /dev/null +++ b/fieldservice_agreement_repair/README.rst @@ -0,0 +1,86 @@ +============================= +Fieldservice Agreement Repair +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3bc94f2421f97aba7e13a13c18f132028ca2eaf21f12a05e01b4d28269efde95 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_agreement_repair + :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_agreement_repair + :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| + +This module allows you to link ``repair.order`` with an ``agreement`` +trough a ``fsm.equipment``. This way you can track the repair orders +that are covered by an agreement. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +No specific usage instructions. + +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 SA +* Italo Lopes + +Contributors +------------ + +- `Camptocamp `__: + + - Italo Lopes + +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/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_agreement_repair/__init__.py b/fieldservice_agreement_repair/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_agreement_repair/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_agreement_repair/__manifest__.py b/fieldservice_agreement_repair/__manifest__.py new file mode 100644 index 0000000000..3833da15f1 --- /dev/null +++ b/fieldservice_agreement_repair/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Fieldservice Agreement Repair", + "summary": "Fieldservice Agreement Repair", + "category": "Field Service", + "version": "17.0.1.0.0", + "author": "Camptocamp SA, Italo Lopes, Odoo Community Association (OCA)", + "license": "AGPL-3", + "maintainer": "Camptocamp", + "depends": [ + # OCA/agreement + "agreement_repair", + # OCA/field-service + "fieldservice_repair", + ], + "website": "https://github.com/OCA/field-service", + "installable": True, +} diff --git a/fieldservice_agreement_repair/models/__init__.py b/fieldservice_agreement_repair/models/__init__.py new file mode 100644 index 0000000000..9943a1f6ca --- /dev/null +++ b/fieldservice_agreement_repair/models/__init__.py @@ -0,0 +1,2 @@ +from . import fsm_order +from . import repair_order diff --git a/fieldservice_agreement_repair/models/fsm_order.py b/fieldservice_agreement_repair/models/fsm_order.py new file mode 100644 index 0000000000..0853750b64 --- /dev/null +++ b/fieldservice_agreement_repair/models/fsm_order.py @@ -0,0 +1,17 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# 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): + res = super().create(vals_list) + for order in res: + if order.repair_id and order.agreement_id: + order.repair_id.agreement_id = order.agreement_id.id + return res diff --git a/fieldservice_agreement_repair/models/repair_order.py b/fieldservice_agreement_repair/models/repair_order.py new file mode 100644 index 0000000000..82dd59b0ca --- /dev/null +++ b/fieldservice_agreement_repair/models/repair_order.py @@ -0,0 +1,26 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class FSMEquipment(models.Model): + _inherit = "repair.order" + + agreement_id = fields.Many2one( + "agreement", compute="_compute_agreement_id", store=True, readonly=False + ) + + @api.depends("product_id", "lot_id", "lot_id.product_id") + def _compute_agreement_id(self): + for repair in self: + if repair.product_id and repair.lot_id: + equipment_id = self.env["fsm.equipment"].search( + [ + ("product_id", "=", repair.product_id.id), + ("lot_id", "=", repair.lot_id.id), + ] + ) + if equipment_id and equipment_id.agreement_id: + repair.agreement_id = equipment_id.agreement_id.id diff --git a/fieldservice_agreement_repair/pyproject.toml b/fieldservice_agreement_repair/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_agreement_repair/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_agreement_repair/readme/CONTRIBUTORS.md b/fieldservice_agreement_repair/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ef0db2bf63 --- /dev/null +++ b/fieldservice_agreement_repair/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Camptocamp](https://camptocamp.com): + + > - Italo Lopes \<\> diff --git a/fieldservice_agreement_repair/readme/DESCRIPTION.md b/fieldservice_agreement_repair/readme/DESCRIPTION.md new file mode 100644 index 0000000000..8759358a58 --- /dev/null +++ b/fieldservice_agreement_repair/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows you to link ``repair.order`` with an ``agreement`` trough a ``fsm.equipment``. +This way you can track the repair orders that are covered by an agreement. diff --git a/fieldservice_agreement_repair/readme/USAGE.md b/fieldservice_agreement_repair/readme/USAGE.md new file mode 100644 index 0000000000..f08cd97a88 --- /dev/null +++ b/fieldservice_agreement_repair/readme/USAGE.md @@ -0,0 +1 @@ +No specific usage instructions. diff --git a/fieldservice_agreement_repair/static/description/icon.png b/fieldservice_agreement_repair/static/description/icon.png new file mode 100644 index 0000000000..e3757caa15 Binary files /dev/null and b/fieldservice_agreement_repair/static/description/icon.png differ diff --git a/fieldservice_agreement_repair/static/description/icon.svg b/fieldservice_agreement_repair/static/description/icon.svg new file mode 100644 index 0000000000..c27c090fda --- /dev/null +++ b/fieldservice_agreement_repair/static/description/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/fieldservice_agreement_repair/static/description/index.html b/fieldservice_agreement_repair/static/description/index.html new file mode 100644 index 0000000000..5734509305 --- /dev/null +++ b/fieldservice_agreement_repair/static/description/index.html @@ -0,0 +1,434 @@ + + + + + +Fieldservice Agreement Repair + + + +
+

Fieldservice Agreement Repair

+ + +

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

+

This module allows you to link repair.order with an agreement +trough a fsm.equipment. This way you can track the repair orders +that are covered by an agreement.

+

Table of contents

+ +
+

Usage

+

No specific usage instructions.

+
+
+

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 SA
  • +
  • Italo Lopes
  • +
+
+
+

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.

+

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_agreement_repair/tests/__init__.py b/fieldservice_agreement_repair/tests/__init__.py new file mode 100644 index 0000000000..9a757edeba --- /dev/null +++ b/fieldservice_agreement_repair/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fieldservice_agreement_repair diff --git a/fieldservice_agreement_repair/tests/test_fieldservice_agreement_repair.py b/fieldservice_agreement_repair/tests/test_fieldservice_agreement_repair.py new file mode 100644 index 0000000000..87753b7414 --- /dev/null +++ b/fieldservice_agreement_repair/tests/test_fieldservice_agreement_repair.py @@ -0,0 +1,93 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestRepairPartSourceLocation(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.agreement_model = cls.env["agreement"] + cls.repair_order_model = cls.env["repair.order"] + cls.equipment_model = cls.env["fsm.equipment"] + cls.product_model = cls.env["product.product"] + cls.lot_model = cls.env["stock.lot"] + + cls.product = cls.product_model.create({"name": "Test Product"}) + cls.product02 = cls.product_model.create({"name": "Test Product 02"}) + cls.product03 = cls.product_model.create({"name": "Test Product 03"}) + + cls.lot = cls.lot_model.create({"product_id": cls.product.id}) + cls.lot02 = cls.lot_model.create({"product_id": cls.product02.id}) + cls.lot03 = cls.lot_model.create({"product_id": cls.product03.id}) + + cls.agreement = cls.agreement_model.create({"name": "Test Agreement"}) + cls.agreement02 = cls.agreement_model.create({"name": "Test Agreement 02"}) + + cls.equipment_with_agreement = cls.equipment_model.create( + { + "product_id": cls.product.id, + "lot_id": cls.lot.id, + "agreement_id": cls.agreement.id, + } + ) + + cls.equipment_no_agreement = cls.equipment_model.create( + { + "product_id": cls.product02.id, + "lot_id": cls.lot02.id, + } + ) + cls.repair_order = cls.repair_order_model.create( + {"product_id": cls.product.id, "lot_id": cls.lot.id} + ) + + def test_01_agreement_is_set_correctly(self): + self.repair_order._compute_agreement_id() + self.assertEqual(self.repair_order.agreement_id, self.agreement.id) + + def test_02_agreement_is_not_set_when_no_equipment(self): + repair_order = self.repair_order_model.create( + {"product_id": self.product03.id, "lot_id": self.lot03.id} + ) + repair_order._compute_agreement_id() + self.assertFalse(repair_order.agreement_id) + + def test_03_agreement_is_not_set_when_equipment_no_agreement(self): + repair_order = self.repair_order_model.create( + {"product_id": self.product02.id, "lot_id": self.lot02.id} + ) + equipment = self.equipment_model.search( + [ + ("product_id", "=", self.product02.id), + ("lot_id", "=", self.lot02.id), + ] + ) + self.assertEqual(equipment, self.equipment_no_agreement) + repair_order._compute_agreement_id() + self.assertFalse(repair_order.agreement_id) + + def test_04_agreement_is_not_set_when_no_lot(self): + product = self.env["product.product"].create({"name": "Test Product"}) + repair_order = self.env["repair.order"].create({"product_id": product.id}) + repair_order._compute_agreement_id() + self.assertFalse(repair_order.agreement_id) + + def test_05_agreement_is_set_when_lot_updated(self): + repair_order = self.repair_order_model.create( + {"product_id": self.product03.id, "lot_id": self.lot03.id} + ) + repair_order._compute_agreement_id() + self.assertFalse(repair_order.agreement_id) + repair_order.product_id = self.product.id + repair_order.lot_id = self.lot.id + repair_order._compute_agreement_id() + self.assertEqual(repair_order.agreement_id, self.agreement.id) + + def test_06_agreement_can_be_updated_manually(self): + self.repair_order._compute_agreement_id() + self.assertEqual(self.repair_order.agreement_id, self.agreement.id) + self.repair_order.agreement_id = self.agreement02.id + self.assertEqual(self.repair_order.agreement_id, self.agreement02.id)