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..15352810f 100644 --- a/maintenance_stock/data/demo_maintenance_stock.xml +++ b/maintenance_stock/data/demo_maintenance_stock.xml @@ -1,147 +1,150 @@ - - + + + Inventory adjustment + inventory - - Maintenance Warehouse - - Main - + + + Maintenance Warehouse + + Main + one_step + ship_only + - - - + + + - - TON_1234 - Toner - product - - 100.0 - 70.0 - - - - + + TON_1234 + Toner + product + + 100.0 + 70.0 + + + - - Inventory for Toner - - + - - - - - 50.0 - - + + Inventory for Toner + - - - + - - - + + + + + 50.0 + + + + + + + + - - - - + + + - - Change toner - - - - 7 - - - + - - - - - - - - + + Change toner + + + + 7 + - - - + + + + + 1.0 + + + + + + + - - - + + + + + + + + + + + + diff --git a/maintenance_stock/models/maintenance_equipment.py b/maintenance_stock/models/maintenance_equipment.py index 53afaa7a5..c6f5ba43d 100644 --- a/maintenance_stock/models/maintenance_equipment.py +++ b/maintenance_stock/models/maintenance_equipment.py @@ -6,11 +6,6 @@ class MaintenanceEquipment(models.Model): _inherit = "maintenance.equipment" - stock_picking_ids = fields.One2many( - comodel_name="stock.picking", - inverse_name="maintenance_equipment_id", - groups="stock.group_stock_user", - ) allow_consumptions = fields.Boolean( groups="stock.group_stock_user", ) @@ -27,7 +22,9 @@ def _onchange_allow_consumptions(self): def action_view_stock_picking_ids(self): self.ensure_one() - action = self.env.ref("stock.action_picking_tree_all").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.action_picking_tree_all" + ) action["domain"] = [("maintenance_equipment_id", "=", self.id)] action["context"] = { "show_maintenance_request_id": True, @@ -36,13 +33,17 @@ def action_view_stock_picking_ids(self): def action_view_stock_move_ids(self): self.ensure_one() - action = self.env.ref("stock.stock_move_action").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.stock_move_action" + ) action["domain"] = [("maintenance_equipment_id", "=", self.id)] return action def action_view_stock_move_line_ids(self): self.ensure_one() - action = self.env.ref("stock.stock_move_line_action").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.stock_move_line_action" + ) action["domain"] = [("maintenance_equipment_id", "=", self.id)] # TODO Grouping by destination allows separating consumptions diff --git a/maintenance_stock/models/maintenance_request.py b/maintenance_stock/models/maintenance_request.py index ad15702f0..79848e4cf 100644 --- a/maintenance_stock/models/maintenance_request.py +++ b/maintenance_stock/models/maintenance_request.py @@ -24,7 +24,9 @@ class MaintenanceRequest(models.Model): def action_view_stock_picking_ids(self): self.ensure_one() - action = self.env.ref("stock.stock_picking_action_picking_type").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.stock_picking_action_picking_type" + ) action["domain"] = [("maintenance_request_id", "=", self.id)] action["context"] = { "default_picking_type_id": self.default_consumption_warehouse_id.cons_type_id.id, @@ -34,13 +36,17 @@ def action_view_stock_picking_ids(self): def action_view_stock_move_ids(self): self.ensure_one() - action = self.env.ref("stock.stock_move_action").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.stock_move_action" + ) action["domain"] = [("maintenance_request_id", "=", self.id)] return action def action_view_stock_move_line_ids(self): self.ensure_one() - action = self.env.ref("stock.stock_move_line_action").read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "stock.stock_move_line_action" + ) action["domain"] = [("maintenance_request_id", "=", self.id)] # TODO Grouping by destination allows separating consumptions diff --git a/maintenance_stock/models/stock_warehouse.py b/maintenance_stock/models/stock_warehouse.py index 37d36155d..287b65779 100644 --- a/maintenance_stock/models/stock_warehouse.py +++ b/maintenance_stock/models/stock_warehouse.py @@ -20,7 +20,9 @@ def _create_or_update_sequences_and_picking_types(self): # solved with a hook if "cons_type_id" in warehouse_data: PickingType.browse(warehouse_data["cons_type_id"]).write( - {"return_picking_type_id": warehouse_data.get("in_type_id", False),} + { + "return_picking_type_id": warehouse_data.get("in_type_id", False), + } ) return warehouse_data @@ -41,8 +43,9 @@ def _get_picking_type_create_values(self, max_sequence): "use_existing_lots": True, "default_location_src_id": self.lot_stock_id.id, "default_location_dest_id": self.wh_cons_loc_id.id, - "sequence": max_sequence_new, + "sequence_code": max_sequence_new, "barcode": self.code.replace(" ", "").upper() + "-CONS", + "company_id": self.company_id.id or self.env.company.id, }, }, max_sequence_new + 1, @@ -64,8 +67,8 @@ def _get_sequence_values(self): }, } - def _get_locations_values(self, vals): - sub_locations = super()._get_locations_values(vals) + def _get_locations_values(self, vals, code=False): + sub_locations = super()._get_locations_values(vals, code) code = vals.get("code") or self.code code = code.replace(" ", "").upper() company_id = vals.get("company_id", self.company_id.id) diff --git a/maintenance_stock/tests/test_maintenance_stock.py b/maintenance_stock/tests/test_maintenance_stock.py index 1e3707b21..3e8e5f3dc 100644 --- a/maintenance_stock/tests/test_maintenance_stock.py +++ b/maintenance_stock/tests/test_maintenance_stock.py @@ -1,15 +1,13 @@ # © 2020 Solvos Consultoría Informática () # 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 - +