diff --git a/maintenance_stock/__manifest__.py b/maintenance_stock/__manifest__.py index 30781626e..9dfee2e04 100644 --- a/maintenance_stock/__manifest__.py +++ b/maintenance_stock/__manifest__.py @@ -5,10 +5,13 @@ "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",], + "depends": [ + "base_maintenance", + "stock", + ], "data": [ "views/maintenance_equipment_views.xml", "views/maintenance_request_views.xml", @@ -16,7 +19,9 @@ "views/stock_move_line_views.xml", "views/stock_picking_views.xml", ], - "demo": ["data/demo_maintenance_stock.xml",], + "demo": [ + "data/demo_maintenance_stock.xml", + ], "post_init_hook": "post_init_hook", "installable": True, } diff --git a/maintenance_stock/data/demo_maintenance_stock.xml b/maintenance_stock/data/demo_maintenance_stock.xml index 2d576d1d1..9848978a7 100644 --- a/maintenance_stock/data/demo_maintenance_stock.xml +++ b/maintenance_stock/data/demo_maintenance_stock.xml @@ -1,11 +1,17 @@ + + Inventory adjustment + inventory + Maintenance Warehouse Main + one_step + one_step @@ -37,18 +43,20 @@ + Inventory for Toner + @@ -58,8 +66,14 @@ 50.0 - - + + + + @@ -81,6 +95,7 @@ name="default_consumption_warehouse_id" ref="maintenance_stock.stock_warehouse_maintenance" /> + @@ -90,12 +105,13 @@ 7 - - + + + + + 1.0 + + @@ -134,8 +145,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", "code": "TEST",} - {"name": "Test warehouse", "code": "TEST"} { "name": "Test warehouse", "code": "TEST", @@ -30,6 +28,7 @@ def setUp(self): { "name": "Test equipment", "allow_consumptions": True, + "equipment_assign_to": "employee", "default_consumption_warehouse_id": self.maintenance_warehouse.id, } ) @@ -109,61 +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 - move_line_data = { - "product_id": self.product1.id, - "product_uom_id": self.env.ref("uom.product_uom_unit").id, - "qty_done": qty_done, - "location_id": self.maintenance_warehouse.lot_stock_id.id, - "location_dest_id": self.maintenance_warehouse.wh_cons_loc_id.id, - } - 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), @@ -173,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 3bdcb8e28..07b2f5511 100644 --- a/maintenance_stock/views/stock_move_views.xml +++ b/maintenance_stock/views/stock_move_views.xml @@ -49,11 +49,11 @@ - Stock Moves stock.move ir.actions.act_window + 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 - +