From afc6f030234dd38406523aa6ac959c9aaf9d9d7f Mon Sep 17 00:00:00 2001 From: Patryk Pyczko Date: Mon, 2 Dec 2024 09:45:31 +0100 Subject: [PATCH] [IMP] repair_picking_after_done: Implement auto-transfer functionality for completed repair orders --- repair_picking_after_done/README.rst | 37 +++- repair_picking_after_done/__manifest__.py | 8 +- repair_picking_after_done/i18n/ca.po | 158 ++++++++++++++++++ repair_picking_after_done/i18n/es.po | 158 ++++++++++++++++++ repair_picking_after_done/models/__init__.py | 1 + repair_picking_after_done/models/repair.py | 43 ++++- .../models/res_config_settings.py | 15 ++ repair_picking_after_done/readme/CONFIGURE.md | 7 +- .../readme/DESCRIPTION.md | 6 +- repair_picking_after_done/readme/USAGE.md | 12 +- .../static/description/index.html | 39 ++++- .../tests/test_repair_transfers.py | 28 ++-- repair_picking_after_done/views/repair.xml | 2 +- .../views/res_config_settings_views.xml | 20 +++ 14 files changed, 500 insertions(+), 34 deletions(-) create mode 100644 repair_picking_after_done/i18n/ca.po create mode 100644 repair_picking_after_done/i18n/es.po create mode 100644 repair_picking_after_done/models/res_config_settings.py create mode 100644 repair_picking_after_done/views/res_config_settings_views.xml 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/i18n/ca.po b/repair_picking_after_done/i18n/ca.po new file mode 100644 index 00000000..a9df69fa --- /dev/null +++ b/repair_picking_after_done/i18n/ca.po @@ -0,0 +1,158 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * repair_picking_after_done +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-11 13:39+0000\n" +"PO-Revision-Date: 2024-12-11 13:39+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: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_res_config_settings__auto_transfer_repair +msgid "Automatic Transfer on Repair Completion" +msgstr "Transferència Automàtica en Compleció de Reparació" + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/models/repair.py:0 +#, python-format +msgid "" +"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." +msgstr "" +"La transferència automàtica no es pot completar perquè no s'ha especificat un producte per " +"aquesta ordre de reparació. Assegureu-vos que s'hagi assignat un producte a l'ordre de reparació " +"abans de continuar amb la transferència." + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.res_config_settings_view_form_inherit +msgid "" +"Automatically create and validate stock transfers for completed repair " +"orders." +msgstr "Crear i validar automàticament les transferències d'estoc per a ordres de reparació completes." + +#. module: repair_picking_after_done +#: model:ir.model.fields,help:repair_picking_after_done.field_res_config_settings__auto_transfer_repair +msgid "" +"Automatically create and validate transfers for repair orders upon " +"completion." +msgstr "Crear i validar automàticament les transferències per a les ordres de reparació en completar-les." + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Cancel" +msgstr "Cancel·lar" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_res_config_settings +msgid "Config Settings" +msgstr "Paràmetres de configuració" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.repair_type_form_inherit +msgid "Create Transfer" +msgstr "Crear Transferència" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_repair_move_transfer +msgid "Create an internal transfer from repaired moves" +msgstr "Crear una transferència interna a partir dels moviments reparats" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Create transfer" +msgstr "Crear transferència" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__create_uid +msgid "Created by" +msgstr "Creat per" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__create_date +msgid "Created on" +msgstr "Creat el" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__location_dest_id +msgid "Destination location" +msgstr "Ubicació de destí" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__display_name +msgid "Display Name" +msgstr "Nom a mostrar" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__id +msgid "ID" +msgstr "ID" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__write_uid +msgid "Last Updated by" +msgstr "Última actualització per" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__write_date +msgid "Last Updated on" +msgstr "Última actualització el" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__quantity +msgid "Quantity to transfer" +msgstr "Quantitat a transferir" + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#, python-format +msgid "" +"Quantity to transfer cannot exceed the remaining quantity in the repair " +"order." +msgstr "" +"La quantitat a transferir no pot excedir la quantitat restant en l'ordre de reparació." + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#, python-format +msgid "Quantity to transfer must be greater than 0." +msgstr "La quantitat a transferir ha de ser superior a 0." + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__remaining_quantity +msgid "Remaining Quantity to Transfer" +msgstr "Quantitat restant a transferir" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_order__remaining_quantity +msgid "Remaining quantity to be transferred" +msgstr "Quantitat restant per transferir" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_repair_order +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__repair_order_id +msgid "Repair Order" +msgstr "Ordre de reparació" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Transfer Repaired Moves" +msgstr "Transferir moviments reparats" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "or" +msgstr "o" diff --git a/repair_picking_after_done/i18n/es.po b/repair_picking_after_done/i18n/es.po new file mode 100644 index 00000000..16869daa --- /dev/null +++ b/repair_picking_after_done/i18n/es.po @@ -0,0 +1,158 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * repair_picking_after_done +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-11 13:38+0000\n" +"PO-Revision-Date: 2024-12-11 13:38+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: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_res_config_settings__auto_transfer_repair +msgid "Automatic Transfer on Repair Completion" +msgstr "Transferencia automática al completar la reparación" + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/models/repair.py:0 +#, python-format +msgid "" +"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." +msgstr "" +"No se puede completar la transferencia automática porque no se ha especificado un producto para " +"esta orden de reparación. Asegúrese de que un producto esté asignado a la orden de reparación antes " +"de proceder con la transferencia." + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.res_config_settings_view_form_inherit +msgid "" +"Automatically create and validate stock transfers for completed repair " +"orders." +msgstr "Crear y validar automáticamente transferencias de stock para órdenes de reparación completadas." + +#. module: repair_picking_after_done +#: model:ir.model.fields,help:repair_picking_after_done.field_res_config_settings__auto_transfer_repair +msgid "" +"Automatically create and validate transfers for repair orders upon " +"completion." +msgstr "Crear y validar automáticamente transferencias para órdenes de reparación al completarlas." + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Cancel" +msgstr "Cancelar" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_res_config_settings +msgid "Config Settings" +msgstr "Ajustes de configuración" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.repair_type_form_inherit +msgid "Create Transfer" +msgstr "Crear Transferencia" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_repair_move_transfer +msgid "Create an internal transfer from repaired moves" +msgstr "Crear una transferencia interna a partir de los movimientos reparados" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Create transfer" +msgstr "Crear transferencia" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__location_dest_id +msgid "Destination location" +msgstr "Ubicación de destino" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__display_name +msgid "Display Name" +msgstr "Nombre para mostrar" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__id +msgid "ID" +msgstr "ID" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__quantity +msgid "Quantity to transfer" +msgstr "Cantidad a transferir" + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#, python-format +msgid "" +"Quantity to transfer cannot exceed the remaining quantity in the repair " +"order." +msgstr "" +"La cantidad a transferir no puede exceder la cantidad restante en la orden de reparación." + +#. module: repair_picking_after_done +#. odoo-python +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#: code:addons/repair_picking_after_done/wizards/repair_move_transfer.py:0 +#, python-format +msgid "Quantity to transfer must be greater than 0." +msgstr "La cantidad a transferir debe ser mayor que 0." + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__remaining_quantity +msgid "Remaining Quantity to Transfer" +msgstr "Cantidad restante a transferir" + +#. module: repair_picking_after_done +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_order__remaining_quantity +msgid "Remaining quantity to be transferred" +msgstr "Cantidad restante por transferir" + +#. module: repair_picking_after_done +#: model:ir.model,name:repair_picking_after_done.model_repair_order +#: model:ir.model.fields,field_description:repair_picking_after_done.field_repair_move_transfer__repair_order_id +msgid "Repair Order" +msgstr "Orden de reparación" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "Transfer Repaired Moves" +msgstr "Transferir movimientos reparados" + +#. module: repair_picking_after_done +#: model_terms:ir.ui.view,arch_db:repair_picking_after_done.view_repair_move_transfer_wizard +msgid "or" +msgstr "o" 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..4c569140 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,43 @@ 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:

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