[FIX] stock_reserve_rule: rule matching

A move from "Stock/Zone1/A" must match removal rules defined for
"Stock/Zone1"
This commit is contained in:
Jacques-Etienne Baudoux
2021-12-16 10:16:31 +01:00
committed by Denis Roussel
parent 98c31d1f35
commit 0a75207e13
6 changed files with 52 additions and 5 deletions

View File

@@ -161,6 +161,7 @@ Contributors
~~~~~~~~~~~~
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
Maintainers
~~~~~~~~~~~

View File

@@ -3,7 +3,7 @@
{
"name": "Stock Reservation Rules",
"summary": "Configure reservation rules by location",
"version": "14.0.1.0.0",
"version": "14.0.1.0.1",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Stock Management",

View File

@@ -1,4 +1,5 @@
# Copyright 2019 Camptocamp SA
# Copyright 2019-2021 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
from odoo.tools.float_utils import float_compare
@@ -50,7 +51,12 @@ class StockMove(models.Model):
# it can use both rules.
# If we have a stock.move with "Stock/Zone2" as source location,
# it should never use "Stock/Zone1"
if not removal_rule.location_id.is_sublocation_of(location_id):
# If we have a stock.move with "Stock/Zone1/A" as source location,
# it should use "Stock/Zone1" rule
if not (
removal_rule.location_id.is_sublocation_of(location_id)
or location_id.is_sublocation_of(removal_rule.location_id)
):
continue
quants = self.env["stock.quant"]._gather(

View File

@@ -1 +1,2 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>

View File

@@ -499,6 +499,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li>
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">

View File

@@ -1,4 +1,5 @@
# Copyright 2019 Camptocamp (https://www.camptocamp.com)
# Copyright 2019-2021 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
from odoo import exceptions, fields
from odoo.tests import common
@@ -71,7 +72,7 @@ class TestReserveRule(common.SavepointCase):
{"name": "Pallet", "code": "PALLET", "sequence": 5}
)
def _create_picking(self, wh, products=None):
def _create_picking(self, wh, products=None, location_src_id=None):
"""Create picking
Products must be a list of tuples (product, quantity).
@@ -82,7 +83,7 @@ class TestReserveRule(common.SavepointCase):
picking = self.env["stock.picking"].create(
{
"location_id": wh.lot_stock_id.id,
"location_id": location_src_id or wh.lot_stock_id.id,
"location_dest_id": wh.wh_output_stock_loc_id.id,
"partner_id": self.partner_delta.id,
"picking_type_id": wh.pick_type_id.id,
@@ -97,7 +98,7 @@ class TestReserveRule(common.SavepointCase):
"product_uom_qty": qty,
"product_uom": product.uom_id.id,
"picking_id": picking.id,
"location_id": wh.lot_stock_id.id,
"location_id": location_src_id or wh.lot_stock_id.id,
"location_dest_id": wh.wh_output_stock_loc_id.id,
"state": "confirmed",
}
@@ -180,6 +181,43 @@ class TestReserveRule(common.SavepointCase):
)
self.assertEqual(move.state, "assigned")
def test_rule_match_parent(self):
all_locs = (
self.loc_zone1_bin1,
self.loc_zone1_bin2,
self.loc_zone2_bin1,
self.loc_zone2_bin2,
self.loc_zone3_bin1,
self.loc_zone3_bin2,
)
for loc in all_locs:
self._update_qty_in_location(loc, self.product1, 100)
picking = self._create_picking(
self.wh, [(self.product1, 200)], self.loc_zone1.id
)
self._create_rule(
{},
[
{"location_id": self.loc_zone1.id, "sequence": 2},
{"location_id": self.loc_zone2.id, "sequence": 1},
{"location_id": self.loc_zone3.id, "sequence": 3},
],
)
picking.action_assign()
move = picking.move_lines
ml = move.move_line_ids
self.assertRecordValues(
ml,
[
{"location_id": self.loc_zone1_bin1.id, "product_qty": 100},
{"location_id": self.loc_zone1_bin2.id, "product_qty": 100},
],
)
self.assertEqual(move.state, "assigned")
def test_rule_take_all_in_2_and_3(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)