From 641adb6ae82fbb33418fb64a6555a132d781152c Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 22 Dec 2022 07:48:50 +1100 Subject: [PATCH] Fix stock location structural check (#4089) (#4095) * 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 14a2c128a95c79899e4f393a957552824c22a055) Co-authored-by: bloemp --- InvenTree/part/models.py | 2 +- InvenTree/stock/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 3407e2ebf6..72e6e0e8de 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -148,7 +148,7 @@ class PartCategory(MetadataMixin, InvenTreeTree): - 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!")) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 93ee99c951..a4a9124a2a 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -152,7 +152,7 @@ class StockLocation(InvenTreeBarcodeMixin, MetadataMixin, InvenTreeTree): - 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!"))