From edd6f254111ee05a199923ce28cc24cce6b6b3e4 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 7 Feb 2024 20:11:46 +1100 Subject: [PATCH] Fix for issue 6442 (#6443) - Add null option to status field for stock adjustment - Prevent stock adjustments from setting status to OK --- InvenTree/stock/serializers.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 05676c6acd..c5755eeb20 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -1193,6 +1193,14 @@ class StockMergeSerializer(serializers.Serializer): ) +def stock_item_adjust_status_options(): + """Return a custom set of options for the StockItem status adjustment field. + + In particular, include a Null option for the status field. + """ + return [(None, _('No Change'))] + InvenTree.status_codes.StockStatus.items() + + class StockAdjustmentItemSerializer(serializers.Serializer): """Serializer for a single StockItem within a stock adjument request. @@ -1235,8 +1243,8 @@ class StockAdjustmentItemSerializer(serializers.Serializer): ) status = serializers.ChoiceField( - choices=InvenTree.status_codes.StockStatus.items(), - default=InvenTree.status_codes.StockStatus.OK.value, + choices=stock_item_adjust_status_options(), + default=None, label=_('Status'), help_text=_('Stock item status code'), required=False, @@ -1373,8 +1381,8 @@ class StockTransferSerializer(StockAdjustmentSerializer): kwargs = {} for field_name in StockItem.optional_transfer_fields(): - if field_name in item: - kwargs[field_name] = item[field_name] + if field_value := item.get(field_name, None): + kwargs[field_name] = field_value stock_item.move( location, notes, request.user, quantity=quantity, **kwargs