feat: 物料删除时进行校验和相应的数据矫正
This commit is contained in:
parent
196209d60c
commit
3e56fa7390
|
@ -1,5 +1,17 @@
|
||||||
from .models import Material
|
from .models import Material
|
||||||
|
|
||||||
|
def correct_material_deleted():
|
||||||
|
"""
|
||||||
|
矫正物料是否被删除
|
||||||
|
"""
|
||||||
|
from apps.inm.models import MaterialBatch
|
||||||
|
ms = MaterialBatch.objects.all().values('material').distinct()
|
||||||
|
for m in ms:
|
||||||
|
material = Material.objects.get_queryset(all=True).get(id=m['material'])
|
||||||
|
if material.is_deleted:
|
||||||
|
material.is_deleted = False
|
||||||
|
material.save(update_fields=['is_deleted'])
|
||||||
|
|
||||||
def correct_material_cate():
|
def correct_material_cate():
|
||||||
"""
|
"""
|
||||||
矫正物料分类/ 光子的棒管
|
矫正物料分类/ 光子的棒管
|
||||||
|
|
|
@ -15,6 +15,7 @@ from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
|
||||||
from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin
|
from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin
|
||||||
from rest_framework.serializers import Serializer
|
from rest_framework.serializers import Serializer
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
@ -34,6 +35,14 @@ class MaterialViewSet(CustomModelViewSet):
|
||||||
ordering_fields = ['name', 'model', 'specification',
|
ordering_fields = ['name', 'model', 'specification',
|
||||||
'type', 'process', 'process__sort', 'sort', 'id', 'number']
|
'type', 'process', 'process__sort', 'sort', 'id', 'number']
|
||||||
|
|
||||||
|
def perform_destroy(self, instance):
|
||||||
|
from apps.inm.models import MaterialBatch
|
||||||
|
if MaterialBatch.objects.filter(material=instance).exists():
|
||||||
|
raise ParseError('该物料有库存!')
|
||||||
|
if Route.objects.filter(Q(material=instance) | Q(material_in=instance) | Q(material_out=instance)).exists():
|
||||||
|
raise ParseError('该物料有工艺路线!')
|
||||||
|
return super().perform_destroy(instance)
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, serializer_class=Serializer, perms_map={'post': 'material.create'})
|
@action(methods=['post'], detail=False, serializer_class=Serializer, perms_map={'post': 'material.create'})
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def daoru(self, request, *args, **kwargs):
|
def daoru(self, request, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue