mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Expose "is_allocated" parameter on StockItem API
This commit is contained in:
@ -367,6 +367,17 @@ class StockList(generics.ListCreateAPIView):
|
||||
# Filter out parts which are not actually "in stock"
|
||||
stock_list = stock_list.filter(customer=None, belongs_to=None)
|
||||
|
||||
# Filter by 'allocated' patrs?
|
||||
allocated = self.request.query_params.get('allocated', None)
|
||||
|
||||
if allocated is not None:
|
||||
allocated = str2bool(allocated)
|
||||
|
||||
if allocated:
|
||||
stock_list = stock_list.exclude(Q(sales_order_line=None))
|
||||
else:
|
||||
stock_list = stock_list.filter(Q(sales_order_line=None))
|
||||
|
||||
# Do we wish to filter by "active parts"
|
||||
active = self.request.query_params.get('active', None)
|
||||
|
||||
|
19
InvenTree/stock/migrations/0029_auto_20200421_2359.py
Normal file
19
InvenTree/stock/migrations/0029_auto_20200421_2359.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-21 23:59
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0028_auto_20200421_0724'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitem',
|
||||
name='status',
|
||||
field=models.PositiveIntegerField(choices=[(10, 'OK'), (50, 'Attention needed'), (55, 'Damaged'), (60, 'Destroyed'), (70, 'Lost'), (110, 'Shipped'), (85, 'Returned')], default=10, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
]
|
@ -397,6 +397,16 @@ class StockItem(MPTTModel):
|
||||
|
||||
infinite = models.BooleanField(default=False)
|
||||
|
||||
def is_allocated(self):
|
||||
"""
|
||||
Return True if this StockItem is allocated to a SalesOrder or a Build
|
||||
"""
|
||||
|
||||
# TODO - For now this only checks if the StockItem is allocated to a SalesOrder
|
||||
# TODO - In future, once the "build" is working better, check this too
|
||||
|
||||
return self.sales_order_line is not None
|
||||
|
||||
def can_delete(self):
|
||||
""" Can this stock item be deleted? It can NOT be deleted under the following circumstances:
|
||||
|
||||
|
@ -90,6 +90,8 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True)
|
||||
|
||||
allocated = serializers.BooleanField(source='is_allocated', read_only=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
part_detail = kwargs.pop('part_detail', False)
|
||||
@ -110,6 +112,7 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
class Meta:
|
||||
model = StockItem
|
||||
fields = [
|
||||
'allocated',
|
||||
'batch',
|
||||
'in_stock',
|
||||
'link',
|
||||
|
Reference in New Issue
Block a user