Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] stock_storage_type: Allow to re-apply putaway rules on computed location for a selected move line #938

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
rousseldenis marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading