From 04973177097e4597cf0939b415f017e52395df4e Mon Sep 17 00:00:00 2001 From: Patryk Pyczko Date: Wed, 20 Nov 2024 12:15:24 +0100 Subject: [PATCH] [FIX] repair_type: Remove duplicated destination location for added parts and add product destination location --- repair_type/__manifest__.py | 1 + repair_type/i18n/es.po | 54 ++++++--- repair_type/models/__init__.py | 1 + repair_type/models/repair.py | 28 +++++ repair_type/models/stock_move.py | 2 +- repair_type/models/stock_picking_type.py | 29 ++--- repair_type/tests/test_repair_type.py | 114 +++++++++++------- repair_type/views/repair_views.xml | 31 +++++ .../views/stock_picking_type_views.xml | 22 ++-- 9 files changed, 189 insertions(+), 93 deletions(-) create mode 100644 repair_type/models/repair.py create mode 100644 repair_type/views/repair_views.xml diff --git a/repair_type/__manifest__.py b/repair_type/__manifest__.py index fc7c8813..e7d6c639 100644 --- a/repair_type/__manifest__.py +++ b/repair_type/__manifest__.py @@ -10,6 +10,7 @@ "category": "Repair", "depends": ["repair"], "data": [ + "views/repair_views.xml", "views/stock_picking_type_views.xml", ], "installable": True, diff --git a/repair_type/i18n/es.po b/repair_type/i18n/es.po index 8ba5fb00..8c53ae20 100644 --- a/repair_type/i18n/es.po +++ b/repair_type/i18n/es.po @@ -6,25 +6,24 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 17.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-06-27 13:31+0000\n" -"PO-Revision-Date: 2024-06-27 13:31+0000\n" +"POT-Creation-Date: 2024-11-21 09:04+0000\n" +"PO-Revision-Date: 2024-11-21 09:04+0000\n" "Last-Translator: \n" "Language-Team: \n" -"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" -#. module: repair_type -#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_add_location_dest_id -msgid "Default Add Destination Location" -msgstr "" - #. module: repair_type #: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_add_location_src_id msgid "Default Add Source Location" -msgstr "" +msgstr "Ubicación de origen por defecto para añadir" + +#. module: repair_type +#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_product_location_dest_id +msgid "Default Product Destination Location" +msgstr "Ubicación de destino del producto por defecto" #. module: repair_type #: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_recycle_location_src_id @@ -39,7 +38,17 @@ msgstr "Ubicación de origen por defecto para eliminar" #. module: repair_type #: model:ir.model,name:repair_type.model_stock_picking_type msgid "Picking Type" -msgstr "Tipo de recolección" +msgstr "Tipo de albarán" + +#. module: repair_type +#: model:ir.model.fields,field_description:repair_type.field_repair_order__product_location_dest_id +msgid "Product Destination Location" +msgstr "Ubicación de destino del producto" + +#. module: repair_type +#: model:ir.model,name:repair_type.model_repair_order +msgid "Repair Order" +msgstr "Orden de reparación" #. module: repair_type #: model:ir.model,name:repair_type.model_stock_move @@ -47,18 +56,22 @@ msgid "Stock Move" msgstr "Movimiento de stock" #. module: repair_type -#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_dest_id +#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_src_id msgid "" -"This is the default add destination location when you create a repair order " -"with this operation type." +"This is the default add source location when you create a repair order with " +"this operation type." msgstr "" +"Esta es la ubicación de origen por defecto para añadir cuando cree una orden" +" de reparación con este tipo de operación." #. module: repair_type -#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_src_id +#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_product_location_dest_id msgid "" -"This is the default add source location when you create a repair order with " -"this operation type." +"This is the default product destination location when you create a repair " +"order with this operation type." msgstr "" +"Esta es la ubicación de destino del producto por defecto cuando cree una " +"orden de reparación con este tipo de operación." #. module: repair_type #: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_recycle_location_src_id @@ -66,8 +79,8 @@ msgid "" "This is the default recycle source location when you create a repair order " "with this operation type." msgstr "" -"Esta es la ubicación de origen por defecto para el reciclaje cuando cree una " -"orden de reparación con este tipo de operación." +"Esta es la ubicación de origen por defecto para el reciclaje cuando cree una" +" orden de reparación con este tipo de operación." #. module: repair_type #: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_remove_location_src_id @@ -77,3 +90,8 @@ msgid "" msgstr "" "Esta es la ubicación de origen por defecto para eleminar cuando cree una " "orden de reparación con este tipo de operación." + +#. module: repair_type +#: model:ir.model.fields,help:repair_type.field_repair_order__product_location_dest_id +msgid "This is the location where the repaired product will be stored." +msgstr "Esta es la ubicación donde se almacenará el producto reparado." \ No newline at end of file diff --git a/repair_type/models/__init__.py b/repair_type/models/__init__.py index 90f60beb..658423aa 100644 --- a/repair_type/models/__init__.py +++ b/repair_type/models/__init__.py @@ -1,2 +1,3 @@ +from . import repair from . import stock_move from . import stock_picking_type diff --git a/repair_type/models/repair.py b/repair_type/models/repair.py new file mode 100644 index 00000000..85f6245f --- /dev/null +++ b/repair_type/models/repair.py @@ -0,0 +1,28 @@ +# Copyright 2024 Patryk Pyczko (APSL-Nagarro) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class RepairOrder(models.Model): + _inherit = "repair.order" + + product_location_dest_id = fields.Many2one( + "stock.location", + "Product Destination Location", + compute="_compute_product_location_dest_id", + store=True, + readonly=False, + required=True, + precompute=True, + index=True, + check_company=True, + help="This is the location where the repaired product will be stored.", + ) + + @api.depends("picking_type_id") + def _compute_product_location_dest_id(self): + for repair in self: + repair.product_location_dest_id = ( + repair.picking_type_id.default_product_location_dest_id + ) diff --git a/repair_type/models/stock_move.py b/repair_type/models/stock_move.py index 5a4e21ff..dce15de8 100644 --- a/repair_type/models/stock_move.py +++ b/repair_type/models/stock_move.py @@ -16,7 +16,7 @@ def _get_repair_locations(self, repair_line_type, repair_id=False): ): res = ( self.repair_id.picking_type_id.default_add_location_src_id, - self.repair_id.picking_type_id.default_add_location_dest_id, + res[1], ) elif ( repair_line_type == "remove" diff --git a/repair_type/models/stock_picking_type.py b/repair_type/models/stock_picking_type.py index 1692ce40..747abd72 100644 --- a/repair_type/models/stock_picking_type.py +++ b/repair_type/models/stock_picking_type.py @@ -40,16 +40,16 @@ class PickingType(models.Model): help="This is the default add source location when you create a repair " "order with this operation type.", ) - default_add_location_dest_id = fields.Many2one( + default_product_location_dest_id = fields.Many2one( "stock.location", - "Default Add Destination Location", - compute="_compute_default_location_dest_id", + "Default Product Destination Location", + compute="_compute_default_location_src_id", check_company=True, store=True, readonly=False, precompute=True, - help="This is the default add destination location when you create a repair " - "order with this operation type.", + help="This is the default product destination location when you create a " + "repair order with this operation type.", ) @api.depends("code") @@ -59,20 +59,7 @@ def _compute_default_location_src_id(self): stock_location = picking_type.warehouse_id.lot_stock_id if picking_type.code == "repair_operation": picking_type.default_add_location_src_id = stock_location.id - return res - - @api.depends("code") - def _compute_default_location_dest_id(self): - res = super()._compute_default_location_dest_id() - for picking_type in self: - if picking_type.code == "repair_operation": - picking_type.default_add_location_dest_id = ( - picking_type.default_location_dest_id.id - ) - picking_type.default_remove_location_src_id = ( - picking_type.default_location_dest_id.id - ) - picking_type.default_recycle_location_src_id = ( - picking_type.default_location_dest_id.id - ) + picking_type.default_remove_location_src_id = stock_location.id + picking_type.default_recycle_location_src_id = stock_location.id + picking_type.default_product_location_dest_id = stock_location.id return res diff --git a/repair_type/tests/test_repair_type.py b/repair_type/tests/test_repair_type.py index 2e803295..aa235f29 100644 --- a/repair_type/tests/test_repair_type.py +++ b/repair_type/tests/test_repair_type.py @@ -5,68 +5,90 @@ class TestRepairType(TransactionCase): - def test_get_repair_locations_remove(self): - self.env.ref( - "repair.picking_type_warehouse0_repair" - ).default_remove_location_src_id = self.env.ref( - "stock.stock_location_customers" - ) - repair = self.env["repair.order"].create( + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.picking_type = cls.env.ref("repair.picking_type_warehouse0_repair") + cls.product_4 = cls.env.ref("product.product_product_4") + cls.product_3 = cls.env.ref("product.product_product_3") + cls.product_11 = cls.env.ref("product.product_product_11") + cls.uom_unit = cls.env.ref("uom.product_uom_unit") + cls.customer_location = cls.env.ref("stock.stock_location_customers") + + def _create_repair_order( + self, + picking_type_ref, + product_ref, + repair_line_type, + product_qty, + component_ref, + ): + """Helper method to create a repair order.""" + return self.env["repair.order"].create( { - "picking_type_id": self.env.ref( - "repair.picking_type_warehouse0_repair" - ).id, - "product_id": self.env.ref("product.product_product_4").id, - "product_uom": self.env.ref("uom.product_uom_unit").id, + "picking_type_id": picking_type_ref.id, + "product_id": product_ref.id, + "product_uom": self.uom_unit.id, "move_ids": [ ( 0, 0, { - "name": "Remove Component 1", - "repair_line_type": "remove", - "product_id": self.env.ref("product.product_product_3").id, - "product_uom_qty": 3, + "name": f"{repair_line_type.capitalize()} Component", + "repair_line_type": repair_line_type, + "product_id": component_ref.id, + "product_uom_qty": product_qty, }, ) ], } ) + + def _set_default_location(self, location_field, location_ref): + """Helper method to set default locations.""" + self.picking_type[location_field] = location_ref + + def _test_repair_location( + self, repair_line_type, location_field, location_ref, component_ref, product_qty + ): + """Reusable test logic for validating repair locations.""" + self._set_default_location(location_field, location_ref) + repair = self._create_repair_order( + self.picking_type, + self.product_4, + repair_line_type, + product_qty, + component_ref, + ) repair._action_repair_confirm() self.assertEqual( repair.move_ids.move_line_ids.location_id, - self.env.ref("stock.stock_location_customers"), + location_ref, ) - def test_get_repair_locations_recycle(self): - self.env.ref( - "repair.picking_type_warehouse0_repair" - ).default_recycle_location_src_id = self.env.ref( - "stock.stock_location_customers" + def test_get_repair_locations_remove(self): + self._test_repair_location( + repair_line_type="remove", + location_field="default_remove_location_src_id", + location_ref=self.customer_location, + component_ref=self.product_3, + product_qty=3, ) - repair = self.env["repair.order"].create( - { - "picking_type_id": self.env.ref( - "repair.picking_type_warehouse0_repair" - ).id, - "product_id": self.env.ref("product.product_product_4").id, - "product_uom": self.env.ref("uom.product_uom_unit").id, - "move_ids": [ - ( - 0, - 0, - { - "name": "Recycle Component", - "repair_line_type": "recycle", - "product_uom_qty": 3, - "product_id": self.env.ref("product.product_product_11").id, - }, - ) - ], - } + + def test_get_repair_locations_recycle(self): + self._test_repair_location( + repair_line_type="recycle", + location_field="default_recycle_location_src_id", + location_ref=self.customer_location, + component_ref=self.product_11, + product_qty=3, ) - repair._action_repair_confirm() - self.assertEqual( - repair.move_ids.move_line_ids.location_id, - self.env.ref("stock.stock_location_customers"), + + def test_get_repair_locations_add(self): + self._test_repair_location( + repair_line_type="add", + location_field="default_add_location_src_id", + location_ref=self.customer_location, + component_ref=self.product_3, + product_qty=5, ) diff --git a/repair_type/views/repair_views.xml b/repair_type/views/repair_views.xml new file mode 100644 index 00000000..465a7641 --- /dev/null +++ b/repair_type/views/repair_views.xml @@ -0,0 +1,31 @@ + + + + repair.type.repair.order.tree.inherit + repair.order + + + + + + + + + + repair.type.repair.order.form.inherit + repair.order + + + + + + + + diff --git a/repair_type/views/stock_picking_type_views.xml b/repair_type/views/stock_picking_type_views.xml index 2f384711..60d67909 100644 --- a/repair_type/views/stock_picking_type_views.xml +++ b/repair_type/views/stock_picking_type_views.xml @@ -5,21 +5,28 @@ stock.picking.type - + + + + + + + + +