diff --git a/repair_picking_after_done/README.rst b/repair_picking_after_done/README.rst index e9f18d75..cd4585eb 100644 --- a/repair_picking_after_done/README.rst +++ b/repair_picking_after_done/README.rst @@ -28,8 +28,15 @@ Repair picking after done |badge1| |badge2| |badge3| |badge4| |badge5| -This module adds the functionality to create transfer of repaired move -once repair order is done. +This module enhances Odoo's repair process by introducing automatic +stock transfers for repaired products. + +- **Automatic Transfer:** When a repair order is marked as done, a + stock transfer for the remaining repaired products is automatically + created and validated if the **auto_transfer_repair** parameter is + enabled. +- **Manual Transfer:** Users can manually create stock transfers when + automatic transfer is disabled. .. IMPORTANT:: This is an alpha version, the data model and design can change at any time without warning. @@ -44,14 +51,32 @@ once repair order is done. Configuration ============= -No configuration needed for this module. +To enable automatic transfers for repaired products when a repair order +is completed: + +- Navigate to Repairs → Configuration → Settings. +- Enable the **Automatic Transfer on Repair Completion** setting. + +When enabled, internal transfers for repaired products are automatically +created and validated upon completing the repair order. Usage ===== -After repair order is done, You will be able to see button "Transfer" on -repair order's form view. You will be able to create internal transfer -between repair location to any destination location. +**Manual Transfers** + +1. After a repair order is marked as **Done**, a **Create Transfer** + button will appear on the repair order's form view. +2. Click the Create Transfer button to create an internal transfer for + the repaired products. +3. Specify the destination location and quantity to complete the + transfer. + +**Automatic Transfers** + +1. If the **auto_transfer_repair** configuration parameter is enabled, + an internal transfer is automatically created and validated when the + repair order is marked as **Done**. Known issues / Roadmap ====================== diff --git a/repair_picking_after_done/__manifest__.py b/repair_picking_after_done/__manifest__.py index a0edf33d..363c994c 100644 --- a/repair_picking_after_done/__manifest__.py +++ b/repair_picking_after_done/__manifest__.py @@ -8,10 +8,16 @@ "website": "https://github.com/OCA/repair", "summary": "Transfer repaired move to another location directly from repair order", "category": "Repair", - "depends": ["repair_type", "repair_stock"], + "depends": [ + "base_repair_config", + "repair_type", + "repair_stock", + "repair_type_product_destination", + ], "data": [ "security/ir.model.access.csv", "views/repair.xml", + "views/res_config_settings_views.xml", "wizards/repair_move_transfer_views.xml", ], "installable": True, diff --git a/repair_picking_after_done/models/__init__.py b/repair_picking_after_done/models/__init__.py index 3985e558..e2f26b7f 100644 --- a/repair_picking_after_done/models/__init__.py +++ b/repair_picking_after_done/models/__init__.py @@ -1 +1,2 @@ from . import repair +from . import res_config_settings diff --git a/repair_picking_after_done/models/repair.py b/repair_picking_after_done/models/repair.py index 3a4838c8..f08d2530 100644 --- a/repair_picking_after_done/models/repair.py +++ b/repair_picking_after_done/models/repair.py @@ -1,7 +1,8 @@ # Copyright (C) 2022 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import fields, models +from odoo import _, fields, models +from odoo.exceptions import ValidationError class Repair(models.Model): @@ -38,3 +39,41 @@ def action_transfer_done_moves(self): }, "target": "new", } + + def _get_auto_transfer_value(self): + return ( + self.env["ir.config_parameter"] + .sudo() + .get_param("repair.auto_transfer_repair", default=False) + ) + + def action_validate(self): + auto_transfer = self._get_auto_transfer_value() + + if auto_transfer and not self.product_id: + raise ValidationError( + _( + "Automatic transfer cannot be completed because no product is specified for this repair order. " + "Please ensure that a product is assigned to the repair order before proceeding with the transfer." + ) + ) + + return super().action_validate() + + def action_repair_done(self): + super().action_repair_done() + + auto_transfer = self._get_auto_transfer_value() + if auto_transfer: + for repair in self: + if repair.remaining_quantity > 0: + transfer_wizard = self.env["repair.move.transfer"].create( + { + "repair_order_id": repair.id, + "location_dest_id": repair.product_location_dest_id.id, + "quantity": repair.remaining_quantity, + } + ) + transfer_wizard.action_create_transfer() + repair.picking_ids.button_validate() + return True diff --git a/repair_picking_after_done/models/res_config_settings.py b/repair_picking_after_done/models/res_config_settings.py new file mode 100644 index 00000000..c849794c --- /dev/null +++ b/repair_picking_after_done/models/res_config_settings.py @@ -0,0 +1,15 @@ +# Copyright 2024 Patryk Pyczko (APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + auto_transfer_repair = fields.Boolean( + "Automatic Transfer on Repair Completion", + config_parameter="repair.auto_transfer_repair", + help="Automatically create and validate transfers for " + "repair orders upon completion.", + ) diff --git a/repair_picking_after_done/readme/CONFIGURE.md b/repair_picking_after_done/readme/CONFIGURE.md index 029bb402..acf6ff20 100644 --- a/repair_picking_after_done/readme/CONFIGURE.md +++ b/repair_picking_after_done/readme/CONFIGURE.md @@ -1 +1,6 @@ -No configuration needed for this module. +To enable automatic transfers for repaired products when a repair order is completed: + +- Navigate to Repairs → Configuration → Settings. +- Enable the **Automatic Transfer on Repair Completion** setting. + +When enabled, internal transfers for repaired products are automatically created and validated upon completing the repair order. \ No newline at end of file diff --git a/repair_picking_after_done/readme/DESCRIPTION.md b/repair_picking_after_done/readme/DESCRIPTION.md index c10f2f76..ea678b7a 100644 --- a/repair_picking_after_done/readme/DESCRIPTION.md +++ b/repair_picking_after_done/readme/DESCRIPTION.md @@ -1,2 +1,4 @@ -This module adds the functionality to create transfer of repaired move -once repair order is done. +This module enhances Odoo's repair process by introducing automatic stock transfers for repaired products. + +- **Automatic Transfer:** When a repair order is marked as done, a stock transfer for the remaining repaired products is automatically created and validated if the ***auto_transfer_repair*** parameter is enabled. +- **Manual Transfer:** Users can manually create stock transfers when automatic transfer is disabled. \ No newline at end of file diff --git a/repair_picking_after_done/readme/USAGE.md b/repair_picking_after_done/readme/USAGE.md index 47f06395..682f70f3 100644 --- a/repair_picking_after_done/readme/USAGE.md +++ b/repair_picking_after_done/readme/USAGE.md @@ -1,3 +1,9 @@ -After repair order is done, You will be able to see button "Transfer" on -repair order's form view. You will be able to create internal transfer -between repair location to any destination location. +**Manual Transfers** + +1. After a repair order is marked as **Done**, a **Create Transfer** button will appear on the repair order's form view. +2. Click the Create Transfer button to create an internal transfer for the repaired products. +3. Specify the destination location and quantity to complete the transfer. + +**Automatic Transfers** + +1. If the ***auto_transfer_repair*** configuration parameter is enabled, an internal transfer is automatically created and validated when the repair order is marked as **Done**. \ No newline at end of file diff --git a/repair_picking_after_done/static/description/index.html b/repair_picking_after_done/static/description/index.html index ef3efbac..f2b2e763 100644 --- a/repair_picking_after_done/static/description/index.html +++ b/repair_picking_after_done/static/description/index.html @@ -370,8 +370,16 @@

