2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-11 07:24:15 +00:00

Implement structural stock locations (#3949)

* Implement structural stock locations

* Bumped API version
This commit is contained in:
Miklós Márton
2022-11-19 12:24:18 +01:00
committed by GitHub
parent bc8a6ae4b8
commit 0716238f3b
10 changed files with 167 additions and 7 deletions

View File

@ -107,6 +107,14 @@ class StockLocation(InvenTreeBarcodeMixin, MetadataMixin, InvenTreeTree):
help_text=_('Select Owner'),
related_name='stock_locations')
structural = models.BooleanField(
default=False,
verbose_name=_('Structural'),
help_text=_(
'Stock items may not be directly located into a structural stock locations, '
'but may be located to it\'s child locations.'),
)
def get_location_owner(self):
"""Get the closest "owner" for this location.
@ -139,6 +147,17 @@ class StockLocation(InvenTreeBarcodeMixin, MetadataMixin, InvenTreeTree):
return user in owner.get_related_owners(include_group=True)
def clean(self):
"""Custom clean action for the StockLocation model:
- 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:
raise ValidationError(
_("You cannot make this stock location structural because some stock items "
"are already located into it!"))
super().clean()
def get_absolute_url(self):
"""Return url for instance."""
return reverse('stock-location-detail', kwargs={'pk': self.id})
@ -496,8 +515,14 @@ class StockItem(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
- The 'part' and 'supplier_part.part' fields cannot point to the same Part object
- The 'part' is not virtual
- The 'part' does not belong to itself
- The location is not structural
- Quantity must be 1 if the StockItem has a serial number
"""
if self.location is not None and self.location.structural:
raise ValidationError(
{'location': _("Stock items cannot be located into structural stock locations!")})
super().clean()
# Strip serial number field