diff --git a/fieldservice_purchase_request/README.rst b/fieldservice_purchase_request/README.rst new file mode 100644 index 0000000000..d6b1b97f93 --- /dev/null +++ b/fieldservice_purchase_request/README.rst @@ -0,0 +1,89 @@ +================================ +Field Service - Purchase Request +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8c0aacfbd9c19169889c55fb0a9b9e011edb060981daf78b3bdd992562287326 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/fieldservice_purchase_request + :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-18-0/field-service-18-0-fieldservice_purchase_request + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Let field technicians request parts from a field service order. + +A **Request Parts** button on the FSM order creates a purchase request +linked to the order (origin and requester pre-filled), and a stat button +shows all purchase requests originated by the order. Deleting an order +keeps its purchase requests, only unlinking the reference. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* Pop Solutions + +Contributors +------------ + +- Marcos Mendez + +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-marcos-mendez| image:: https://github.com/marcos-mendez.png?size=40px + :target: https://github.com/marcos-mendez + :alt: marcos-mendez + +Current `maintainer `__: + +|maintainer-marcos-mendez| + +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_purchase_request/__init__.py b/fieldservice_purchase_request/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_purchase_request/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_purchase_request/__manifest__.py b/fieldservice_purchase_request/__manifest__.py new file mode 100644 index 0000000000..1f126c221e --- /dev/null +++ b/fieldservice_purchase_request/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 Pop Solutions +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Field Service - Purchase Request", + "summary": "Request parts (purchase requests) from field service orders", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "website": "https://github.com/OCA/field-service", + "category": "Field Service", + "author": "Pop Solutions, Odoo Community Association (OCA)", + "maintainers": ["marcos-mendez"], + "depends": ["fieldservice", "purchase_request"], + "data": ["views/fsm_order_views.xml"], +} diff --git a/fieldservice_purchase_request/i18n/pt_BR.po b/fieldservice_purchase_request/i18n/pt_BR.po new file mode 100644 index 0000000000..72d98ed8ed --- /dev/null +++ b/fieldservice_purchase_request/i18n/pt_BR.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_purchase_request +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Pop Solutions\n" +"Language-Team: \n" +"Language: pt_BR\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" + +#. module: fieldservice_purchase_request +#: model:ir.model.fields,field_description:fieldservice_purchase_request.field_purchase_request__fsm_order_id +msgid "Field Service Order" +msgstr "Ordem de Serviço" + +#. module: fieldservice_purchase_request +#: model:ir.model.fields,field_description:fieldservice_purchase_request.field_fsm_order__purchase_request_ids +msgid "Purchase Requests" +msgstr "Requisições de Compra" + +#. module: fieldservice_purchase_request +#: model:ir.model.fields,field_description:fieldservice_purchase_request.field_fsm_order__purchase_request_count +msgid "# Purchase Requests" +msgstr "Nº de Requisições" + +#. module: fieldservice_purchase_request +#: model_terms:ir.ui.view,arch_db:fieldservice_purchase_request.fsm_order_form_purchase_request +msgid "Request Parts" +msgstr "Solicitar Peças" + +#. module: fieldservice_purchase_request +#: model:ir.model.fields,help:fieldservice_purchase_request.field_purchase_request__fsm_order_id +msgid "Field service order that originated this purchase request." +msgstr "OS de campo que originou esta requisição de peças." diff --git a/fieldservice_purchase_request/models/__init__.py b/fieldservice_purchase_request/models/__init__.py new file mode 100644 index 0000000000..141a660af7 --- /dev/null +++ b/fieldservice_purchase_request/models/__init__.py @@ -0,0 +1,2 @@ +from . import purchase_request +from . import fsm_order diff --git a/fieldservice_purchase_request/models/fsm_order.py b/fieldservice_purchase_request/models/fsm_order.py new file mode 100644 index 0000000000..6fc77daf7e --- /dev/null +++ b/fieldservice_purchase_request/models/fsm_order.py @@ -0,0 +1,52 @@ +# Copyright 2026 Pop Solutions +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models + + +class FSMOrder(models.Model): + _inherit = "fsm.order" + + purchase_request_ids = fields.One2many( + "purchase.request", "fsm_order_id", string="Purchase Requests" + ) + purchase_request_count = fields.Integer( + compute="_compute_purchase_request_count", string="# Purchase Requests" + ) + + @api.depends("purchase_request_ids") + def _compute_purchase_request_count(self): + for order in self: + order.purchase_request_count = len(order.purchase_request_ids) + + def action_create_purchase_request(self): + self.ensure_one() + request = self.env["purchase.request"].create( + { + "fsm_order_id": self.id, + "origin": self.name, + "requested_by": self.env.user.id, + "company_id": self.company_id.id, + } + ) + return { + "type": "ir.actions.act_window", + "name": _("Request Parts"), + "res_model": "purchase.request", + "res_id": request.id, + "view_mode": "form", + "target": "current", + } + + def action_view_purchase_requests(self): + self.ensure_one() + return { + "type": "ir.actions.act_window", + "name": _("Purchase Requests"), + "res_model": "purchase.request", + "domain": [("fsm_order_id", "=", self.id)], + "view_mode": "list,form", + "context": { + "default_fsm_order_id": self.id, + "default_origin": self.name, + }, + } diff --git a/fieldservice_purchase_request/models/purchase_request.py b/fieldservice_purchase_request/models/purchase_request.py new file mode 100644 index 0000000000..450e41698b --- /dev/null +++ b/fieldservice_purchase_request/models/purchase_request.py @@ -0,0 +1,15 @@ +# Copyright 2026 Pop Solutions +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class PurchaseRequest(models.Model): + _inherit = "purchase.request" + + fsm_order_id = fields.Many2one( + "fsm.order", + string="Field Service Order", + index=True, + ondelete="set null", + help="Field service order that originated this purchase request.", + ) diff --git a/fieldservice_purchase_request/pyproject.toml b/fieldservice_purchase_request/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_purchase_request/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_purchase_request/readme/CONTRIBUTORS.md b/fieldservice_purchase_request/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ada042f260 --- /dev/null +++ b/fieldservice_purchase_request/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Marcos Mendez \ diff --git a/fieldservice_purchase_request/readme/DESCRIPTION.md b/fieldservice_purchase_request/readme/DESCRIPTION.md new file mode 100644 index 0000000000..cc0975ffa6 --- /dev/null +++ b/fieldservice_purchase_request/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +Let field technicians request parts from a field service order. + +A **Request Parts** button on the FSM order creates a purchase request linked +to the order (origin and requester pre-filled), and a stat button shows all +purchase requests originated by the order. Deleting an order keeps its +purchase requests, only unlinking the reference. diff --git a/fieldservice_purchase_request/static/description/index.html b/fieldservice_purchase_request/static/description/index.html new file mode 100644 index 0000000000..1126ad27c2 --- /dev/null +++ b/fieldservice_purchase_request/static/description/index.html @@ -0,0 +1,429 @@ + + + + + +Field Service - Purchase Request + + + +
+

