mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Merge remote-tracking branch 'inventree/master'
This commit is contained in:
@ -38,6 +38,9 @@ class StockCategoryTree(TreeSerializer):
|
||||
def root_url(self):
|
||||
return reverse('stock-index')
|
||||
|
||||
def get_items(self):
|
||||
return StockLocation.objects.all().prefetch_related('stock_items', 'children')
|
||||
|
||||
|
||||
class StockDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
""" API detail endpoint for Stock object
|
||||
|
19
InvenTree/stock/migrations/0007_auto_20190618_0042.py
Normal file
19
InvenTree/stock/migrations/0007_auto_20190618_0042.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.2 on 2019-06-17 14:42
|
||||
|
||||
import InvenTree.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0006_stockitem_purchase_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stocklocation',
|
||||
name='name',
|
||||
field=models.CharField(max_length=100, unique=True, validators=[InvenTree.validators.validate_tree_name]),
|
||||
),
|
||||
]
|
@ -49,19 +49,23 @@ class StockLocation(InvenTreeTree):
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def stock_item_count(self):
|
||||
def stock_item_count(self, cascade=True):
|
||||
""" Return the number of StockItem objects which live in or under this category
|
||||
"""
|
||||
|
||||
return StockItem.objects.filter(location__in=self.getUniqueChildren()).count()
|
||||
if cascade:
|
||||
query = StockItem.objects.filter(location__in=self.getUniqueChildren())
|
||||
else:
|
||||
query = StockItem.objects.filter(location=self)
|
||||
|
||||
return query.count()
|
||||
|
||||
@property
|
||||
def item_count(self):
|
||||
""" Simply returns the number of stock items in this location.
|
||||
Required for tree view serializer.
|
||||
"""
|
||||
return self.stock_item_count
|
||||
return self.stock_item_count()
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
||||
|
Reference in New Issue
Block a user