Prevent expired stock from being added to a sales order

This commit is contained in:
Oliver Walters 2021-01-06 20:22:56 +11:00
parent 9b086560cb
commit 580e7599a0
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block page_title %}
InvenTree | {% trans "Index" %}
{% endblock %}
@ -22,7 +23,10 @@ InvenTree | {% trans "Index" %}
<div class='col-sm-4'>
{% if roles.stock.view %}
{% include "InvenTree/low_stock.html" with collapse_id="order" %}
{% settings_value "STOCK_ENABLE_EXPIRY" as expiry %}
{% if expiry %}
{% include "InvenTree/expired_stock.html" with collapse_id="expired" %}
{% endif %}
{% include "InvenTree/required_stock_build.html" with collapse_id="stock_to_build" %}
{% endif %}
</div>