diff --git a/fieldservice_equipment_stock_return/README.rst b/fieldservice_equipment_stock_return/README.rst new file mode 100644 index 0000000000..4b4954ded1 --- /dev/null +++ b/fieldservice_equipment_stock_return/README.rst @@ -0,0 +1,124 @@ +====================================== +Field Service - Stock Equipment Return +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ccef108ff488fd2820ce9403b90512a866de4e4edaa606f7f03418b70520b741 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_equipment_stock_return + :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_equipment_stock_return + :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 return FSM equipments creating a new picking. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Check ``Field Service - Stock Equipment`` module configuration. + +To configure this module, you need to: + +- Go to Field Service > Configuration > Order Types +- Check if you have at least one ``return`` order type +- Set the ``Picking Type`` linked to the ``return`` order type + +Usage +===== + +The ``Return`` field service order type can be used to create a field +service order to dispatch someone to pickup equipments in its current +location. From the equipment, it is possible to create an order to +record the return of the equipment. This action will create a new +picking with the equipment to be returned. + +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 +* Italo LOPES + +Contributors +------------ + +- Italo LOPES + +Other credits +------------- + +The development of this module has been financially supported by: + +- Camptocamp SA + +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-brian10048| image:: https://github.com/brian10048.png?size=40px + :target: https://github.com/brian10048 + :alt: brian10048 +.. |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-smangukiya| image:: https://github.com/smangukiya.png?size=40px + :target: https://github.com/smangukiya + :alt: smangukiya +.. |maintainer-imlopes| image:: https://github.com/imlopes.png?size=40px + :target: https://github.com/imlopes + :alt: imlopes + +Current `maintainers `__: + +|maintainer-brian10048| |maintainer-wolfhall| |maintainer-max3903| |maintainer-smangukiya| |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_equipment_stock_return/__init__.py b/fieldservice_equipment_stock_return/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/fieldservice_equipment_stock_return/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/fieldservice_equipment_stock_return/__manifest__.py b/fieldservice_equipment_stock_return/__manifest__.py new file mode 100644 index 0000000000..8e814826b3 --- /dev/null +++ b/fieldservice_equipment_stock_return/__manifest__.py @@ -0,0 +1,30 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Field Service - Stock Equipment Return", + "summary": "Integrate return orders for field service equipments", + "version": "17.0.1.0.0", + "category": "Field Service", + "author": "Camptocamp, " "Italo LOPES, " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": [ + "fieldservice_equipment_stock", + ], + "data": [ + "data/fsm_order_type.xml", + "views/fsm_equipment.xml", + "views/fsm_order_view.xml", + "views/fsm_order_type_view.xml", + ], + "license": "AGPL-3", + "development_status": "Beta", + "maintainers": [ + "brian10048", + "wolfhall", + "max3903", + "smangukiya", + "imlopes", + ], +} diff --git a/fieldservice_equipment_stock_return/data/fsm_order_type.xml b/fieldservice_equipment_stock_return/data/fsm_order_type.xml new file mode 100644 index 0000000000..39d0acb902 --- /dev/null +++ b/fieldservice_equipment_stock_return/data/fsm_order_type.xml @@ -0,0 +1,9 @@ + + + + + Return + return + + + diff --git a/fieldservice_equipment_stock_return/i18n/fieldservice_equipment_stock_return.pot b/fieldservice_equipment_stock_return/i18n/fieldservice_equipment_stock_return.pot new file mode 100644 index 0000000000..bc019e7b9e --- /dev/null +++ b/fieldservice_equipment_stock_return/i18n/fieldservice_equipment_stock_return.pot @@ -0,0 +1,81 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_equipment_stock_return +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-10-29 14:22+0000\n" +"PO-Revision-Date: 2024-10-29 14:22+0000\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: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "" +"Cannot create a return order because order type does not have a current " +"Picking Type." +msgstr "" + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "Cannot create return order without an equipment." +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model_terms:ir.ui.view,arch_db:fieldservice_equipment_stock_return.fsm_equipment_form_view_stock +msgid "Create Return" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_equipment +msgid "Field Service Equipment" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_order +msgid "Field Service Order" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_order_type +msgid "Field Service Order Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "Impossible to find the equipment current location." +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields,field_description:fieldservice_equipment_stock_return.field_fsm_order_type__internal_type +msgid "Internal Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_equipment.py:0 +#, python-format +msgid "No return order type found." +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields,field_description:fieldservice_equipment_stock_return.field_fsm_order_type__picking_type_id +msgid "Picking Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields.selection,name:fieldservice_equipment_stock_return.selection__fsm_order_type__internal_type__return +msgid "Return" +msgstr "" diff --git a/fieldservice_equipment_stock_return/i18n/fr.po b/fieldservice_equipment_stock_return/i18n/fr.po new file mode 100644 index 0000000000..2d9abed9ee --- /dev/null +++ b/fieldservice_equipment_stock_return/i18n/fr.po @@ -0,0 +1,81 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * fieldservice_equipment_stock_return +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-10-29 14:22+0000\n" +"PO-Revision-Date: 2024-10-29 14:22+0000\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: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "" +"Cannot create a return order because order type does not have a current " +"Picking Type." +msgstr "Impossible de créer une commande de retour car le type choisie n'a pas de Type de Picking définie." + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "Cannot create return order without an equipment." +msgstr "Impossible de créer une commande de retour sans équipement." + +#. module: fieldservice_equipment_stock_return +#: model_terms:ir.ui.view,arch_db:fieldservice_equipment_stock_return.fsm_equipment_form_view_stock +msgid "Create Return" +msgstr "Créer un retour" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_equipment +msgid "Field Service Equipment" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_order +msgid "Field Service Order" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model,name:fieldservice_equipment_stock_return.model_fsm_order_type +msgid "Field Service Order Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_order.py:0 +#, python-format +msgid "Impossible to find the equipment current location." +msgstr "Impossible de trouver l'emplacement actuel de l'équipement." + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields,field_description:fieldservice_equipment_stock_return.field_fsm_order_type__internal_type +msgid "Internal Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#. odoo-python +#: code:addons/fieldservice_equipment_stock_return/models/fsm_equipment.py:0 +#, python-format +msgid "No return order type found." +msgstr "Aucun type de commande avec un type interne de retour trouvé." + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields,field_description:fieldservice_equipment_stock_return.field_fsm_order_type__picking_type_id +msgid "Picking Type" +msgstr "" + +#. module: fieldservice_equipment_stock_return +#: model:ir.model.fields.selection,name:fieldservice_equipment_stock_return.selection__fsm_order_type__internal_type__return +msgid "Return" +msgstr "Retour" diff --git a/fieldservice_equipment_stock_return/models/__init__.py b/fieldservice_equipment_stock_return/models/__init__.py new file mode 100644 index 0000000000..7e821bbc7f --- /dev/null +++ b/fieldservice_equipment_stock_return/models/__init__.py @@ -0,0 +1,5 @@ +from . import ( + fsm_equipment, + fsm_order, + fsm_order_type, +) diff --git a/fieldservice_equipment_stock_return/models/fsm_equipment.py b/fieldservice_equipment_stock_return/models/fsm_equipment.py new file mode 100644 index 0000000000..f76a65969c --- /dev/null +++ b/fieldservice_equipment_stock_return/models/fsm_equipment.py @@ -0,0 +1,33 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, models +from odoo.exceptions import ValidationError + + +class FSMEquipment(models.Model): + _inherit = "fsm.equipment" + + def create_equipment_order_return(self): + self.ensure_one() + order_type = self.env.ref( + "fieldservice_equipment_stock_return.fsm_order_type_return", + raise_if_not_found=False, + ) + if not order_type: + order_type = self.env["fsm.order.type"].search( + [("internal_type", "=", "return")], limit=1 + ) + if not order_type: + raise ValidationError(_("No return order type found.")) + return { + "name": "Return Equipment", + "type": "ir.actions.act_window", + "res_model": "fsm.order", + "view_mode": "form", + "context": { + "default_equipment_id": self.id, + "default_type": order_type and order_type.id or False, + }, + } diff --git a/fieldservice_equipment_stock_return/models/fsm_order.py b/fieldservice_equipment_stock_return/models/fsm_order.py new file mode 100644 index 0000000000..d842f3a381 --- /dev/null +++ b/fieldservice_equipment_stock_return/models/fsm_order.py @@ -0,0 +1,88 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class FSMOrder(models.Model): + _inherit = "fsm.order" + + def _prepare_return_procurement_group_values(self): + self.ensure_one() + return { + "name": self.display_name, + "fsm_order_id": self.id, + "move_type": "direct", + } + + def _get_equipment_current_location(self): + self.ensure_one() + if self.equipment_id.current_stock_location_id: + return self.equipment_id.current_stock_location_id + elif self.equipment_id.current_location_id: + return ( + self.equipment_id.current_location_id + and self.equipment_id.current_location_id.inventory_location_id + ) + else: + raise ValidationError( + _("Impossible to find the equipment current location.") + ) + + def _prepare_return_stock_picking_values(self): + self.ensure_one() + source_location_id = self._get_equipment_current_location() + return { + "picking_type_id": self.type.picking_type_id.id, + "origin": self.display_name, + "location_dest_id": self.type.picking_type_id.default_location_dest_id.id, + "location_id": source_location_id and source_location_id.id, + "fsm_order_id": self.id, + "group_id": self.procurement_group_id.id, + } + + def _prepare_return_stock_move_values(self): + self.ensure_one() + source_location_id = self._get_equipment_current_location() + return { + "name": self.display_name, + "product_id": self.equipment_id.product_id.id, + "product_uom_qty": 1, + "product_uom": self.equipment_id.product_id.uom_id.id, + "location_id": source_location_id.id, + "location_dest_id": self.type.picking_type_id.default_location_dest_id.id, + "group_id": self.procurement_group_id.id, + "fsm_order_id": self.id, + "lot_ids": [(4, self.equipment_id.lot_id.id)] + if self.equipment_id.lot_id + else False, + } + + @api.model_create_multi + def create(self, vals_list): + orders = super().create(vals_list) + for order in orders: + if order.type.internal_type == "return": + if not order.type.picking_type_id or not order.equipment_id: + raise ValidationError( + _( + "You must set a Picking Type on the order type " + "and an equipment on the order." + ) + ) + group = self.env["procurement.group"].search( + [("fsm_order_id", "=", order.id)] + ) + if not group: + values = order._prepare_return_procurement_group_values() + group = self.env["procurement.group"].create(values) + order.procurement_group_id = group and group.id + return_picking_values = order._prepare_return_stock_picking_values() + new_picking = self.env["stock.picking"].create(return_picking_values) + return_move_values = order._prepare_return_stock_move_values() + return_move_values["picking_id"] = new_picking.id + self.env["stock.move"].create(return_move_values) + new_picking.action_confirm() + return orders diff --git a/fieldservice_equipment_stock_return/models/fsm_order_type.py b/fieldservice_equipment_stock_return/models/fsm_order_type.py new file mode 100644 index 0000000000..f295be005f --- /dev/null +++ b/fieldservice_equipment_stock_return/models/fsm_order_type.py @@ -0,0 +1,17 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class FsmOrderType(models.Model): + _inherit = "fsm.order.type" + + internal_type = fields.Selection( + selection_add=[("return", "Return")], + ) + picking_type_id = fields.Many2one( + "stock.picking.type", + domain=[("code", "=", "incoming")], + ) diff --git a/fieldservice_equipment_stock_return/pyproject.toml b/fieldservice_equipment_stock_return/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/fieldservice_equipment_stock_return/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/fieldservice_equipment_stock_return/readme/CONFIGURE.md b/fieldservice_equipment_stock_return/readme/CONFIGURE.md new file mode 100644 index 0000000000..3c334e1ad9 --- /dev/null +++ b/fieldservice_equipment_stock_return/readme/CONFIGURE.md @@ -0,0 +1,8 @@ +Check `Field Service - Stock Equipment` module configuration. + + +To configure this module, you need to: + +- Go to Field Service \> Configuration \> Order Types +- Check if you have at least one `return` order type +- Set the `Picking Type` linked to the `return` order type diff --git a/fieldservice_equipment_stock_return/readme/CONTRIBUTORS.md b/fieldservice_equipment_stock_return/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..0b564563c9 --- /dev/null +++ b/fieldservice_equipment_stock_return/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Italo LOPES \<\> diff --git a/fieldservice_equipment_stock_return/readme/CREDITS.md b/fieldservice_equipment_stock_return/readme/CREDITS.md new file mode 100644 index 0000000000..f2acf51d88 --- /dev/null +++ b/fieldservice_equipment_stock_return/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +- Camptocamp SA \<\> diff --git a/fieldservice_equipment_stock_return/readme/DESCRIPTION.md b/fieldservice_equipment_stock_return/readme/DESCRIPTION.md new file mode 100644 index 0000000000..8b406f7213 --- /dev/null +++ b/fieldservice_equipment_stock_return/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows you to return FSM equipments creating a new picking. diff --git a/fieldservice_equipment_stock_return/readme/USAGE.md b/fieldservice_equipment_stock_return/readme/USAGE.md new file mode 100644 index 0000000000..a8acc92782 --- /dev/null +++ b/fieldservice_equipment_stock_return/readme/USAGE.md @@ -0,0 +1,4 @@ +The `Return` field service order type can be used to create a field service order to dispatch +someone to pickup equipments in its current location. +From the equipment, it is possible to create an order to record the return of the equipment. +This action will create a new picking with the equipment to be returned. diff --git a/fieldservice_equipment_stock_return/static/description/icon.png b/fieldservice_equipment_stock_return/static/description/icon.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/fieldservice_equipment_stock_return/static/description/index.html b/fieldservice_equipment_stock_return/static/description/index.html new file mode 100644 index 0000000000..317ff98354 --- /dev/null +++ b/fieldservice_equipment_stock_return/static/description/index.html @@ -0,0 +1,451 @@ + + + + + +Field Service - Stock Equipment Return + + + +
+