Repair picking after done

!! source digest: sha256:f11fa65acd2414cbbab2c2c100e3d976b2147ad613787ffc494bc85e0242b0bd !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Alpha License: AGPL-3 OCA/repair Translate me on Weblate Try me on Runboat

-

This module adds the functionality to create transfer of repaired move -once repair order is done.

+

This module enhances Odoo’s repair process by introducing automatic +stock transfers for repaired products.

+

Important

This is an alpha version, the data model and design can change at any time without warning. @@ -395,13 +403,32 @@

Repair picking after done

Configuration

-

No configuration needed for this module.

+

To enable automatic transfers for repaired products when a repair order +is completed:

+ +

When enabled, internal transfers for repaired products are automatically +created and validated upon completing the repair order.

Usage

-

After repair order is done, You will be able to see button “Transfer” on -repair order’s form view. You will be able to create internal transfer -between repair location to any destination location.

+

Manual Transfers

+
    +
  1. After a repair order is marked as Done, a Create Transfer +button will appear on the repair order’s form view.
  2. +
  3. Click the Create Transfer button to create an internal transfer for +the repaired products.
  4. +
  5. Specify the destination location and quantity to complete the +transfer.
  6. +
+

Automatic Transfers

+
    +
  1. If the auto_transfer_repair configuration parameter is enabled, +an internal transfer is automatically created and validated when the +repair order is marked as Done.
  2. +

