Skip to content

Commit

Permalink
Fix stock location structural check (#4089) (#4095)
Browse files Browse the repository at this point in the history
* Fix stock location structural check

Exclude sub stock location items from preventing that a stock location can be switched to structural.

* Fix structural check on both storage location and parts category

Exclude children of sub- locations/categories in the check to allow this location/category to be structural

(cherry picked from commit 14a2c12)

Co-authored-by: bloemp <pbloem@upcmail.nl>
  • Loading branch information
SchrodingersGat and bloemp committed Dec 21, 2022
1 parent eb7aba4 commit 641adb6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion InvenTree/part/models.py
Expand Up @@ -148,7 +148,7 @@ def clean(self):
- Ensure that the structural parameter cannot get set if products already assigned to the category
"""
if self.pk and self.structural and self.item_count > 0:
if self.pk and self.structural and self.partcount(False, False) > 0:
raise ValidationError(
_("You cannot make this part category structural because some parts "
"are already assigned to it!"))
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/stock/models.py
Expand Up @@ -152,7 +152,7 @@ def clean(self):
- Ensure stock location can't be made structural if stock items already located to them
"""
if self.pk and self.structural and self.item_count > 0:
if self.pk and self.structural and self.stock_item_count(False) > 0:
raise ValidationError(
_("You cannot make this stock location structural because some stock items "
"are already located into it!"))
Expand Down

0 comments on commit 641adb6

Please sign in to comment.