Add explicit filter on picking type

This commit is contained in:
Guewen Baconnier
2020-05-25 08:30:02 +02:00
parent 6c8c6c9fd9
commit 3d977e92e2
3 changed files with 40 additions and 0 deletions

View File

@@ -46,6 +46,10 @@ class StockReserveRule(models.Model):
required=True,
help="Rule applied only in this location and sub-locations.",
)
picking_type_id = fields.Many2one(
comodel_name="stock.picking.type",
string="Operation Type",
help="Apply this rule only if the operation type of the move is the same.",
)
rule_removal_ids = fields.One2many(
@@ -85,6 +89,10 @@ class StockReserveRule(models.Model):
)
def _is_rule_applicable(self, move):
if self.picking_type_id:
picking_type = move.picking_type_id or move.picking_id.picking_type_id
if picking_type != self.picking_type_id:
return False
domain = safe_eval(self.rule_domain) or []
if domain:
return self._eval_rule_domain(move, domain)

View File

@@ -264,6 +264,37 @@ class TestReserveRule(common.SavepointCase):
)
self.assertEqual(move.state, "assigned")
def test_picking_type(self):
self._update_qty_in_location(self.loc_zone1_bin1, self.product1, 100)
self._update_qty_in_location(self.loc_zone2_bin1, self.product1, 100)
self._update_qty_in_location(self.loc_zone3_bin1, self.product1, 100)
picking = self._create_picking(self.wh, [(self.product1, 200)])
self._create_rule(
# different picking, should be excluded
{"picking_type_id": self.wh.int_type_id.id, "sequence": 1},
[{"location_id": self.loc_zone1.id, "sequence": 1}],
)
self._create_rule(
# same picking type as the move
{"picking_type_id": self.wh.pick_type_id.id, "sequence": 2},
[
{"location_id": self.loc_zone2.id, "sequence": 1},
{"location_id": self.loc_zone3.id, "sequence": 2},
],
)
picking.action_assign()
move = picking.move_lines
ml = move.move_line_ids
self.assertRecordValues(
ml,
[
{"location_id": self.loc_zone2_bin1.id, "product_qty": 100},
{"location_id": self.loc_zone3_bin1.id, "product_qty": 100},
],
)
self.assertEqual(move.state, "assigned")
def test_quant_domain(self):
self._update_qty_in_location(self.loc_zone1_bin1, self.product1, 100)
self._update_qty_in_location(self.loc_zone2_bin1, self.product1, 100)

View File

@@ -22,6 +22,7 @@
<group>
<field name="active" invisible="1" />
<field name="location_id" />
<field name="picking_type_id" />
<field name="sequence" />
</group>
<group>