From 5dc61690cc7b6cd1d3c92f2f9499f6c68843caaa Mon Sep 17 00:00:00 2001 From: Heliconia Solutions Date: Tue, 17 Dec 2024 09:39:50 +0530 Subject: [PATCH] [MIG] mrp_repair_order: Migration to 18.0 --- mrp_repair_order/README.rst | 16 ++- mrp_repair_order/__manifest__.py | 2 +- mrp_repair_order/readme/CONTRIBUTORS.md | 1 + .../tests/test_mrp_repair_order.py | 128 +++++++++++++++--- 4 files changed, 122 insertions(+), 25 deletions(-) diff --git a/mrp_repair_order/README.rst b/mrp_repair_order/README.rst index 7980df2da70..ae473722f64 100644 --- a/mrp_repair_order/README.rst +++ b/mrp_repair_order/README.rst @@ -17,13 +17,13 @@ MRP Repair Order :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github - :target: https://github.com/OCA/manufacture/tree/17.0/mrp_repair_order + :target: https://github.com/OCA/manufacture/tree/18.0/mrp_repair_order :alt: OCA/manufacture .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-mrp_repair_order + :target: https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_repair_order :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/manufacture&target_branch=17.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=18.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -58,7 +58,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -73,9 +73,11 @@ Authors Contributors ------------ -- [APSL-Nagarro](https://apsl.tech): +- [APSL-Nagarro](https://apsl.tech): - - Antoni Marroig + - Antoni Marroig + +- Heliconia Solutions Pvt. Ltd. Maintainers ----------- @@ -98,6 +100,6 @@ Current `maintainer `__: |maintainer-peluko00| -This module is part of the `OCA/manufacture `_ project on GitHub. +This module is part of the `OCA/manufacture `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_repair_order/__manifest__.py b/mrp_repair_order/__manifest__.py index 1593c107d4e..5068981bbf6 100644 --- a/mrp_repair_order/__manifest__.py +++ b/mrp_repair_order/__manifest__.py @@ -3,7 +3,7 @@ { "name": "MRP Repair Order", "summary": "Create repair order from manufacturing order", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "category": "Manufacturing", "website": "https://github.com/OCA/manufacture", "author": "Antoni Marroig, Odoo Community Association (OCA)", diff --git a/mrp_repair_order/readme/CONTRIBUTORS.md b/mrp_repair_order/readme/CONTRIBUTORS.md index c5177d8c592..842e90f93fc 100644 --- a/mrp_repair_order/readme/CONTRIBUTORS.md +++ b/mrp_repair_order/readme/CONTRIBUTORS.md @@ -1,2 +1,3 @@ - \[APSL-Nagarro\](): - Antoni Marroig \<\> +- Heliconia Solutions Pvt. Ltd. \<\> diff --git a/mrp_repair_order/tests/test_mrp_repair_order.py b/mrp_repair_order/tests/test_mrp_repair_order.py index a1f93df2652..6fbbfbc196b 100644 --- a/mrp_repair_order/tests/test_mrp_repair_order.py +++ b/mrp_repair_order/tests/test_mrp_repair_order.py @@ -1,30 +1,124 @@ # Copyright 2024 Antoni Marroig(APSL-Nagarro) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.tests.common import Form, TransactionCase +from odoo.tests import Form, TransactionCase -class MRPRepairOrderTest(TransactionCase): +class TestMrpRepairIntegration(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.mrp_order = cls.env["mrp.production"].create( + # Create product + cls.product = cls.env["product.product"].create( { - "product_id": cls.env.ref("product.product_delivery_01").id, - "product_qty": 2, + "name": "Test Product", + "tracking": "none", } ) + # Create component + cls.component = cls.env["product.product"].create( + { + "name": "Test Component", + } + ) + # Create BOM + cls.bom = cls.env["mrp.bom"].create( + { + "product_tmpl_id": cls.product.product_tmpl_id.id, + "product_qty": 1.0, + "type": "normal", + "bom_line_ids": [ + (0, 0, {"product_id": cls.component.id, "product_qty": 1.0}) + ], + } + ) + + def test_01_create_repair_from_mrp(self): + """Test creation of repair order from manufacturing order""" + # Create MO + mo_form = Form(self.env["mrp.production"]) + mo_form.product_id = self.product + mo_form.bom_id = self.bom + mo_form.product_qty = 1.0 + mo = mo_form.save() + + # Create repair order from MO + action = mo.action_create_repair_order() + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["res_model"], "repair.order") + self.assertEqual(action["view_mode"], "form") + self.assertEqual(action["target"], "new") - def test_create_repair_order_from_mrp(self): - repair_form = Form( - self.env["repair.order"].with_context( - default_mrp_id=self.mrp_order.id, - default_product_qty=self.mrp_order.product_qty, - default_product_id=self.mrp_order.product_id.id, - default_mrp_ids=[self.mrp_order.id], - ) + # Check context values + context = action["context"] + self.assertEqual(context["default_product_id"], self.product.id) + self.assertEqual(context["default_product_qty"], 1.0) + self.assertEqual(context["default_mrp_ids"], [mo.id]) + + def test_02_repair_mrp_navigation(self): + """Test navigation between repair order and manufacturing order""" + # Create MO + mo = self.env["mrp.production"].create( + { + "product_id": self.product.id, + "bom_id": self.bom.id, + "product_qty": 1.0, + } + ) + + # Create Repair Order + repair = self.env["repair.order"].create( + { + "product_id": self.product.id, + "product_qty": 1.0, + "mrp_ids": [(4, mo.id)], + } ) - repair_order = repair_form.save() - self.assertEqual(self.mrp_order.repair_id, repair_order) - self.assertEqual(self.mrp_order.repair_id.product_id, repair_order.product_id) - self.assertEqual(self.mrp_order.repair_id.product_qty, repair_order.product_qty) + + # Link MO to repair + mo.repair_id = repair.id + + # Test navigation from repair to MO + action = repair.action_view_repair_manufacturing_order() + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["res_model"], "mrp.production") + self.assertEqual(action["res_id"], mo.id) + + # Test navigation from MO to repair + action = mo.action_view_mrp_production_repair_orders() + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["res_model"], "repair.order") + self.assertEqual(action["res_id"], repair.id) + + def test_03_multiple_mrp_orders(self): + """Test handling of multiple manufacturing orders linked to repair""" + repair = self.env["repair.order"].create( + { + "product_id": self.product.id, + "product_qty": 1.0, + } + ) + + # Create multiple MOs + mo1 = self.env["mrp.production"].create( + { + "product_id": self.product.id, + "bom_id": self.bom.id, + "product_qty": 1.0, + "repair_id": repair.id, + } + ) + + mo2 = self.env["mrp.production"].create( + { + "product_id": self.product.id, + "bom_id": self.bom.id, + "product_qty": 1.0, + "repair_id": repair.id, + } + ) + + # Verify mrp_ids in repair order + self.assertEqual(len(repair.mrp_ids), 2) + self.assertIn(mo1.id, repair.mrp_ids.ids) + self.assertIn(mo2.id, repair.mrp_ids.ids)