diff --git a/fieldservice_recurring_repair/README.rst b/fieldservice_recurring_repair/README.rst new file mode 100644 index 0000000000..7b0b71484c --- /dev/null +++ b/fieldservice_recurring_repair/README.rst @@ -0,0 +1,134 @@ +=========================== +Field Service Recurring Rep +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:63d6818ff0933504f5716e8f706153621e0878275471dcd36b0b1c4c1c570869 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_recurring_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_recurring_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 manage your recurring field service work +orders linked to repairs. + +As repairs are often recurring and ``fieldservice_repair`` accept only +one equipment, this module allows you to create a recurring work order +for several equipments. This way, you can create a recurring order for a +group of equipments and the ``fsm.order`` will be created for each +equipment. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +- Follow the steps to configure ``fieldservice_repair`` module and + ``fieldservice_recurring`` + +Usage +===== + +To use this module, you can: + +1. Create ``fsm.order.type`` Maintenance with internal type = Repair +2. Create ``fsm.template`` Maintenance with type Maintenance (created on + step 1) +3. Create a ``fsm.recurring.template`` Daily Maintenance with + + - order template = maintenance (created on step 2) + +4. Create a SO with a product with creation of new equipment activated + and the generation of recurring orders. +5. Confirm and deliver → you get a new ``fsm.equipment`` linked to the + delivered product and a ``fsm.recurring.order`` linked to the SO: +6. On the ``fsm.recurring.order``: + + - set the equipment to the one delivered + +7. click Start + +This will create one ``fsm.order`` per equipment and one +``repair.order`` by ``fsm.order``. + +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 +------- + +* Italo Lopes +* Camptocamp + +Contributors +------------ + +- 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. + +.. |maintainer-wolfhall| image:: https://github.com/wolfhall.png?size=40px + :target: https://github.com/wolfhall + :alt: wolfhall +.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px + :target: https://github.com/max3903 + :alt: max3903 +.. |maintainer-brian10048| image:: https://github.com/brian10048.png?size=40px + :target: https://github.com/brian10048 + :alt: brian10048 +.. |maintainer-imlopes| image:: https://github.com/imlopes.png?size=40px + :target: https://github.com/imlopes + :alt: imlopes + +Current `maintainers `__: + +|maintainer-wolfhall| |maintainer-max3903| |maintainer-brian10048| |maintainer-imlopes| + +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_recurring_repair/__init__.py b/fieldservice_recurring_repair/__init__.py new file mode 100644 index 0000000000..989c19b38a --- /dev/null +++ b/fieldservice_recurring_repair/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from . import models diff --git a/fieldservice_recurring_repair/__manifest__.py b/fieldservice_recurring_repair/__manifest__.py new file mode 100644 index 0000000000..0c97881bc7 --- /dev/null +++ b/fieldservice_recurring_repair/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2019 Brian McMaster, Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Field Service Recurring Rep", + "summary": "Manage recurring Field Service orders for repairs", + "version": "17.0.1.1.0", + "category": "Field Service", + "author": "Italo Lopes, " "Camptocamp, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": ["fieldservice_recurring", "fieldservice_repair"], + "data": [ + # "views/fsm_recurring.xml", + ], + "license": "AGPL-3", + "development_status": "Beta", + "maintainers": ["wolfhall", "max3903", "brian10048", "imlopes"], +} diff --git a/fieldservice_recurring_repair/models/__init__.py b/fieldservice_recurring_repair/models/__init__.py new file mode 100644 index 0000000000..a87c785fd4 --- /dev/null +++ b/fieldservice_recurring_repair/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from . import fsm_recurring diff --git a/fieldservice_recurring_repair/models/fsm_recurring.py b/fieldservice_recurring_repair/models/fsm_recurring.py new file mode 100644 index 0000000000..06bbf54b6d --- /dev/null +++ b/fieldservice_recurring_repair/models/fsm_recurring.py @@ -0,0 +1,36 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class FSMRecurringOrder(models.Model): + _inherit = "fsm.recurring" + + def _split_create(self, vals): + self.ensure_one() + orders = self.env["fsm.order"] + for equipment in self.equipment_ids: + order_vals = vals.copy() + order_vals["equipment_id"] = equipment.id + orders |= self.env["fsm.order"].create(order_vals) + return orders + + def _check_split_create(self): + return bool( + self.fsm_order_template_id + and self.fsm_order_template_id.type_id + and self.fsm_order_template_id.type_id.internal_type == "repair" + ) + + def _create_order(self, date): + self.ensure_one() + vals = self._prepare_order_values(date) + if self._check_split_create(): + orders = self._split_create(vals) + for order in orders: + order._onchange_template_id() + else: + orders = super()._create_order(date) + orders._onchange_template_id() + return orders diff --git a/fieldservice_recurring_repair/pyproject.toml b/fieldservice_recurring_repair/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_recurring_repair/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_recurring_repair/readme/CONFIGURE.md b/fieldservice_recurring_repair/readme/CONFIGURE.md new file mode 100644 index 0000000000..2e81e75857 --- /dev/null +++ b/fieldservice_recurring_repair/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +To configure this module, you need to: + +- Follow the steps to configure ``fieldservice_repair`` module and ``fieldservice_recurring`` diff --git a/fieldservice_recurring_repair/readme/CONTRIBUTORS.md b/fieldservice_recurring_repair/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..16455d65b5 --- /dev/null +++ b/fieldservice_recurring_repair/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Italo Lopes \<\> diff --git a/fieldservice_recurring_repair/readme/DESCRIPTION.md b/fieldservice_recurring_repair/readme/DESCRIPTION.md new file mode 100644 index 0000000000..44725b3d2b --- /dev/null +++ b/fieldservice_recurring_repair/readme/DESCRIPTION.md @@ -0,0 +1,8 @@ +This module allows you to manage your recurring field service work +orders linked to repairs. + +As repairs are often recurring and `fieldservice_repair` accept only one +equipment, this module allows you to create a recurring work order for several +equipments. This way, you can create a recurring order for a group of equipments +and the `fsm.order` will be created for each equipment. + diff --git a/fieldservice_recurring_repair/readme/USAGE.md b/fieldservice_recurring_repair/readme/USAGE.md new file mode 100644 index 0000000000..0d675094e4 --- /dev/null +++ b/fieldservice_recurring_repair/readme/USAGE.md @@ -0,0 +1,15 @@ +To use this module, you can: + +1. Create `fsm.order.type` Maintenance with internal type = Repair +2. Create `fsm.template` Maintenance with type Maintenance (created on step 1) +3. Create a `fsm.recurring.template` Daily Maintenance with + - order template = maintenance (created on step 2) +4. Create a SO with a product with creation of new equipment activated +and the generation of recurring orders. +5. Confirm and deliver → you get a new `fsm.equipment` linked to the delivered product +and a `fsm.recurring.order` linked to the SO: +6. On the `fsm.recurring.order`: + - set the equipment to the one delivered +7. click Start + +This will create one `fsm.order` per equipment and one `repair.order` by `fsm.order`. diff --git a/fieldservice_recurring_repair/static/description/icon.png b/fieldservice_recurring_repair/static/description/icon.png new file mode 100644 index 0000000000..955674d8f0 Binary files /dev/null and b/fieldservice_recurring_repair/static/description/icon.png differ diff --git a/fieldservice_recurring_repair/static/description/index.html b/fieldservice_recurring_repair/static/description/index.html new file mode 100644 index 0000000000..df768ebe4f --- /dev/null +++ b/fieldservice_recurring_repair/static/description/index.html @@ -0,0 +1,463 @@ + + + + + +Field Service Recurring Rep + + + +
+

