From 3cef5c93ce8a8d04d9233a478cc78f5a46d87200 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:18:08 +1000 Subject: [PATCH] Improve stock item splitting --- InvenTree/stock/models.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 37a2323992..6ae7803d10 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -492,20 +492,12 @@ class StockItem(models.Model): return # Create a new StockItem object, duplicating relevant fields - new_stock = StockItem.objects.create( - part=self.part, - quantity=quantity, - supplier_part=self.supplier_part, - location=self.location, - notes=self.notes, - URL=self.URL, - batch=self.batch, - delete_on_deplete=self.delete_on_deplete - ) - + # Nullify the PK so a new record is created + new_stock = StockItem.objects.get(pk=self.pk) + new_stock.quantity = quantity new_stock.save() - # Copy the transaction history + # Copy the transaction history of this part into the new one new_stock.copyHistoryFrom(self) # Add a new tracking item for the new stock item