From b541b46d3dba9929abf28f244bf0a8a60b822d21 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 15 Jul 2026 08:18:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=89=A9=E6=96=99=E6=96=B0=E5=A2=9Eset=5F?= =?UTF-8?q?safe=E6=8E=A5=E5=8F=A3=E8=AE=BE=E7=BD=AE=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E4=B8=8A=E4=B8=8B=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/mtm/views.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/mtm/views.py b/apps/mtm/views.py index 6017b495..5f3d4788 100644 --- a/apps/mtm/views.py +++ b/apps/mtm/views.py @@ -79,7 +79,20 @@ class MaterialViewSet(CustomModelViewSet): 'week_esitimate_consume', None) obj.save() return Response() - + + @action(methods=['put'], detail=True, serializer_class=Serializer, perms_map={'put': '*'}) + @transaction.atomic + def set_safe(self, request, *args, **kwargs): + """设置安全库存上下限 + + count_safe 为下限, count_safe_upper 为上限 + """ + obj: Material = self.get_object() + obj.count_safe = request.data.get('count_safe', None) + obj.count_safe_upper = request.data.get('count_safe_upper', None) + obj.save(update_fields=['count_safe', 'count_safe_upper', 'update_time']) + return Response() + @action(methods=['get'], detail=False, serializer_class=Serializer, perms_map={'get': '*'}) def cates(self, request, *args, **kwargs): res = Material.objects.exclude(cate='').exclude(cate=None).values_list('cate', flat=True).distinct()