From e591d33805d2f62c7b40650c47508e8d1e91d049 Mon Sep 17 00:00:00 2001 From: geomer198 Date: Tue, 3 Oct 2023 22:39:07 +0400 Subject: [PATCH] [IMP] stock_reserve_rule: Tests for tolerance is added. --- stock_reserve_rule/tests/test_reserve_rule.py | 95 ++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/stock_reserve_rule/tests/test_reserve_rule.py b/stock_reserve_rule/tests/test_reserve_rule.py index f8419e5d91f..21c89bdad0e 100644 --- a/stock_reserve_rule/tests/test_reserve_rule.py +++ b/stock_reserve_rule/tests/test_reserve_rule.py @@ -144,9 +144,10 @@ def _create_rule(self, rule_values, removal_values): "rule_removal_ids": [(0, 0, values) for values in removal_values], } rule_config.update(rule_values) - self.env["stock.reserve.rule"].create(rule_config) + record = self.env["stock.reserve.rule"].create(rule_config) # workaround for https://github.com/odoo/odoo/pull/41900 self.env["stock.reserve.rule"].invalidate_cache() + return record def _setup_packagings(self, product, packagings): """Create packagings on a product @@ -962,6 +963,98 @@ def test_rule_single_lot_eq(self): # # self.assertFalse(move.move_line_ids) # # self.assertEqual(move.state, "confirmed") + def test_rule_validation(self): + rule = self._create_rule( + # different picking, should be excluded + {"picking_type_ids": [(6, 0, self.wh.out_type_id.ids)], "sequence": 1}, + [ + { + "location_id": self.loc_zone4.id, + "removal_strategy": "single_lot", + "reserve_lot": "lot_qty_gt_requested_qty", + } + ], + ) + with Form( + rule, view="stock_reserve_rule.view_stock_reserve_rule_form" + ) as form, form.rule_removal_ids.edit(0) as line: + with self.assertRaises(exceptions.UserError): + line.tolerance_margin = "absolute" + line.tolerance_upper_limit = -1 + + def test_rule_tolerance_absolute(self): + self._update_qty_in_location( + self.loc_zone4_bin1, self.product3, 4, lot_id=self.lot0_id + ) + self._create_rule( + # different picking, should be excluded + {"picking_type_ids": [(6, 0, self.wh.out_type_id.ids)], "sequence": 1}, + [ + { + "location_id": self.loc_zone4.id, + "removal_strategy": "single_lot", + "reserve_lot": "lot_qty_gt_requested_qty", + "tolerance_margin": "absolute", + "tolerance_upper_limit": 1.0, + } + ], + ) + picking = self._create_picking( + self.wh, [(self.product3, 4)], picking_type_id=self.wh.out_type_id.id + ) + picking.action_assign() + move = picking.move_lines + self.assertFalse(move.move_line_ids) + + picking = self._create_picking( + self.wh, [(self.product3, 3)], picking_type_id=self.wh.out_type_id.id + ) + picking.action_assign() + move = picking.move_lines + self.assertRecordValues( + move.move_line_ids, + [ + { + "location_id": self.loc_zone4_bin1.id, + "product_qty": 3, + "lot_id": self.lot0_id.id, + }, + ], + ) + + def test_rule_tolerance_percent(self): + self._update_qty_in_location( + self.loc_zone4_bin1, self.product3, 5, lot_id=self.lot0_id + ) + self._create_rule( + # different picking, should be excluded + {"picking_type_ids": [(6, 0, self.wh.out_type_id.ids)], "sequence": 1}, + [ + { + "location_id": self.loc_zone4.id, + "removal_strategy": "single_lot", + "reserve_lot": "lot_qty_gt_requested_qty", + "tolerance_margin": "percentage", + "tolerance_upper_limit": 50.0, + } + ], + ) + picking = self._create_picking( + self.wh, [(self.product3, 4)], picking_type_id=self.wh.out_type_id.id + ) + picking.action_assign() + move = picking.move_lines + self.assertRecordValues( + move.move_line_ids, + [ + { + "location_id": self.loc_zone4_bin1.id, + "product_qty": 4, + "lot_id": self.lot0_id.id, + }, + ], + ) + def test_rule_single_lot_gt(self): self._update_qty_in_location( self.loc_zone4_bin1, self.product3, 100, lot_id=self.lot0_id