mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 03:56:43 +00:00
Enforce 'notes' field for StockItem move
- Better error handling for StockItem.move
This commit is contained in:
parent
38fa89d1da
commit
757cd539b2
@ -225,11 +225,12 @@ function moveStockItems(items, options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doMove(location, parts) {
|
function doMove(location, parts, notes) {
|
||||||
inventreeUpdate("/api/stock/move/",
|
inventreeUpdate("/api/stock/move/",
|
||||||
{
|
{
|
||||||
location: location,
|
location: location,
|
||||||
'parts[]': parts
|
'parts[]': parts,
|
||||||
|
'notes': notes,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@ -267,9 +268,13 @@ function moveStockItems(items, options) {
|
|||||||
html += makeOption(loc.pk, loc.name + ' - <i>' + loc.description + '</i>');
|
html += makeOption(loc.pk, loc.name + ' - <i>' + loc.description + '</i>');
|
||||||
}
|
}
|
||||||
|
|
||||||
html += "</select><br><hr>";
|
html += "</select><br>";
|
||||||
|
|
||||||
html += "The following stock items will be moved:<br><ul class='list-group'>\n";
|
html += "<hr><input type='text' id='notes' placeholder='Notes'/>";
|
||||||
|
|
||||||
|
html += "<p class='warning-msg' id='note-warning'><i>Note field must be filled</i></p>";
|
||||||
|
|
||||||
|
html += "<hr>The following stock items will be moved:<br><ul class='list-group'>\n";
|
||||||
|
|
||||||
for (i = 0; i < items.length; i++) {
|
for (i = 0; i < items.length; i++) {
|
||||||
parts.push(items[i].pk);
|
parts.push(items[i].pk);
|
||||||
@ -288,10 +293,19 @@ function moveStockItems(items, options) {
|
|||||||
modalSetContent(modal, html);
|
modalSetContent(modal, html);
|
||||||
attachSelect(modal);
|
attachSelect(modal);
|
||||||
|
|
||||||
|
$(modal).find('#note-warning').hide();
|
||||||
|
|
||||||
modalSubmit(modal, function() {
|
modalSubmit(modal, function() {
|
||||||
var locId = $(modal).find("#stock-location").val();
|
var locId = $(modal).find("#stock-location").val();
|
||||||
|
|
||||||
doMove(locId, parts);
|
var notes = $(modal).find('#notes').val();
|
||||||
|
|
||||||
|
if (!notes) {
|
||||||
|
$(modal).find('#note-warning').show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
doMove(locId, parts, notes);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function(error) {
|
||||||
@ -363,7 +377,7 @@ function loadStockTable(table, options) {
|
|||||||
return renderLink(row.location.pathstring, row.location.url);
|
return renderLink(row.location.pathstring, row.location.url);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '';
|
return '<i>No stock location set</i>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -153,6 +153,9 @@ class StockMove(APIView):
|
|||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
if u'notes' not in data:
|
||||||
|
errors.append({'notes': 'Notes field must be supplied'})
|
||||||
|
|
||||||
for pid in part_list:
|
for pid in part_list:
|
||||||
try:
|
try:
|
||||||
part = StockItem.objects.get(pk=pid)
|
part = StockItem.objects.get(pk=pid)
|
||||||
@ -164,7 +167,7 @@ class StockMove(APIView):
|
|||||||
raise ValidationError(errors)
|
raise ValidationError(errors)
|
||||||
|
|
||||||
for part in parts:
|
for part in parts:
|
||||||
part.move(location, request.user)
|
part.move(location, data.get('notes'), request.user)
|
||||||
|
|
||||||
return Response({'success': 'Moved {n} parts to {loc}'.format(
|
return Response({'success': 'Moved {n} parts to {loc}'.format(
|
||||||
n=len(parts),
|
n=len(parts),
|
||||||
|
@ -221,13 +221,17 @@ class StockItem(models.Model):
|
|||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def move(self, location, notes, user):
|
def move(self, location, notes, user):
|
||||||
|
|
||||||
if location.pk == self.location.pk:
|
if location is None:
|
||||||
return False # raise forms.ValidationError("Cannot move item to its current location")
|
# TODO - Raise appropriate error (cannot move to blank location)
|
||||||
|
return False
|
||||||
|
elif self.location and (location.pk == self.location.pk):
|
||||||
|
# TODO - Raise appropriate error (cannot move to same location)
|
||||||
|
return False
|
||||||
|
|
||||||
msg = "Moved to {loc} (from {src})".format(
|
msg = "Moved to {loc}".format(loc=str(location))
|
||||||
loc=location.name,
|
|
||||||
src=self.location.name
|
if self.location:
|
||||||
)
|
msg += " (from {loc})".format(loc=str(self.location))
|
||||||
|
|
||||||
self.location = location
|
self.location = location
|
||||||
self.save()
|
self.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user