39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
| from django.shortcuts import render
 | |
| from rest_framework.mixins import ListModelMixin
 | |
| from rest_framework.exceptions import ParseError
 | |
| 
 | |
| from apps.inm.models import WareHouse, MaterialBatch
 | |
| from apps.inm.serializers import MaterialBatchSerializer, WareHourseSerializer
 | |
| from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
 | |
| 
 | |
| 
 | |
| # Create your views here.
 | |
| class WarehouseVIewSet(CustomModelViewSet):
 | |
|     """
 | |
|     list: 仓库信息
 | |
| 
 | |
|     仓库信息
 | |
|     """
 | |
|     queryset = WareHouse.objects.all()
 | |
|     serializer_class = WareHourseSerializer
 | |
|     search_fields = ['name', 'number', 'place']
 | |
|     ordering = ['create_time']
 | |
| 
 | |
|     def perform_destroy(self, instance):
 | |
|         if MaterialBatch.objects.filter(warehouse=instance).exclude(count=0).exists():
 | |
|             raise ParseError('该仓库存在物料')
 | |
|         instance.delete()
 | |
| 
 | |
| 
 | |
| class MaterialBatchViewSet(ListModelMixin, CustomGenericViewSet):
 | |
|     """
 | |
|     list: 物料批次
 | |
| 
 | |
|     物料批次
 | |
|     """
 | |
|     perms_map = {'get': '*'}
 | |
|     queryset = MaterialBatch.objects.all()
 | |
|     serializer_class = MaterialBatchSerializer
 | |
|     select_related_fields = ['warehouse', 'material']
 | |
|     filterset_fields = ['warehouse', 'material']
 | |
|      |