From 306a981ca19338a18e908fc0d2aefa8202677fd0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 11 May 2019 00:40:37 +1000 Subject: [PATCH] Allow partial-quantity move - Automatically split out the stock - Move the specified quantity to the new location --- InvenTree/stock/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index d6c19b2bfb..f24516bfcb 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -323,6 +323,23 @@ class StockItem(models.Model): # Remove the specified quantity from THIS stock item self.take_stock(quantity, user, 'Split {n} items into new stock item'.format(n=quantity)) + @transaction.atomic + def move(self, location, notes, user, **kwargs): + """ Move part to a new location. + + Args: + location: Destination location (cannot be null) + notes: User notes + user: Who is performing the move + kwargs: + quantity: If provided, override the quantity (default = total stock quantity) + """ + + quantity = int(kwargs.get('quantity', self.quantity)) + + if quantity <= 0: + return False + if location is None: # TODO - Raise appropriate error (cannot move to blank location) return False @@ -330,6 +347,13 @@ class StockItem(models.Model): # TODO - Raise appropriate error (cannot move to same location) return False + # Test for a partial movement + if quantity < self.quantity: + # We need to split the stock! + + # Leave behind certain quantity + self.splitStock(self.quantity - quantity, user) + msg = "Moved to {loc}".format(loc=str(location)) if self.location: