From bc0a7745157b93b41de55b7901f203985a417b0d Mon Sep 17 00:00:00 2001 From: Reyes4711 Date: Thu, 6 Jul 2023 08:41:58 +0200 Subject: [PATCH] [MIG] maintenance_stock: Migration to 14.0 --- maintenance_stock/__manifest__.py | 2 +- .../data/demo_maintenance_stock.xml | 57 +++++++++----- .../models/maintenance_equipment.py | 5 -- .../tests/test_maintenance_stock.py | 74 ++++++------------- .../views/maintenance_request_views.xml | 2 +- .../views/stock_move_line_views.xml | 1 - maintenance_stock/views/stock_move_views.xml | 3 +- .../views/stock_picking_views.xml | 2 +- 8 files changed, 65 insertions(+), 81 deletions(-) diff --git a/maintenance_stock/__manifest__.py b/maintenance_stock/__manifest__.py index 5c4327a83..52ce7634e 100644 --- a/maintenance_stock/__manifest__.py +++ b/maintenance_stock/__manifest__.py @@ -5,7 +5,7 @@ "summary": "Links maintenance requests to stock", "author": "Odoo Community Association (OCA), Solvos", "license": "AGPL-3", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "category": "Warehouse", "website": "https://github.com/OCA/maintenance", "depends": ["base_maintenance", "stock"], diff --git a/maintenance_stock/data/demo_maintenance_stock.xml b/maintenance_stock/data/demo_maintenance_stock.xml index 3a27934cf..127fb7572 100644 --- a/maintenance_stock/data/demo_maintenance_stock.xml +++ b/maintenance_stock/data/demo_maintenance_stock.xml @@ -1,11 +1,15 @@ + + Inventory adjustment + inventory + Maintenance Warehouse - + Main @@ -37,18 +41,22 @@ 70.0 - + + Inventory for Toner - product - + + @@ -58,7 +66,13 @@ 50.0 - + + + + @@ -82,12 +97,13 @@ 7 - - + + + + + 1.0 + + @@ -126,8 +137,14 @@ obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]" /> - - + + + + ) # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html import odoo.tests.common as test_common +from odoo.tests.common import Form class TestMaintenanceStock(test_common.TransactionCase): def setUp(self): super().setUp() - self.maintenance_warehouse = self.env["stock.warehouse"].create( { "name": "Test warehouse", @@ -28,6 +28,7 @@ def setUp(self): { "name": "Test equipment", "allow_consumptions": True, + "equipment_assign_to": "employee", "default_consumption_warehouse_id": self.maintenance_warehouse.id, } ) @@ -107,54 +108,26 @@ def test_request(self): def test_picking(self): self.assertEqual(len(self.request_1.stock_picking_ids), 0) - self.assertEqual(len(self.equipment_1.stock_picking_ids), 0) - - qty_done = 5.0 - location_id = self.maintenance_warehouse.lot_stock_id.id - location_dest_id = self.maintenance_warehouse.wh_cons_loc_id.id - picking_type_id = self.maintenance_warehouse.cons_type_id.id - picking = self.env["stock.picking"].create( + location_id = self.maintenance_warehouse.lot_stock_id + location_dest_id = self.maintenance_warehouse.wh_cons_loc_id + picking_type_id = self.maintenance_warehouse.cons_type_id + self.env["stock.quant"].create( { - "maintenance_request_id": self.request_1.id, - "picking_type_id": picking_type_id, - "location_id": location_id, - "location_dest_id": location_dest_id, - "move_lines": [ - ( - 0, - 0, - { - "name": "Test move", - "product_id": self.product1.id, - "product_uom": self.env.ref("uom.product_uom_unit").id, - "product_uom_qty": 5.0, - "picking_type_id": picking_type_id, - "location_id": location_id, - "location_dest_id": location_dest_id, - "move_line_ids": [ - ( - 0, - 0, - { - "product_id": self.product1.id, - "product_uom_id": self.env.ref( - "uom.product_uom_unit" - ).id, - "qty_done": qty_done, - "location_id": location_id, - "location_dest_id": location_dest_id, - }, - ) - ], - }, - ) - ], + "product_id": self.product1.id, + "location_id": location_id.id, + "quantity": 5, } ) - + picking_form = Form(self.env["stock.picking"]) + picking_form.picking_type_id = picking_type_id + picking_form.location_id = location_id + picking_form.location_dest_id = location_dest_id + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.product1 + move.product_uom_qty = 5.0 + picking = picking_form.save() + picking.write({"maintenance_request_id": self.request_1.id}) self.assertEqual(len(self.request_1.stock_picking_ids), 1) - self.assertEqual(len(self.equipment_1.stock_picking_ids), 1) - stock_quant_obj = self.env["stock.quant"] domain_from = [ ("product_id", "=", self.product1.id), @@ -164,11 +137,12 @@ def test_picking(self): ("product_id", "=", self.product1.id), ("location_id", "=", self.maintenance_warehouse.wh_cons_loc_id.id), ] - self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0) + self.assertEqual(stock_quant_obj.search(domain_from).quantity, 5) self.assertEqual(stock_quant_obj.search(domain_to).quantity, 0) picking.action_confirm() - picking.action_done() - - self.assertEqual(stock_quant_obj.search(domain_from).quantity, -qty_done) - self.assertEqual(stock_quant_obj.search(domain_to).quantity, qty_done) + picking.action_assign() + picking.move_line_ids.write({"qty_done": 5.0}) + picking.button_validate() + self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0) + self.assertEqual(stock_quant_obj.search(domain_to).quantity, 5) diff --git a/maintenance_stock/views/maintenance_request_views.xml b/maintenance_stock/views/maintenance_request_views.xml index 0185b1f02..9e799be68 100644 --- a/maintenance_stock/views/maintenance_request_views.xml +++ b/maintenance_stock/views/maintenance_request_views.xml @@ -6,7 +6,7 @@ - + Product Moves stock.move.line ir.actions.act_window - form tree,kanban,pivot,form [('maintenance_request_id', '!=', False)] diff --git a/maintenance_stock/views/stock_move_views.xml b/maintenance_stock/views/stock_move_views.xml index d5d77deb3..07b2f5511 100644 --- a/maintenance_stock/views/stock_move_views.xml +++ b/maintenance_stock/views/stock_move_views.xml @@ -49,12 +49,11 @@ - Stock Moves stock.move ir.actions.act_window - form + form [('maintenance_request_id', '!=', False)] diff --git a/maintenance_stock/views/stock_picking_views.xml b/maintenance_stock/views/stock_picking_views.xml index af697826d..5a482bc61 100644 --- a/maintenance_stock/views/stock_picking_views.xml +++ b/maintenance_stock/views/stock_picking_views.xml @@ -5,7 +5,7 @@ stock.picking - +