Field Service Recurring Rep

+ + +

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

+

This module allows you to manage your recurring field service work +orders linked to repairs.

+

As repairs are often recurring and fieldservice_repair accept only +one equipment, this module allows you to create a recurring work order +for several equipments. This way, you can create a recurring order for a +group of equipments and the fsm.order will be created for each +equipment.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  • Follow the steps to configure fieldservice_repair module and +fieldservice_recurring
  • +
+
+
+

Usage

+

To use this module, you can:

+
    +
  1. Create fsm.order.type Maintenance with internal type = Repair
  2. +
  3. Create fsm.template Maintenance with type Maintenance (created on +step 1)
  4. +
  5. Create a fsm.recurring.template Daily Maintenance with
      +
    • order template = maintenance (created on step 2)
    • +
    +
  6. +
  7. Create a SO with a product with creation of new equipment activated +and the generation of recurring orders.
  8. +
  9. Confirm and deliver → you get a new fsm.equipment linked to the +delivered product and a fsm.recurring.order linked to the SO:
  10. +
  11. On the fsm.recurring.order:
      +
    • set the equipment to the one delivered
    • +
    +
  12. +
  13. click Start
  14. +
+

This will create one fsm.order per equipment and one +repair.order by fsm.order.

+
+
+

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

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

+

Current maintainers:

+

wolfhall max3903 brian10048 imlopes

