From b2d252875e3986b1ccdca23fcab84eb561a7d3e4 Mon Sep 17 00:00:00 2001 From: colaftc Date: Mon, 2 Feb 2026 19:16:38 +0800 Subject: [PATCH] fix: frozen excluded from stock api, refactor --- api_v1/views/stock_change_views/list.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api_v1/views/stock_change_views/list.py b/api_v1/views/stock_change_views/list.py index 1b328ed..728cc7b 100644 --- a/api_v1/views/stock_change_views/list.py +++ b/api_v1/views/stock_change_views/list.py @@ -308,6 +308,14 @@ class ListStockChangeDetailsView(StockChangeViewMixin, views.APIView): change_type = stock_models.StockChangeTypeEnum.REMOVE # 出库 # 查询库存变动明细,仅查询未被消耗的明细(consumed_by_detail为空) + active_freeze_statuses = [ + status + for status in stock_models.StockFreezeStatusEnum.values + if status not in { + stock_models.StockFreezeStatusEnum.CANCELLED, + stock_models.StockFreezeStatusEnum.COMPLETED, + } + ] details = stock_models.StockChangeDetail.objects.filter( stock_change_record__merchant_id=merchant_id, stock_change_record__warehouse_id=warehouse_id, @@ -315,7 +323,7 @@ class ListStockChangeDetailsView(StockChangeViewMixin, views.APIView): product_id=product_id, consumed_by_detail__isnull=True # 仅查询未被消耗的明细 ).exclude( - stock_freezes__status=stock_models.StockFreezeStatusEnum.FROZEN + stock_freezes__status__in=active_freeze_statuses ).select_related( 'stock_change_record', 'product'