diff --git a/stock_reserve_rule/models/stock_move.py b/stock_reserve_rule/models/stock_move.py index 671cbb105..34902032f 100644 --- a/stock_reserve_rule/models/stock_move.py +++ b/stock_reserve_rule/models/stock_move.py @@ -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 diff --git a/stock_reserve_rule/tests/test_reserve_rule.py b/stock_reserve_rule/tests/test_reserve_rule.py index 721b8236b..7047db89f 100644 --- a/stock_reserve_rule/tests/test_reserve_rule.py +++ b/stock_reserve_rule/tests/test_reserve_rule.py @@ -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()