mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -57,7 +57,7 @@ class ProductProduct(models.Model):
|
||||
component_needs = product._get_components_needs(exploded_components)
|
||||
if not component_needs:
|
||||
# The BoM has no line we can use
|
||||
potential_qty = immediately_usable_qty = 0.0
|
||||
potential_qty = 0.0
|
||||
else:
|
||||
# Find the lowest quantity we can make with the stock at hand
|
||||
components_potential_qty = min(
|
||||
@@ -79,8 +79,7 @@ class ProductProduct(models.Model):
|
||||
)
|
||||
|
||||
res[product.id]["potential_qty"] = potential_qty
|
||||
immediately_usable_qty = potential_qty if bom_id.type != "phantom" else 0
|
||||
res[product.id]["immediately_usable_qty"] += immediately_usable_qty
|
||||
res[product.id]["immediately_usable_qty"] = potential_qty
|
||||
|
||||
return res, stock_dict
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user