Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12e16f3

Browse files
committedOct 18, 2024·
[IMP] stock_storage_type: Allow to re-apply putaway rules on computed location for a selected move line
1 parent 77a99cb commit 12e16f3

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎stock_storage_type/models/stock_storage_category_capacity.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2022 ACSONE SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
33
from odoo import _, api, fields, models
4+
from odoo.osv.expression import AND, OR
45

56

67
class StorageCategoryProductCapacity(models.Model):
@@ -95,7 +96,34 @@ def _domain_location_storage_type(self, candidate_locations, quants, products):
9596
]
9697
# Build the domain using the 'allow_new_product' field
9798
if self.allow_new_product == "empty":
98-
location_domain.append(("location_is_empty", "=", True))
99+
# We should include the destination location of the current
100+
# stock move line to avoid excluding it if already selected
101+
# Indeed, if the current move line point to the last void location,
102+
# calling the putaway apply will recompute the destination location
103+
# to the related stock.move destination as the rules consider
104+
# there is no more room available (which is not true).
105+
exclude_sml_ids = self.env.context.get("exclude_sml_ids")
106+
if exclude_sml_ids:
107+
lines_locations = (
108+
self.env["stock.move.line"].browse(exclude_sml_ids).location_dest_id
109+
)
110+
if lines_locations:
111+
location_domain = AND(
112+
[
113+
location_domain,
114+
OR(
115+
[
116+
[
117+
("location_is_empty", "=", False),
118+
("id", "in", lines_locations.ids),
119+
],
120+
[("location_is_empty", "=", True)],
121+
]
122+
),
123+
]
124+
)
125+
else:
126+
location_domain.append(("location_is_empty", "=", True))
99127
elif self.allow_new_product == "same":
100128
location_domain += self._get_product_location_domain(products)
101129
elif self.allow_new_product == "same_lot":

‎stock_storage_type/tests/test_storage_type_putaway_strategy.py

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def test_storage_strategy_only_empty_ordered_locations_pallets(self):
141141
self.pallets_bin_1_location | self.pallets_bin_3_location,
142142
)
143143

144+
# Try to re-apply the putaways to check the same destinations are selected
145+
int_picking.move_line_ids._apply_putaway_strategy()
146+
self.assertEqual(
147+
int_picking.move_line_ids.mapped("location_dest_id"),
148+
self.pallets_bin_1_location | self.pallets_bin_3_location,
149+
)
150+
144151
def test_storage_strategy_max_weight_ordered_locations_pallets(self):
145152
# Add a category for max_weight 50
146153
category_50 = self.env["stock.storage.category"].create(

0 commit comments

Comments
 (0)
Please sign in to comment.