mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
3e977834c5
@ -44,7 +44,6 @@ class CreateStockItemForm(HelperForm):
|
|||||||
'serial_numbers',
|
'serial_numbers',
|
||||||
'delete_on_deplete',
|
'delete_on_deplete',
|
||||||
'status',
|
'status',
|
||||||
'notes',
|
|
||||||
'URL',
|
'URL',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
19
InvenTree/stock/migrations/0020_auto_20200206_1213.py
Normal file
19
InvenTree/stock/migrations/0020_auto_20200206_1213.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.2.9 on 2020-02-06 12:13
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import markdownx.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('stock', '0019_auto_20200202_1024'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='stockitem',
|
||||||
|
name='notes',
|
||||||
|
field=markdownx.models.MarkdownxField(blank=True, help_text='Stock Item Notes', null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -360,7 +360,7 @@ class StockItem(models.Model):
|
|||||||
choices=StockStatus.items(),
|
choices=StockStatus.items(),
|
||||||
validators=[MinValueValidator(0)])
|
validators=[MinValueValidator(0)])
|
||||||
|
|
||||||
notes = MarkdownxField(blank=True, help_text=_('Stock Item Notes'))
|
notes = MarkdownxField(blank=True, null=True, help_text=_('Stock Item Notes'))
|
||||||
|
|
||||||
# If stock item is incoming, an (optional) ETA field
|
# If stock item is incoming, an (optional) ETA field
|
||||||
# expected_arrival = models.DateField(null=True, blank=True)
|
# expected_arrival = models.DateField(null=True, blank=True)
|
||||||
|
@ -884,34 +884,49 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))]
|
form.errors['serial_numbers'] = [_('The following serial numbers already exist: ({sn})'.format(sn=exists))]
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
# At this point we have a list of serial numbers which we know are valid,
|
else:
|
||||||
# and do not currently exist
|
# At this point we have a list of serial numbers which we know are valid,
|
||||||
form.clean()
|
# and do not currently exist
|
||||||
|
form.clean()
|
||||||
|
|
||||||
data = form.cleaned_data
|
form_data = form.cleaned_data
|
||||||
|
|
||||||
for serial in serials:
|
for serial in serials:
|
||||||
# Create a new stock item for each serial number
|
# Create a new stock item for each serial number
|
||||||
item = StockItem(
|
item = StockItem(
|
||||||
part=part,
|
part=part,
|
||||||
quantity=1,
|
quantity=1,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
supplier_part=data.get('supplier_part'),
|
supplier_part=form_data.get('supplier_part'),
|
||||||
location=data.get('location'),
|
location=form_data.get('location'),
|
||||||
batch=data.get('batch'),
|
batch=form_data.get('batch'),
|
||||||
delete_on_deplete=False,
|
delete_on_deplete=False,
|
||||||
status=data.get('status'),
|
status=form_data.get('status'),
|
||||||
notes=data.get('notes'),
|
URL=form_data.get('URL'),
|
||||||
URL=data.get('URL'),
|
)
|
||||||
)
|
|
||||||
|
|
||||||
item.save(user=request.user)
|
item.save(user=request.user)
|
||||||
|
|
||||||
|
data['success'] = _('Created {n} new stock items'.format(n=len(serials)))
|
||||||
|
valid = True
|
||||||
|
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
form.errors['serial_numbers'] = e.messages
|
form.errors['serial_numbers'] = e.messages
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# We have a serialized part, but no serial numbers specified...
|
||||||
|
form.clean()
|
||||||
|
form._post_clean()
|
||||||
|
|
||||||
|
item = form.save(commit=False)
|
||||||
|
item.save(user=request.user)
|
||||||
|
|
||||||
|
data['pk'] = item.pk
|
||||||
|
data['url'] = item.get_absolute_url()
|
||||||
|
data['success'] = _("Created new stock item")
|
||||||
|
|
||||||
|
else: # Referenced Part object is not marked as "trackable"
|
||||||
# For non-serialized items, simply save the form.
|
# For non-serialized items, simply save the form.
|
||||||
# We need to call _post_clean() here because it is prevented in the form implementation
|
# We need to call _post_clean() here because it is prevented in the form implementation
|
||||||
form.clean()
|
form.clean()
|
||||||
|
Loading…
Reference in New Issue
Block a user