feat:物料新增set_safe接口设置安全库存上下限

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-07-15 08:18:23 +08:00
parent 3c0088d18f
commit b541b46d3d
1 changed files with 14 additions and 1 deletions

View File

@ -80,6 +80,19 @@ class MaterialViewSet(CustomModelViewSet):
obj.save() obj.save()
return Response() 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': '*'}) @action(methods=['get'], detail=False, serializer_class=Serializer, perms_map={'get': '*'})
def cates(self, request, *args, **kwargs): def cates(self, request, *args, **kwargs):
res = Material.objects.exclude(cate='').exclude(cate=None).values_list('cate', flat=True).distinct() res = Material.objects.exclude(cate='').exclude(cate=None).values_list('cate', flat=True).distinct()