Known issues / Roadmap

diff --git a/repair_picking_after_done/tests/test_repair_transfers.py b/repair_picking_after_done/tests/test_repair_transfers.py index e6c46411..a7284147 100644 --- a/repair_picking_after_done/tests/test_repair_transfers.py +++ b/repair_picking_after_done/tests/test_repair_transfers.py @@ -61,6 +61,9 @@ def setUpClass(cls): } ) + # Set the repair auto-transfer configuration to disabled (manual transfers) + cls.env["ir.config_parameter"].set_param("repair.auto_transfer_repair", False) + def setUpRepairOrder(self, repair_order): # Validate and set the state of the repair order repair_order.action_validate() @@ -82,22 +85,14 @@ def createTransfer(self, repair_order, quantity): ) transfer_repair_wizard.action_create_transfer() - def test_repair_transfer_1(self): + def test_repair_transfer_manual_1(self): + """Test creating a single manual transfer.""" self.setUpRepairOrder(self.repair_r1) self.createTransfer(self.repair_r1, 1.0) self.assertEqual(len(self.repair_r1.picking_ids), 1) - def test_repair_transfer_2(self): - self.setUpRepairOrder(self.repair_r2) - self.createTransfer(self.repair_r2, 1.0) - self.assertEqual(len(self.repair_r2.picking_ids), 1) - - move_line = self.repair_r2.picking_ids.mapped("move_ids").mapped( - "move_line_ids" - )[0] - self.assertEqual(move_line.lot_id.name, "LOT0001") - - def test_multiple_transfers(self): + def test_repair_transfer_manual_multiple(self): + """Test multiple manual transfers for the repair order.""" self.setUpRepairOrder(self.repair_r1) # Attempt to create a transfer for 0 items. @@ -106,7 +101,7 @@ def test_multiple_transfers(self): ): self.createTransfer(self.repair_r1, 0.0) - # Create the first transfer for 1 item + # Create the first manual transfer for 1 item self.createTransfer(self.repair_r1, 1.0) # Update remaining quantity after first transfer @@ -139,3 +134,10 @@ def test_multiple_transfers(self): self.assertEqual( total_transferred, 3.0, "Total transferred quantity should equal to 3.0" ) + + def test_repair_transfer_automatic(self): + """Test automatic transfer creation upon repair order completion.""" + self.env["ir.config_parameter"].set_param("repair.auto_transfer_repair", True) + self.setUpRepairOrder(self.repair_r2) + self.assertEqual(len(self.repair_r2.picking_ids), 1) + self.assertEqual(self.repair_r2.picking_ids.state, "done") diff --git a/repair_picking_after_done/views/repair.xml b/repair_picking_after_done/views/repair.xml index 040d54a0..a66ce357 100644 --- a/repair_picking_after_done/views/repair.xml +++ b/repair_picking_after_done/views/repair.xml @@ -11,7 +11,7 @@ name="action_transfer_done_moves" string="Create Transfer" type="object" - invisible="state != 'done' or remaining_quantity == 0" + invisible="state != 'done' or remaining_quantity == 0 or not product_id" /> diff --git a/repair_picking_after_done/views/res_config_settings_views.xml b/repair_picking_after_done/views/res_config_settings_views.xml new file mode 100644 index 00000000..38317207 --- /dev/null +++ b/repair_picking_after_done/views/res_config_settings_views.xml @@ -0,0 +1,20 @@ + + + + + res.config.settings.view.form.inherit.repair + res.config.settings + + + + + + + + + + +