[IMP] stock_reserve_rule: Don't evaluate strategies if needed quantity is already taken

This commit is contained in:
Denis Roussel
2024-03-11 15:06:30 +01:00
parent bc363dfae7
commit 2c4bfbfaff
2 changed files with 45 additions and 0 deletions

View File

@@ -98,6 +98,15 @@ class StockMove(models.Model):
strict=strict,
)
still_need -= taken_in_loc
# We should break between quants if original needs is fulfilled
# TODO: Check if float_is_zero should be more appropriate
need_zero = (
float_compare(still_need, 0, precision_rounding=rounding)
!= 1
)
if need_zero:
# useless to eval the other rules when still_need <= 0
break
except StopIteration:
break

View File

@@ -717,3 +717,39 @@ class TestReserveRule(common.TransactionCase):
ml, [{"location_id": self.loc_zone2_bin1.id, "reserved_uom_qty": 80.0}]
)
self.assertEqual(move.state, "assigned")
def test_several_rules_same_loc_negative(self):
"""
We have several rules for the same location
We have two quants in the location with one negative
"""
self.env["stock.quant"].create(
{
"location_id": self.loc_zone1_bin1.id,
"quantity": 10.0,
"product_id": self.product1.id,
}
)
self.env["stock.quant"].create(
{
"location_id": self.loc_zone1_bin1.id,
"quantity": -2.0,
"product_id": self.product1.id,
}
)
picking = self._create_picking(self.wh, [(self.product1, 1.0)])
self._create_rule(
{},
[
{
"location_id": self.loc_zone1_bin1.id,
"removal_strategy": "packaging",
"sequence": 1,
},
{"location_id": self.loc_zone1_bin1.id, "sequence": 2},
],
)
picking.action_assign()