Field Service - Stock Equipment Return

+ + +

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

+

This module allows you to return FSM equipments creating a new picking.

+

Table of contents

+ +
+

Configuration

+

Check Field Service - Stock Equipment module configuration.

+

To configure this module, you need to:

+
    +
  • Go to Field Service > Configuration > Order Types
  • +
  • Check if you have at least one return order type
  • +
  • Set the Picking Type linked to the return order type
  • +
+
+
+

Usage

+

The Return field service order type can be used to create a field +service order to dispatch someone to pickup equipments in its current +location. From the equipment, it is possible to create an order to +record the return of the equipment. This action will create a new +picking with the equipment to be returned.

+
+
+

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
  • +
  • Italo LOPES
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+ +
+
+

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:

+

brian10048 wolfhall max3903 smangukiya 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_equipment_stock_return/tests/__init__.py b/fieldservice_equipment_stock_return/tests/__init__.py new file mode 100644 index 0000000000..d43fe65f38 --- /dev/null +++ b/fieldservice_equipment_stock_return/tests/__init__.py @@ -0,0 +1 @@ +from . import test_fsm_equipment_return diff --git a/fieldservice_equipment_stock_return/tests/test_fsm_equipment_return.py b/fieldservice_equipment_stock_return/tests/test_fsm_equipment_return.py new file mode 100644 index 0000000000..730f186024 --- /dev/null +++ b/fieldservice_equipment_stock_return/tests/test_fsm_equipment_return.py @@ -0,0 +1,156 @@ +# Copyright 2024 Camptocamp SA (https://www.camptocamp.com). +# @author: Italo Lopes +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestFSMEquipmentStockReturn(TransactionCase): + def setUp(self): + super().setUp() + self.fsm_test_location = self.env.ref("fieldservice.test_location") + self.stock_location = self.env.ref("stock.stock_location_customers") + + self.fsm_test_location2 = self.env.ref("fieldservice.test_location").copy() + self.stock_location2 = self.env["stock.location"].create( + {"name": "Stock Location", "usage": "internal"} + ) + self.fsm_test_location2.write( + { + "name": "Test Location 2", + "inventory_location_id": self.stock_location2.id, + } + ) + + self.FSMOrder = self.env["fsm.order"] + self.FSMEquip = self.env["fsm.equipment"] + self.OrderType = self.env.ref( + "fieldservice_equipment_stock_return.fsm_order_type_return" + ) + self.OrderType.picking_type_id = ( + self.env["stock.picking.type"] + .search([("code", "=", "incoming")], limit=1) + .id + ) + self.product1 = self.env["product.product"].create( + {"name": "Product A", "type": "product"} + ) + self.lot1 = self.env["stock.lot"].create( + { + "name": "sn11", + "product_id": self.product1.id, + "company_id": self.env.company.id, + "location_id": self.stock_location.id, + } + ) + self.equipment = self.FSMEquip.create( + { + "name": "test equipment", + "product_id": self.product1.id, + "lot_id": self.lot1.id, + } + ) + + def test_00_equipment_return(self): + """Test return from equipment.""" + equipment_create_vals = self.equipment.create_equipment_order_return() + self.assertEqual(equipment_create_vals["res_model"], "fsm.order") + self.assertEqual( + equipment_create_vals["context"]["default_equipment_id"], self.equipment.id + ) + self.assertEqual( + equipment_create_vals["context"]["default_type"], self.OrderType.id + ) + + def test_01_fsmorder_equipment_return(self): + """Test creating new fsm order.""" + self.equipment.current_stock_location_id = self.stock_location.id + fsm_order_return = self.FSMOrder.create( + { + "type": self.OrderType.id, + "location_id": self.fsm_test_location.id, + "equipment_id": self.equipment.id, + } + ) + picking = fsm_order_return.picking_ids + self.assertEqual(picking.picking_type_id, fsm_order_return.type.picking_type_id) + self.assertEqual(picking.group_id, fsm_order_return.procurement_group_id) + self.assertEqual(picking.fsm_order_id, fsm_order_return) + + def get_validate_message(self, error_type): + if error_type == "no_location": + return "Impossible to find the equipment current location." + elif error_type == "no_picking_type": + return ( + "You must set a Picking Type on the order type " + "and an equipment on the order" + ) + elif error_type == "no_order_type": + return "No return order type found." + elif error_type == "no_equipment": + return ( + "You must set a Picking Type on the order type " + "and an equipment on the order" + ) + + def test_02_equipment_return_errors_no_location(self): + """Test creating new fsm order with known errors.""" + + message = self.get_validate_message("no_location") + with self.assertRaisesRegex(ValidationError, message): + self.FSMOrder.create( + { + "type": self.OrderType.id, + "location_id": self.fsm_test_location.id, + "equipment_id": self.equipment.id, + } + ) + + def test_03_equipment_return_errors_no_picking_type(self): + """Test creating new fsm order with known errors.""" + message = self.get_validate_message("no_picking_type") + self.OrderType.picking_type_id = False + with self.assertRaisesRegex(ValidationError, message): + self.FSMOrder.create( + { + "type": self.OrderType.id, + "location_id": self.fsm_test_location.id, + "equipment_id": self.equipment.id, + } + ) + + def test_04_equipment_return_errors_no_order_type(self): + """Test creating new fsm order with known errors.""" + message = self.get_validate_message("no_order_type") + self.OrderType.unlink() + with self.assertRaisesRegex(ValidationError, message): + self.equipment.create_equipment_order_return() + + def test_05_equipment_return_errors_no_equipment(self): + """Test creating new fsm order with known errors.""" + message = self.get_validate_message("no_equipment") + with self.assertRaisesRegex(ValidationError, message): + self.FSMOrder.create( + { + "type": self.OrderType.id, + "location_id": self.fsm_test_location.id, + } + ) + + def test_06_equipment_return_errors_using_fsm_current_location(self): + """Test creating new fsm order with known errors.""" + self.equipment.current_location_id = self.fsm_test_location2.id + fsm_order_return = self.FSMOrder.create( + { + "type": self.OrderType.id, + "location_id": self.fsm_test_location.id, + "equipment_id": self.equipment.id, + } + ) + picking = fsm_order_return.picking_ids + self.assertEqual(picking.picking_type_id, fsm_order_return.type.picking_type_id) + self.assertEqual(picking.group_id, fsm_order_return.procurement_group_id) + self.assertEqual(picking.fsm_order_id, fsm_order_return) + self.assertEqual(picking.location_id, self.stock_location2) diff --git a/fieldservice_equipment_stock_return/views/fsm_equipment.xml b/fieldservice_equipment_stock_return/views/fsm_equipment.xml new file mode 100644 index 0000000000..31b4f3d3f7 --- /dev/null +++ b/fieldservice_equipment_stock_return/views/fsm_equipment.xml @@ -0,0 +1,29 @@ + + + + + fsm.equipment.form.stock + fsm.equipment + + + + + + + diff --git a/fieldservice_equipment_stock_return/views/fsm_order_type_view.xml b/fieldservice_equipment_stock_return/views/fsm_order_type_view.xml new file mode 100644 index 0000000000..2abf2397a3 --- /dev/null +++ b/fieldservice_equipment_stock_return/views/fsm_order_type_view.xml @@ -0,0 +1,23 @@ + + + + + + fsm.order.type + + + + + + + + + diff --git a/fieldservice_equipment_stock_return/views/fsm_order_view.xml b/fieldservice_equipment_stock_return/views/fsm_order_view.xml new file mode 100644 index 0000000000..ef035bd193 --- /dev/null +++ b/fieldservice_equipment_stock_return/views/fsm_order_view.xml @@ -0,0 +1,25 @@ + + + + + + fsm.order + + + + + + internal_type in ['return'] + + + + +