2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-16 01:08:12 +00:00

Set serial numbers when creating a new stock item

This commit is contained in:
Oliver Walters
2019-07-23 10:31:34 +10:00
parent 23d03d6b9b
commit 9e5eadd6c3
6 changed files with 105 additions and 23 deletions

View File

@@ -6,8 +6,9 @@ Django Forms for interacting with Stock app
from __future__ import unicode_literals
from django import forms
from InvenTree.forms import HelperForm
from django.forms.utils import ErrorDict
from InvenTree.forms import HelperForm
from .models import StockLocation, StockItem, StockItemTracking
@@ -26,6 +27,8 @@ class EditStockLocationForm(HelperForm):
class CreateStockItemForm(HelperForm):
""" Form for creating a new StockItem """
serial_numbers = forms.CharField(label='Serial numbers', required=False, help_text='Enter unique serial numbers')
class Meta:
model = StockItem
fields = [
@@ -34,13 +37,30 @@ class CreateStockItemForm(HelperForm):
'location',
'quantity',
'batch',
'serial',
'serial_numbers',
'delete_on_deplete',
'status',
'notes',
'URL',
]
# Custom clean to prevent complex StockItem.clean() logic from running (yet)
def full_clean(self):
self._errors = ErrorDict()
if not self.is_bound: # Stop further processing.
return
self.cleaned_data = {}
# If the form is permitted to be empty, and none of the form data has
# changed from the initial data, short circuit any validation.
if self.empty_permitted and not self.has_changed():
return
# Don't run _post_clean() as this will run StockItem.clean()
self._clean_fields()
self._clean_form()
class AdjustStockForm(forms.ModelForm):
""" Form for performing simple stock adjustments.