Skip to content

Commit

Permalink
[IMP] stock_reserve_rule: Tests for tolerance is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Oct 3, 2023
1 parent e7d3f6d commit e591d33
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion stock_reserve_rule/tests/test_reserve_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e591d33

Please sign in to comment.