From 1562016235385d69fbe6422658e29bd96dcfcdc3 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 23 Feb 2022 19:19:34 +0100 Subject: [PATCH] [TESTS] stock_available_mrp: Add test for phantom bom --- .../tests/test_potential_qty.py | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/stock_available_mrp/tests/test_potential_qty.py b/stock_available_mrp/tests/test_potential_qty.py index 917926579..804472f07 100644 --- a/stock_available_mrp/tests/test_potential_qty.py +++ b/stock_available_mrp/tests/test_potential_qty.py @@ -404,3 +404,77 @@ class TestPotentialQty(SavepointCase): {p1.id: 3.0, p2.id: 3.0, p3.id: 0.0}, {p.id: p.potential_qty for p in products}, ) + + def test_product_phantom(self): + # Create a BOM product with 2 components + # Set stock quantity for the first one == 0.0 + # Set stock quantity for the second one == 1.0 + # Create an incoming movement for the first component + # The immediately available quantity should stay == 0.0 + uom_unit = self.env.ref("uom.product_uom_unit") + uom_unit.rounding = 1.0 + product = self.product_model.create( + { + "name": "Test product with BOM", + "type": "product", + "uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + bom = self.bom_model.create( + { + "product_tmpl_id": product.product_tmpl_id.id, + "product_id": product.id, + "type": "phantom", + } + ) + + bom_product = self.product_model.create( + { + "name": "BOM product", + "type": "product", + "uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + + self.bom_line_model.create( + { + "bom_id": bom.id, + "product_id": bom_product.id, + "product_qty": 1, + "product_uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + + bom_product_2 = self.product_model.create( + { + "name": "BOM product 2", + "type": "product", + "uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + + self.bom_line_model.create( + { + "bom_id": bom.id, + "product_id": bom_product_2.id, + "product_qty": 1, + "product_uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + self.create_inventory(bom_product_2.id, 1) + + move_in = self.env["stock.move"].create( + { + "name": bom_product.name, + "location_id": self.env.ref("stock.stock_location_suppliers").id, + "location_dest_id": self.env.ref("stock.stock_location_stock").id, + "product_id": bom_product.id, + "product_uom_qty": 1.0, + "product_uom": self.env.ref("uom.product_uom_unit").id, + } + ) + + move_in._action_confirm() + product.invalidate_cache() + + self.assertEqual(product.immediately_usable_qty, 0.0)