mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 19:15:41 +00:00
Enforce 'notes' field for StockItem move
- Better error handling for StockItem.move
This commit is contained in:
@ -153,6 +153,9 @@ class StockMove(APIView):
|
||||
|
||||
errors = []
|
||||
|
||||
if u'notes' not in data:
|
||||
errors.append({'notes': 'Notes field must be supplied'})
|
||||
|
||||
for pid in part_list:
|
||||
try:
|
||||
part = StockItem.objects.get(pk=pid)
|
||||
@ -164,7 +167,7 @@ class StockMove(APIView):
|
||||
raise ValidationError(errors)
|
||||
|
||||
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(
|
||||
n=len(parts),
|
||||
|
@ -221,13 +221,17 @@ class StockItem(models.Model):
|
||||
@transaction.atomic
|
||||
def move(self, location, notes, user):
|
||||
|
||||
if location.pk == self.location.pk:
|
||||
return False # raise forms.ValidationError("Cannot move item to its current location")
|
||||
if location is None:
|
||||
# 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(
|
||||
loc=location.name,
|
||||
src=self.location.name
|
||||
)
|
||||
msg = "Moved to {loc}".format(loc=str(location))
|
||||
|
||||
if self.location:
|
||||
msg += " (from {loc})".format(loc=str(self.location))
|
||||
|
||||
self.location = location
|
||||
self.save()
|
||||
|
Reference in New Issue
Block a user