mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
3959dd40b0
@ -59,7 +59,7 @@ class Build(models.Model):
|
|||||||
take_from = models.ForeignKey('stock.StockLocation', on_delete=models.SET_NULL,
|
take_from = models.ForeignKey('stock.StockLocation', on_delete=models.SET_NULL,
|
||||||
related_name='sourcing_builds',
|
related_name='sourcing_builds',
|
||||||
null=True, blank=True,
|
null=True, blank=True,
|
||||||
help_text='Select location to take stock from for this build (leave blank to take from any stock location'
|
help_text='Select location to take stock from for this build (leave blank to take from any stock location)'
|
||||||
)
|
)
|
||||||
|
|
||||||
quantity = models.PositiveIntegerField(
|
quantity = models.PositiveIntegerField(
|
||||||
|
@ -12,7 +12,6 @@ from rest_framework.response import Response
|
|||||||
from rest_framework import filters
|
from rest_framework import filters
|
||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
from django.db.models import Q
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
@ -109,20 +108,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
if cat_id:
|
if cat_id:
|
||||||
try:
|
try:
|
||||||
category = PartCategory.objects.get(pk=cat_id)
|
category = PartCategory.objects.get(pk=cat_id)
|
||||||
|
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
|
||||||
# Filter by the supplied category
|
|
||||||
flt = Q(category=cat_id)
|
|
||||||
|
|
||||||
if self.request.query_params.get('include_child_categories', None):
|
|
||||||
childs = category.getUniqueChildren()
|
|
||||||
for child in childs:
|
|
||||||
# Ignore the top-level category (already filtered)
|
|
||||||
if str(child) == str(cat_id):
|
|
||||||
continue
|
|
||||||
flt |= Q(category=child)
|
|
||||||
|
|
||||||
parts_list = parts_list.filter(flt)
|
|
||||||
|
|
||||||
except PartCategory.DoesNotExist:
|
except PartCategory.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -574,10 +574,11 @@ class Part(models.Model):
|
|||||||
|
|
||||||
# Copy the part image
|
# Copy the part image
|
||||||
if kwargs.get('image', True):
|
if kwargs.get('image', True):
|
||||||
image_file = ContentFile(other.image.read())
|
if other.image:
|
||||||
image_file.name = rename_part_image(self, 'test.png')
|
image_file = ContentFile(other.image.read())
|
||||||
|
image_file.name = rename_part_image(self, 'test.png')
|
||||||
|
|
||||||
self.image = image_file
|
self.image = image_file
|
||||||
|
|
||||||
# Copy the BOM data
|
# Copy the BOM data
|
||||||
if kwargs.get('bom', False):
|
if kwargs.get('bom', False):
|
||||||
|
@ -153,7 +153,6 @@
|
|||||||
query: {
|
query: {
|
||||||
{% if category %}
|
{% if category %}
|
||||||
category: {{ category.id }},
|
category: {{ category.id }},
|
||||||
include_child_categories: true,
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
},
|
||||||
buttons: ['#part-options'],
|
buttons: ['#part-options'],
|
||||||
|
@ -105,13 +105,6 @@ class PartAPITest(APITestCase):
|
|||||||
url = reverse('api-part-list')
|
url = reverse('api-part-list')
|
||||||
data = {'category': 1}
|
data = {'category': 1}
|
||||||
|
|
||||||
response = self.client.get(url, data, format='json')
|
|
||||||
|
|
||||||
# There should be 1 part in this category
|
|
||||||
self.assertEqual(len(response.data), 0)
|
|
||||||
|
|
||||||
data['include_child_categories'] = 1
|
|
||||||
|
|
||||||
# Now request to include child categories
|
# Now request to include child categories
|
||||||
response = self.client.get(url, data, format='json')
|
response = self.client.get(url, data, format='json')
|
||||||
|
|
||||||
|
@ -7,11 +7,12 @@ from django_filters import NumberFilter
|
|||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
from .models import StockLocation, StockItem
|
from .models import StockLocation, StockItem
|
||||||
from .models import StockItemTracking
|
from .models import StockItemTracking
|
||||||
|
|
||||||
|
from part.models import PartCategory
|
||||||
|
|
||||||
from .serializers import StockItemSerializer, StockQuantitySerializer
|
from .serializers import StockItemSerializer, StockQuantitySerializer
|
||||||
from .serializers import LocationSerializer
|
from .serializers import LocationSerializer
|
||||||
from .serializers import StockTrackingSerializer
|
from .serializers import StockTrackingSerializer
|
||||||
@ -237,16 +238,19 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
- GET: Return a list of all StockItem objects (with optional query filters)
|
- GET: Return a list of all StockItem objects (with optional query filters)
|
||||||
- POST: Create a new StockItem
|
- POST: Create a new StockItem
|
||||||
|
|
||||||
|
Additional query parameters are available:
|
||||||
|
- location: Filter stock by location
|
||||||
|
- category: Filter by parts belonging to a certain category
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
If the query includes a particular location,
|
If the query includes a particular location,
|
||||||
we may wish to also request stock items from all child locations.
|
we may wish to also request stock items from all child locations.
|
||||||
This is set by the optional param 'include_child_categories'
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Does the client wish to filter by category?
|
# Does the client wish to filter by stock location?
|
||||||
loc_id = self.request.query_params.get('location', None)
|
loc_id = self.request.query_params.get('location', None)
|
||||||
|
|
||||||
# Start with all objects
|
# Start with all objects
|
||||||
@ -255,23 +259,22 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
if loc_id:
|
if loc_id:
|
||||||
try:
|
try:
|
||||||
location = StockLocation.objects.get(pk=loc_id)
|
location = StockLocation.objects.get(pk=loc_id)
|
||||||
|
stock_list = stock_list.filter(location__in=location.getUniqueChildren())
|
||||||
# Filter by the supplied category
|
|
||||||
flt = Q(location=loc_id)
|
|
||||||
|
|
||||||
if self.request.query_params.get('include_child_locations', None):
|
|
||||||
childs = location.getUniqueChildren()
|
|
||||||
for child in childs:
|
|
||||||
# Ignore the top-level category (already filtered!)
|
|
||||||
if str(child) == str(loc_id):
|
|
||||||
continue
|
|
||||||
flt |= Q(location=child)
|
|
||||||
|
|
||||||
stock_list = stock_list.filter(flt)
|
|
||||||
|
|
||||||
except StockLocation.DoesNotExist:
|
except StockLocation.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Does the client wish to filter by part category?
|
||||||
|
cat_id = self.request.query_params.get('category', None)
|
||||||
|
|
||||||
|
if cat_id:
|
||||||
|
try:
|
||||||
|
category = PartCategory.objects.get(pk=cat_id)
|
||||||
|
stock_list = stock_list.filter(part__category__in=category.getUniqueChildren())
|
||||||
|
|
||||||
|
except PartCategory.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
return stock_list
|
return stock_list
|
||||||
|
|
||||||
serializer_class = StockItemSerializer
|
serializer_class = StockItemSerializer
|
||||||
|
@ -196,7 +196,6 @@
|
|||||||
params: {
|
params: {
|
||||||
{% if location %}
|
{% if location %}
|
||||||
location: {{ location.id }},
|
location: {{ location.id }},
|
||||||
include_child_locations: true,
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
},
|
||||||
url: "{% url 'api-stock-list' %}",
|
url: "{% url 'api-stock-list' %}",
|
||||||
|
Loading…
Reference in New Issue
Block a user