Field Service - Purchase Request

+ + +

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

+

Let field technicians request parts from a field service order.

+

A Request Parts button on the FSM order creates a purchase request +linked to the order (origin and requester pre-filled), and a stat button +shows all purchase requests originated by the order. Deleting an order +keeps its purchase requests, only unlinking the reference.

+

Table of contents

+ +
+

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

+
    +
  • Pop Solutions
  • +
+
+
+

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:

+

marcos-mendez

+

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_purchase_request/tests/__init__.py b/fieldservice_purchase_request/tests/__init__.py new file mode 100644 index 0000000000..a1144f6a5e --- /dev/null +++ b/fieldservice_purchase_request/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fsm_purchase_request diff --git a/fieldservice_purchase_request/tests/test_fsm_purchase_request.py b/fieldservice_purchase_request/tests/test_fsm_purchase_request.py new file mode 100644 index 0000000000..cbafaf6209 --- /dev/null +++ b/fieldservice_purchase_request/tests/test_fsm_purchase_request.py @@ -0,0 +1,33 @@ +# Copyright 2026 Pop Solutions +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests.common import TransactionCase + + +class TestFsmPurchaseRequest(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.order = cls.env["fsm.order"].create( + {"location_id": cls.env.ref("fieldservice.test_location").id} + ) + + def test_create_purchase_request_from_order(self): + action = self.order.action_create_purchase_request() + request = self.env["purchase.request"].browse(action["res_id"]) + self.assertEqual(request.fsm_order_id, self.order) + self.assertEqual(request.origin, self.order.name) + self.assertEqual(self.order.purchase_request_count, 1) + self.assertEqual(self.order.purchase_request_ids, request) + + def test_view_purchase_requests_action(self): + self.order.action_create_purchase_request() + action = self.order.action_view_purchase_requests() + self.assertEqual(action["domain"], [("fsm_order_id", "=", self.order.id)]) + self.assertEqual(action["context"]["default_fsm_order_id"], self.order.id) + + def test_unlink_order_keeps_request(self): + action = self.order.action_create_purchase_request() + request = self.env["purchase.request"].browse(action["res_id"]) + self.order.unlink() + self.assertTrue(request.exists()) + self.assertFalse(request.fsm_order_id) diff --git a/fieldservice_purchase_request/views/fsm_order_views.xml b/fieldservice_purchase_request/views/fsm_order_views.xml new file mode 100644 index 0000000000..5eb5c8f412 --- /dev/null +++ b/fieldservice_purchase_request/views/fsm_order_views.xml @@ -0,0 +1,34 @@ + + + + fsm.order.form.purchase.request + fsm.order + + +
+
+ + + +
+
+