From 4eded5860e99817efdd3e617a216e57a171c63be Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Mon, 14 Feb 2022 12:26:15 +0100 Subject: [PATCH] [FIX] stock_pull_list: do not show any lines when there's no quantity needed --- stock_pull_list/tests/common.py | 13 +++++++++++++ stock_pull_list/tests/test_stock_pull_list.py | 11 +++++++++++ stock_pull_list/wizards/stock_pull_list_wizard.py | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/stock_pull_list/tests/common.py b/stock_pull_list/tests/common.py index fc02af3ed..cb3acdfd2 100644 --- a/stock_pull_list/tests/common.py +++ b/stock_pull_list/tests/common.py @@ -14,6 +14,7 @@ class TestPullListCommon(TransactionCase): self.move_obj = self.env["stock.move"] self.picking_obj = self.env["stock.picking"] self.wiz_obj = self.env["stock.pull.list.wizard"] + self.stock_change_obj = self.env["stock.change.product.qty"] self.company = self.env.ref("base.main_company") self.warehouse = self.env.ref("stock.warehouse0") @@ -79,3 +80,15 @@ class TestPullListCommon(TransactionCase): ) picking.action_confirm() return picking + + def _update_product_qty(self, product, quantity): + """Update Product quantity.""" + change_product_qty = self.stock_change_obj.create( + { + "product_id": product.id, + "product_tmpl_id": product.product_tmpl_id.id, + "new_quantity": quantity, + } + ) + change_product_qty.change_product_qty() + return change_product_qty diff --git a/stock_pull_list/tests/test_stock_pull_list.py b/stock_pull_list/tests/test_stock_pull_list.py index e1198face..68d410382 100644 --- a/stock_pull_list/tests/test_stock_pull_list.py +++ b/stock_pull_list/tests/test_stock_pull_list.py @@ -30,3 +30,14 @@ class TestStockPullList(TestPullListCommon): expected = 50 + 70 self.assertEqual(line.raw_demand_qty, expected) self.assertEqual(line.needed_qty, expected) + + def test_03_no_needed_qty(self): + """Tests that no line is created in the wizard if there's no + quantity needed.""" + quantity = 120.00 + self._update_product_qty(self.product_a, quantity) + self._generate_moves() + wiz = self.wiz_obj.create({"consolidate_by_product": True}) + wiz.action_prepare() + line = wiz.line_ids.filtered(lambda l: l.product_id == self.product_a) + self.assertEqual(len(line), 0) diff --git a/stock_pull_list/wizards/stock_pull_list_wizard.py b/stock_pull_list/wizards/stock_pull_list_wizard.py index 40eb5bf87..a695f3338 100644 --- a/stock_pull_list/wizards/stock_pull_list_wizard.py +++ b/stock_pull_list/wizards/stock_pull_list_wizard.py @@ -169,7 +169,9 @@ class PullListWizard(models.TransientModel): qty_assigned = {} for key, demand_qty in demand_dict.items(): supply_qty = incoming_dict.get(key, 0.0) - lines.append((0, 0, self._prepare_line_values(key, demand_qty, supply_qty))) + line_data = self._prepare_line_values(key, demand_qty, supply_qty) + if line_data["needed_qty"] > 0.0: + lines.append((0, 0, line_data)) self.update({"line_ids": lines}) res = self._act_window_pull_list_step_2() return res