[IMP] stock_inventory_lockdown: do not block movements of parent location if child bin location is being reviwed

This commit is contained in:
Joan Sisquella
2024-09-18 09:53:58 +02:00
committed by ArnauCForgeFlow
parent 9462014342
commit 172fbdc6db
2 changed files with 28 additions and 23 deletions

View File

@@ -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)

View File

@@ -26,20 +26,11 @@ class StockMoveLine(models.Model):
]._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(
@@ -47,7 +38,7 @@ class StockMoveLine(models.Model):
"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)
)