Skip to content

Commit

Permalink
[IMP] stock_inventory_lockdown: do not block movements of parent loca…
Browse files Browse the repository at this point in the history
…tion if child bin location is being reviwed
  • Loading branch information
JoanSForgeFlow committed Sep 18, 2024
1 parent 10cd8fc commit 16a9ff3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
30 changes: 22 additions & 8 deletions stock_inventory_lockdown/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@ class StockInventory(models.Model):

@api.model
def _get_locations_open_inventories(self, locations_ids=None):
inventory_domain = [("state", "=", "in_progress")]
if locations_ids:
inventory_domain.append(("location_ids", "child_of", locations_ids))
inventories = self.search(inventory_domain)
if not locations_ids:
return []
inventory_domain_same_location = [
("state", "=", "in_progress"),
("location_ids", "in", locations_ids),
]
inventories_same_location = self.search(inventory_domain_same_location)
inventory_domain_parent = [
("state", "=", "in_progress"),
("exclude_sublocation", "=", False),
]
inventories_possible_parent = self.search(inventory_domain_parent)
inventories_parent = self.env["stock.inventory"]
for inventory in inventories_possible_parent:
for location in inventory.location_ids:
if any(
location_id in location.child_internal_location_ids.ids
for location_id in locations_ids
):
inventories_parent |= inventory
inventories = inventories_same_location | inventories_parent
if not inventories:
# Early exit if no match found
return []
location_ids = inventories.mapped("location_ids")
# Extend to the children Locations
location_domain = [
"|",
("location_id", "in", location_ids.ids),
("location_id", "child_of", location_ids.ids),
("id", "in", location_ids.ids),
("usage", "in", ["internal", "transit"]),
]
return self.env["stock.location"].search(location_domain)
21 changes: 6 additions & 15 deletions stock_inventory_lockdown/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,19 @@ def _check_locked_location(self):
]._get_locations_open_inventories(
[move_line.location_dest_id.id, move_line.location_id.id]
)
reserved_origin_loc = move_line.location_id
dest_loc = move_line.location_dest_id
if (
locked_location_ids
and not any(
[
move_line.location_dest_id.usage == "inventory",
move_line.location_id.usage == "inventory",
]
)
and (
reserved_origin_loc in locked_location_ids
or dest_loc in locked_location_ids
)
if locked_location_ids and not any(
[
move_line.location_dest_id.usage == "inventory",
move_line.location_id.usage == "inventory",
]
):
location_names = locked_location_ids.mapped("complete_name")
raise ValidationError(
_(
"Inventory adjusment underway at "
"the following location(s):\n- %s\n"
"Moving products to or from these locations is "
"not allowed until the inventory check is complete."
"not allowed until the inventory adjustment is complete."
)
% "\n - ".join(location_names)
)

0 comments on commit 16a9ff3

Please sign in to comment.