From b4955a93c7ccee633fb8c4bcffddc3dfc35eeee5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 27 Dec 2024 08:40:59 +0000 Subject: [PATCH] Use custom status values in stock operations --- src/backend/InvenTree/stock/models.py | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index a8baa6c475..20d568e4bb 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -2137,6 +2137,12 @@ class StockItem( else: tracking_info['location'] = location.pk + status = kwargs.pop('status', None) or kwargs.pop('status_custom_key', None) + + if status and status != self.status: + self.status_custom_key = status + tracking_info['status'] = status + # Optional fields which can be supplied in a 'move' call for field in StockItem.optional_transfer_fields(): if field in kwargs: @@ -2214,8 +2220,16 @@ class StockItem( if count < 0: return False + tracking_info = {} + + status = kwargs.pop('status', None) or kwargs.pop('status_custom_key', None) + + if status and status != self.status: + self.status_custom_key = status + tracking_info['status'] = status + if self.updateQuantity(count): - tracking_info = {'quantity': float(count)} + tracking_info['quantity'] = float(count) self.stocktake_date = InvenTree.helpers.current_date() self.stocktake_user = user @@ -2269,8 +2283,17 @@ class StockItem( if quantity <= 0: return False + tracking_info = {} + + status = kwargs.pop('status', None) or kwargs.pop('status_custom_key', None) + + if status and status != self.status: + self.status_custom_key = status + tracking_info['status'] = status + if self.updateQuantity(self.quantity + quantity): - tracking_info = {'added': float(quantity), 'quantity': float(self.quantity)} + tracking_info['added'] = float(quantity) + tracking_info['quantity'] = float(self.quantity) # Optional fields which can be supplied in a 'stocktake' call for field in StockItem.optional_transfer_fields(): @@ -2314,8 +2337,17 @@ class StockItem( if quantity <= 0: return False + deltas = {} + + status = kwargs.pop('status', None) or kwargs.pop('status_custom_key', None) + + if status and status != self.status: + self.status_custom_key = status + deltas['status'] = status + if self.updateQuantity(self.quantity - quantity): - deltas = {'removed': float(quantity), 'quantity': float(self.quantity)} + deltas['removed'] = float(quantity) + deltas['quantity'] = float(self.quantity) if location := kwargs.get('location'): deltas['location'] = location.pk