mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Prevent expired stock from being added to a sales order
This commit is contained in:
@ -24,6 +24,8 @@ from company.models import Company, SupplierPart
|
||||
from stock.models import StockItem, StockLocation
|
||||
from part.models import Part
|
||||
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
from . import forms as order_forms
|
||||
|
||||
from InvenTree.views import AjaxView, AjaxCreateView, AjaxUpdateView, AjaxDeleteView
|
||||
@ -1359,7 +1361,8 @@ class SalesOrderAllocationCreate(AjaxCreateView):
|
||||
try:
|
||||
line = SalesOrderLineItem.objects.get(pk=line_id)
|
||||
|
||||
queryset = form.fields['item'].queryset
|
||||
# Construct a queryset for allowable stock items
|
||||
queryset = StockItem.objects.filter(StockItem.IN_STOCK_FILTER)
|
||||
|
||||
# Ensure the part reference matches
|
||||
queryset = queryset.filter(part=line.part)
|
||||
@ -1369,6 +1372,10 @@ class SalesOrderAllocationCreate(AjaxCreateView):
|
||||
|
||||
queryset = queryset.exclude(pk__in=allocated)
|
||||
|
||||
# Exclude stock items which have expired
|
||||
if not InvenTreeSetting.get_setting('STOCK_ALLOW_EXPIRED_SALE'):
|
||||
queryset = queryset.exclude(StockItem.EXPIRED_FILTER)
|
||||
|
||||
form.fields['item'].queryset = queryset
|
||||
|
||||
# Hide the 'line' field
|
||||
|
Reference in New Issue
Block a user