Skip to content

Commit

Permalink
[IMP] stock_storage_type: Don't consider quant with quantities <= 0
Browse files Browse the repository at this point in the history
As Odoo does not void directly a quant after a full quant transfer (quant
remains with quantity == 0), consider that quantity when computing the fields
to avoid mixed products or mixed lots
  • Loading branch information
rousseldenis authored and alexandregaldeano committed Jan 17, 2025
1 parent 62cf77d commit d6cc994
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stock_storage_type/models/stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _should_compute_location_is_empty(self):
return self.only_empty

@api.depends(
"quant_ids",
"quant_ids.quantity",
"in_move_ids",
"in_move_line_ids",
"do_not_mix_products",
Expand All @@ -285,14 +285,16 @@ def _compute_location_will_contain_product_ids(self):
rec.location_will_contain_product_ids = no_product
else:
products = (
rec.mapped("quant_ids.product_id")
rec.mapped("quant_ids")
.filtered(lambda q: q.quantity > 0)
.product_id
| rec.mapped("in_move_ids.product_id")
| rec.mapped("in_move_line_ids.product_id")
)
rec.location_will_contain_product_ids = products

@api.depends(
"quant_ids",
"quant_ids.quantity",
"in_move_line_ids",
"do_not_mix_lots",
)
Expand All @@ -302,9 +304,9 @@ def _compute_location_will_contain_lot_ids(self):
no_lot = self.env["stock.lot"].browse()
rec.location_will_contain_lot_ids = no_lot
else:
lots = rec.mapped("quant_ids.lot_id") | rec.mapped(
"in_move_line_ids.lot_id"
)
lots = rec.mapped("quant_ids").filtered(
lambda q: q.quantity > 0
).lot_id | rec.mapped("in_move_line_ids.lot_id")
rec.location_will_contain_lot_ids = lots

@api.depends(
Expand Down
75 changes: 75 additions & 0 deletions stock_storage_type/tests/test_stock_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,42 @@ def test_will_contain_product_ids(self):
self.env["product.product"].browse(),
)

def test_will_contain_product_ids_quantity(self):
"""
Put a product quantity in pallet bin 1 location
Create a move that will void that location
Transfer the quantity
Odoo lets a quant with zero quantity
The location_will_contain_product_ids should be void
"""
location = self.pallets_bin_1_location
location.computed_storage_category_id.allow_new_product = "same"

self._update_qty_in_location(location, self.product, 10)
self.assertEqual(location.location_will_contain_product_ids, self.product)
ml_move = self.env["stock.move"].create(
{
"name": "test",
"product_id": self.product.id,
"location_id": location.id,
"location_dest_id": self.env.ref("stock.stock_location_customers").id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 10,
}
)
ml_move._action_confirm()
ml_move._action_assign()

ml_move.quantity_done = 10.0
ml_move._action_done()
# Odoo lets a zero quantity quant before scheduler do the garbage collector
quant = self.env["stock.quant"].search(
[("product_id", "=", self.product.id), ("location_id", "=", location.id)]
)
self.assertTrue(quant)
self.assertEqual(0.0, quant.quantity)
self.assertFalse(location.location_will_contain_product_ids)

def test_will_contain_lot_ids(self):
location = self.pallets_bin_1_location
location.computed_storage_category_id.allow_new_product = "same_lot"
Expand Down Expand Up @@ -193,6 +229,45 @@ def test_will_contain_lot_ids(self):
self.env["stock.lot"].browse(),
)

def test_will_contain_product_lot_ids_quantity(self):
"""
Put a product quantity lot in pallet bin 1 location
Create a move that will void that location
Transfer the quantity
Odoo lets a quant with zero quantity
The location_will_contain_product_ids should be void
"""
location = self.pallets_bin_1_location
location.computed_storage_category_id.allow_new_product = "same_lot"

lot_values = {"product_id": self.product.id, "company_id": self.env.company.id}
lot1 = self.env["stock.lot"].create(lot_values)

self._update_qty_in_location(location, self.product, 10, lot=lot1)
self.assertEqual(location.location_will_contain_lot_ids, lot1)
ml_move = self.env["stock.move"].create(
{
"name": "test",
"product_id": self.product.id,
"location_id": location.id,
"location_dest_id": self.env.ref("stock.stock_location_customers").id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 10,
}
)
ml_move._action_confirm()
ml_move._action_assign()

ml_move.quantity_done = 10.0
ml_move._action_done()
# Odoo lets a zero quantity quant before scheduler do the garbage collector
quant = self.env["stock.quant"].search(
[("product_id", "=", self.product.id), ("location_id", "=", location.id)]
)
self.assertTrue(quant)
self.assertEqual(0.0, quant.quantity)
self.assertFalse(location.location_will_contain_lot_ids)

def test_location_is_empty_non_internal(self):
location = self.env.ref("stock.stock_location_customers")
# we always consider an non-internal location empty, the put-away
Expand Down

0 comments on commit d6cc994

Please sign in to comment.