+

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_recurring_repair/tests/__init__.py b/fieldservice_recurring_repair/tests/__init__.py new file mode 100644 index 0000000000..d8e86c7e9f --- /dev/null +++ b/fieldservice_recurring_repair/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_fsm_recurring_repair diff --git a/fieldservice_recurring_repair/tests/test_fsm_recurring_repair.py b/fieldservice_recurring_repair/tests/test_fsm_recurring_repair.py new file mode 100644 index 0000000000..73896f3a9a --- /dev/null +++ b/fieldservice_recurring_repair/tests/test_fsm_recurring_repair.py @@ -0,0 +1,166 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class FSMRecurringRepairCase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Equipment = cls.env["fsm.equipment"] + cls.Recurring = cls.env["fsm.recurring"] + # disable tracking in test + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.test_equipment = cls.Equipment.create({"name": "Equipment"}) + cls.test_equipment2 = cls.Equipment.create({"name": "Equipment 2"}) + cls.Frequency = cls.env["fsm.frequency"] + cls.FrequencySet = cls.env["fsm.frequency.set"] + + cls.rule = cls.Frequency.create( + { + "name": "All weekdays", + "interval_type": "monthly", + "use_byweekday": True, + "mo": True, + "tu": True, + "we": True, + "th": True, + "fr": True, + } + ) + cls.fr_set = cls.FrequencySet.create( + { + "name": "31th only", + "schedule_days": 365, + "fsm_frequency_ids": [(6, 0, cls.rule.ids)], + } + ) + cls.fsm_order_type = cls.env["fsm.order.type"].create( + { + "name": "Install", + "internal_type": "fsm", + } + ) + cls.fsm_order_template_install = cls.env["fsm.template"].create( + { + "name": "Install", + "duration": 1, + "type_id": cls.fsm_order_type.id, + } + ) + cls.fsm_recurring_template_install = cls.env["fsm.recurring.template"].create( + { + "name": "Test Install", + "max_orders": 4, + "fsm_order_template_id": cls.fsm_order_template_install.id, + "fsm_frequency_set_id": cls.fr_set.id, + "company_id": cls.env.ref("base.main_company").id, + } + ) + + cls.fsm_order_template_maintenance = cls.env["fsm.template"].create( + { + "name": "Maintenance", + "duration": 2, + "type_id": cls.env.ref("fieldservice_repair.fsm_order_type_repair").id, + } + ) + cls.fsm_recurring_template_daily = cls.env["fsm.recurring.template"].create( + { + "name": "Test Maintenance", + "max_orders": 4, + "fsm_order_template_id": cls.fsm_order_template_maintenance.id, + "fsm_frequency_set_id": cls.fr_set.id, + "company_id": cls.env.ref("base.main_company").id, + } + ) + cls.test_loc_partner = cls.env["res.partner"].create( + {"name": "Test Loc Partner", "phone": "ABC", "email": "tlp@email.com"} + ) + cls.test_location = cls.env["fsm.location"].create( + { + "name": "Test Location", + "phone": "123", + "email": "tp@email.com", + "partner_id": cls.test_loc_partner.id, + "customer_id": cls.test_loc_partner.id, + "owner_id": cls.test_loc_partner.id, + } + ) + + def _check_fsm_order_type(self, order, order_type): + self.assertEqual(order.fsm_order_type_id, order_type) + self.assertEqual(order.internal_type, order_type.internal_type) + + def test_01_fsm_order_install_multi_equip(self): + # Create Recurring Order + install_recurring_multi_equip = self.Recurring.create( + { + "fsm_recurring_template_id": self.fsm_recurring_template_install.id, + "location_id": self.test_location.id, + "company_id": self.env.ref("base.main_company").id, + "equipment_ids": [ + (6, 0, [self.test_equipment.id, self.test_equipment2.id]) + ], + } + ) + install_recurring_multi_equip.onchange_recurring_template_id() + install_recurring_multi_equip.action_start() + + # Check if the orders are created + self.assertEqual(install_recurring_multi_equip.state, "progress") + self.assertEqual(len(install_recurring_multi_equip.fsm_order_ids), 4) + + def test_02_fsm_order_install_single_equip(self): + install_recurring_single_equip = self.Recurring.create( + { + "fsm_recurring_template_id": self.fsm_recurring_template_install.id, + "location_id": self.test_location.id, + "company_id": self.env.ref("base.main_company").id, + "equipment_ids": [(6, 0, [self.test_equipment.id])], + } + ) + install_recurring_single_equip.onchange_recurring_template_id() + install_recurring_single_equip.action_start() + + # Check if the orders are created + self.assertEqual(install_recurring_single_equip.state, "progress") + self.assertEqual(len(install_recurring_single_equip.fsm_order_ids), 4) + + def test_03_fsm_order_repair_multi_equip(self): + # Create Recurring Order + repair_recurring_multi_equip = self.Recurring.create( + { + "fsm_recurring_template_id": self.fsm_recurring_template_daily.id, + "location_id": self.test_location.id, + "company_id": self.env.ref("base.main_company").id, + "equipment_ids": [ + (6, 0, [self.test_equipment.id, self.test_equipment2.id]) + ], + } + ) + repair_recurring_multi_equip.onchange_recurring_template_id() + repair_recurring_multi_equip.action_start() + + # Check if the orders are created + self.assertEqual(repair_recurring_multi_equip.state, "progress") + self.assertEqual(len(repair_recurring_multi_equip.fsm_order_ids), 8) + + def test_04_fsm_order_repair_single_equip(self): + repair_recurring_single_equip = self.Recurring.create( + { + "fsm_recurring_template_id": self.fsm_recurring_template_daily.id, + "location_id": self.test_location.id, + "equipment_ids": [(6, 0, [self.test_equipment.id])], + "company_id": self.env.ref("base.main_company").id, + } + ) + repair_recurring_single_equip.onchange_recurring_template_id() + repair_recurring_single_equip.action_start() + + # Check if the orders are created + self.assertEqual(repair_recurring_single_equip.state, "progress") + self.assertEqual(len(repair_recurring_single_equip.fsm_order_ids), 4)