From a270811d3c5bb2d05abd5f80ee97a4c91d14f64c Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Tue, 5 Nov 2024 17:02:53 +0100 Subject: [PATCH 1/3] [IMP] stock_inventory_verification_request: compute involved lines and quants --- .../models/stock_slot_verification_request.py | 43 +++++---- .../tests/test_verification_request.py | 88 +++++++++++++++---- 2 files changed, 97 insertions(+), 34 deletions(-) diff --git a/stock_inventory_verification_request/models/stock_slot_verification_request.py b/stock_inventory_verification_request/models/stock_slot_verification_request.py index 33af4c0d3af0..64666b5309f3 100644 --- a/stock_inventory_verification_request/models/stock_slot_verification_request.py +++ b/stock_inventory_verification_request/models/stock_slot_verification_request.py @@ -100,6 +100,8 @@ def _compute_created_inventory_count(self): column1="slot_verification_request_id", column2="move_line_id", string="Involved Stock Moves", + compute="_compute_involved_move_lines", + store=False, ) involved_move_line_count = fields.Integer( compute="_compute_involved_move_line_count" @@ -110,6 +112,8 @@ def _compute_created_inventory_count(self): column1="slot_verification_request_id", column2="quant_id", string="Involved Inventory Quants", + compute="_compute_involved_quants", + store=False, ) involved_quant_count = fields.Integer(compute="_compute_involved_quant_count") created_inventory_ids = fields.One2many( @@ -120,6 +124,29 @@ def _compute_created_inventory_count(self): ) created_inventory_count = fields.Integer(compute="_compute_created_inventory_count") + @api.depends("location_id", "product_id", "lot_id", "state") + def _compute_involved_move_lines(self): + for rec in self: + # Only compute when state is 'open' to prevent irrelevant data accumulation. + # No need to accumulate movements for a 'solved' or 'cancelled' + # SVR a lot of time after resolution. + if rec.state == "open": + rec.involved_move_line_ids = self.env["stock.move.line"].search( + rec._get_involved_move_lines_domain() + ) + else: + rec.involved_move_line_ids = self.env["stock.move.line"] + + @api.depends("location_id", "product_id", "lot_id", "state") + def _compute_involved_quants(self): + for rec in self: + if rec.state == "open": + rec.involved_quant_ids = self.env["stock.quant"].search( + rec._get_involved_quants_domain() + ) + else: + rec.involved_quant_ids = self.env["stock.quant"] + def _get_involved_move_lines_domain(self): domain = [ "|", @@ -140,24 +167,8 @@ def _get_involved_quants_domain(self): domain.append(("lot_id", "=", self.lot_id.id)) return domain - def _get_involved_quants_and_locations(self): - involved_move_lines = self.env["stock.move.line"].search( - self._get_involved_move_lines_domain() - ) - involved_quants = self.env["stock.quant"].search( - self._get_involved_quants_domain() - ) - return involved_move_lines, involved_quants - def action_confirm(self): self.write({"state": "open"}) - for rec in self: - ( - involved_moves_lines, - involved_quants, - ) = rec._get_involved_quants_and_locations() - rec.involved_move_line_ids = involved_moves_lines - rec.involved_quant_ids = involved_quants return True def action_cancel(self): diff --git a/stock_inventory_verification_request/tests/test_verification_request.py b/stock_inventory_verification_request/tests/test_verification_request.py index ea96633c9c83..3df17dbea79e 100644 --- a/stock_inventory_verification_request/tests/test_verification_request.py +++ b/stock_inventory_verification_request/tests/test_verification_request.py @@ -76,7 +76,7 @@ def setUp(self): } ).action_apply_inventory() - def test_svr_creation(self): + def test_01_svr_creation(self): """Tests the creation of Slot Verification Requests.""" inventory = self.obj_inventory.create( { @@ -104,7 +104,7 @@ def test_svr_creation(self): for quant in inventory.stock_quant_ids: quant.action_open_svr() - def test_svr_workflow(self): + def test_02_svr_workflow(self): """Tests workflow of Slot Verification Request.""" test_svr = self.env["stock.slot.verification.request"].create( { @@ -135,7 +135,7 @@ def test_svr_workflow(self): "Slot Verification Request not marked as cancelled.", ) - def test_view_methods(self): + def test_03_view_methods(self): """Tests the methods used to handle de UI.""" test_svr = self.env["stock.slot.verification.request"].create( { @@ -152,7 +152,7 @@ def test_view_methods(self): test_svr.action_view_move_lines() test_svr.action_view_quants() - def test_svr_full_workflow(self): + def test_04_svr_full_workflow(self): test_svr = self.env["stock.slot.verification.request"].create( { "location_id": self.test_loc.id, @@ -182,7 +182,7 @@ def test_svr_full_workflow(self): "Slot Verification Request not marked as cancelled.", ) - def test_user_permissions_on_svr(self): + def test_05_user_permissions_on_svr(self): """Tests that users without the correct permissions cannot change SVR state.""" test_svr = self.env["stock.slot.verification.request"].create( { @@ -197,17 +197,69 @@ def test_user_permissions_on_svr(self): with self.assertRaises(AccessError): test_svr.with_user(self.user).action_solved() + def test_06_action_view_methods(self): + """Tests the view methods in Slot Verification Request.""" + svr = self.obj_svr.create( + { + "location_id": self.test_loc.id, + "state": "wait", + "product_id": self.product1.id, + } + ) + svr.action_view_move_lines() + svr.action_view_quants() + svr.action_create_inventory_adjustment() + svr.action_view_inventories() + + def test_07_involved_move_lines_compute(self): + move = self.obj_move.create( + { + "name": "Test Move", + "product_id": self.product1.id, + "product_uom_qty": 10, + "product_uom": self.product1.uom_id.id, + "location_id": self.test_loc.id, + "location_dest_id": self.test_loc.id, + } + ) + move._action_confirm() + move._action_assign() + move_line = move.move_line_ids[0] + test_svr = self.obj_svr.create( + { + "location_id": self.test_loc.id, + "state": "wait", + "product_id": self.product1.id, + } + ) + test_svr.action_confirm() + self.assertEqual( + test_svr.state, "open", "Slot Verification Request not confirmed properly." + ) + self.assertIn( + move_line, + test_svr.involved_move_line_ids, + "Move line not found in involved_move_line_ids", + ) -def test_action_view_methods(self): - """Tests the view methods in Slot Verification Request.""" - svr = self.obj_svr.create( - { - "location_id": self.test_loc.id, - "state": "wait", - "product_id": self.product1.id, - } - ) - svr.action_view_move_lines() - svr.action_view_quants() - svr.action_create_inventory_adjustment() - svr.action_view_inventories() + def test_08_involved_quants_compute(self): + self.quant3 = self.env["stock.quant"].create( + { + "location_id": self.test_loc.id, + "product_id": self.product1.id, + "quantity": 20.0, + } + ) + test_svr = self.obj_svr.create( + { + "location_id": self.test_loc.id, + "state": "wait", + "product_id": self.product1.id, + } + ) + test_svr.action_confirm() + self.assertIn( + self.quant3, + test_svr.involved_quant_ids, + "Quant3 not found in involved_quant_ids", + ) From da32bfa011a6c1a30f8f81f5c965dfebff476e18 Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Tue, 12 Nov 2024 12:45:25 +0100 Subject: [PATCH 2/3] [IMP] stock_inventory_verification_request: do not show related inventory adjustments button if created_inventory_count is zero --- .../views/stock_slot_verification_request_view.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml b/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml index 2dfd7575bbb3..49159ffaaa8c 100644 --- a/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml +++ b/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml @@ -71,6 +71,7 @@ type="object" class="oe_stat_button" icon="fa-building-o" + attrs="{'invisible':[('created_inventory_count', '=', 0)]}" > Date: Tue, 12 Nov 2024 14:03:44 +0100 Subject: [PATCH 3/3] [IMP] aust_stock_inventory_verification_request: show lot_id for stock.group_production_lot group --- .../views/stock_slot_verification_request_view.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml b/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml index 49159ffaaa8c..afdbd0186ad7 100644 --- a/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml +++ b/stock_inventory_verification_request/views/stock_slot_verification_request_view.xml @@ -11,6 +11,7 @@ + @@ -120,7 +121,7 @@ - +