diff --git a/stock_reserve_rule/README.rst b/stock_reserve_rule/README.rst index 8e3a3bfb8..6881a7986 100644 --- a/stock_reserve_rule/README.rst +++ b/stock_reserve_rule/README.rst @@ -161,6 +161,7 @@ Contributors ~~~~~~~~~~~~ * Guewen Baconnier +* Jacques-Etienne Baudoux (BCIM) Maintainers ~~~~~~~~~~~ diff --git a/stock_reserve_rule/__manifest__.py b/stock_reserve_rule/__manifest__.py index cfb9b05a8..b952aafe3 100644 --- a/stock_reserve_rule/__manifest__.py +++ b/stock_reserve_rule/__manifest__.py @@ -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", diff --git a/stock_reserve_rule/models/stock_move.py b/stock_reserve_rule/models/stock_move.py index 4b3915aa8..671cbb105 100644 --- a/stock_reserve_rule/models/stock_move.py +++ b/stock_reserve_rule/models/stock_move.py @@ -1,4 +1,5 @@ # Copyright 2019 Camptocamp SA +# Copyright 2019-2021 Jacques-Etienne Baudoux (BCIM) # 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( diff --git a/stock_reserve_rule/readme/CONTRIBUTORS.rst b/stock_reserve_rule/readme/CONTRIBUTORS.rst index 48286263c..3bdce7f9f 100644 --- a/stock_reserve_rule/readme/CONTRIBUTORS.rst +++ b/stock_reserve_rule/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Guewen Baconnier +* Jacques-Etienne Baudoux (BCIM) diff --git a/stock_reserve_rule/static/description/index.html b/stock_reserve_rule/static/description/index.html index 43009976e..1c5ce39c6 100644 --- a/stock_reserve_rule/static/description/index.html +++ b/stock_reserve_rule/static/description/index.html @@ -499,6 +499,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Contributors

diff --git a/stock_reserve_rule/tests/test_reserve_rule.py b/stock_reserve_rule/tests/test_reserve_rule.py index 57ebd6cdc..24930732b 100644 --- a/stock_reserve_rule/tests/test_reserve_rule.py +++ b/stock_reserve_rule/tests/test_reserve_rule.py @@ -1,4 +1,5 @@ # Copyright 2019 Camptocamp (https://www.camptocamp.com) +# Copyright 2019-2021 Jacques-Etienne Baudoux (BCIM) 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)