Skip to content

Commit

Permalink
[IMP] stock_storage_type: Allow to re-apply putaway rules on computed…
Browse files Browse the repository at this point in the history
… location for a selected move line
  • Loading branch information
rousseldenis committed Oct 18, 2024
1 parent 77a99cb commit 12e16f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
30 changes: 29 additions & 1 deletion stock_storage_type/models/stock_storage_category_capacity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2022 ACSONE SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import _, api, fields, models
from odoo.osv.expression import AND, OR


class StorageCategoryProductCapacity(models.Model):
Expand Down Expand Up @@ -95,7 +96,34 @@ def _domain_location_storage_type(self, candidate_locations, quants, products):
]
# Build the domain using the 'allow_new_product' field
if self.allow_new_product == "empty":
location_domain.append(("location_is_empty", "=", True))
# We should include the destination location of the current
# stock move line to avoid excluding it if already selected
# Indeed, if the current move line point to the last void location,
# calling the putaway apply will recompute the destination location
# to the related stock.move destination as the rules consider
# there is no more room available (which is not true).
exclude_sml_ids = self.env.context.get("exclude_sml_ids")
if exclude_sml_ids:
lines_locations = (
self.env["stock.move.line"].browse(exclude_sml_ids).location_dest_id
)
if lines_locations:
location_domain = AND(
[
location_domain,
OR(
[
[
("location_is_empty", "=", False),
("id", "in", lines_locations.ids),
],
[("location_is_empty", "=", True)],
]
),
]
)
else:
location_domain.append(("location_is_empty", "=", True))
elif self.allow_new_product == "same":
location_domain += self._get_product_location_domain(products)
elif self.allow_new_product == "same_lot":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def test_storage_strategy_only_empty_ordered_locations_pallets(self):
self.pallets_bin_1_location | self.pallets_bin_3_location,
)

# Try to re-apply the putaways to check the same destinations are selected
int_picking.move_line_ids._apply_putaway_strategy()
self.assertEqual(
int_picking.move_line_ids.mapped("location_dest_id"),
self.pallets_bin_1_location | self.pallets_bin_3_location,
)

def test_storage_strategy_max_weight_ordered_locations_pallets(self):
# Add a category for max_weight 50
category_50 = self.env["stock.storage.category"].create(
Expand Down

0 comments on commit 12e16f3

Please sign in to comment.