mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Exclude expired stock from builds
This commit is contained in:
parent
580e7599a0
commit
33d6396a4e
@ -27,6 +27,8 @@ from InvenTree.helpers import increment, getSetting, normalize
|
||||
from InvenTree.validators import validate_build_order_reference
|
||||
from InvenTree.models import InvenTreeAttachment
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
import InvenTree.fields
|
||||
|
||||
from stock import models as StockModels
|
||||
@ -819,6 +821,10 @@ class Build(MPTTModel):
|
||||
location__in=[loc for loc in self.take_from.getUniqueChildren()]
|
||||
)
|
||||
|
||||
# Exclude expired stock items
|
||||
if not InvenTreeSetting.get_setting('STOCK_ALLOW_EXPIRED_BUILD'):
|
||||
items = items.exclude(StockModels.StockItem.EXPIRED_FILTER)
|
||||
|
||||
return items
|
||||
|
||||
@property
|
||||
|
@ -903,6 +903,7 @@ class BuildItemCreate(AjaxCreateView):
|
||||
|
||||
if self.build and self.part:
|
||||
available_items = self.build.availableStockItems(self.part, self.output)
|
||||
|
||||
form.fields['stock_item'].queryset = available_items
|
||||
|
||||
self.available_stock = form.fields['stock_item'].queryset.all()
|
||||
|
@ -5,6 +5,8 @@ from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@ -32,6 +34,9 @@ class StockViewTestCase(TestCase):
|
||||
password='password'
|
||||
)
|
||||
|
||||
self.user.is_staff = True
|
||||
self.user.save()
|
||||
|
||||
# Put the user into a group with the correct permissions
|
||||
group = Group.objects.create(name='mygroup')
|
||||
self.user.groups.add(group)
|
||||
@ -163,6 +168,9 @@ class StockItemTest(StockViewTestCase):
|
||||
and should be in the future!
|
||||
"""
|
||||
|
||||
# First, ensure that the expiry date feature is enabled!
|
||||
InvenTreeSetting.set_setting('STOCK_ENABLE_EXPIRY', True, self.user)
|
||||
|
||||
url = reverse('stock-item-create')
|
||||
|
||||
response = self.client.get(url, {'part': 25}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
|
Loading…
Reference in New Issue
Block a user