2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 03:30:54 +00:00

Enforce 'notes' field for StockItem move

- Better error handling for StockItem.move
This commit is contained in:
Oliver Walters
2019-04-25 23:01:03 +10:00
parent 38fa89d1da
commit 757cd539b2
3 changed files with 34 additions and 13 deletions

View File

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