From 3e56fa7390f347a16e5acc087f36fe1c50c005d4 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 19 Apr 2024 14:32:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=89=A9=E6=96=99=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E8=BF=9B=E8=A1=8C=E6=A0=A1=E9=AA=8C=E5=92=8C=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=95=B0=E6=8D=AE=E7=9F=AB=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mtm/correct.py | 12 ++++++++++++ apps/mtm/views.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/apps/mtm/correct.py b/apps/mtm/correct.py index d668c086..7ea57792 100644 --- a/apps/mtm/correct.py +++ b/apps/mtm/correct.py @@ -1,5 +1,17 @@ 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(): """ 矫正物料分类/ 光子的棒管 diff --git a/apps/mtm/views.py b/apps/mtm/views.py index 28f03da0..b40de2b9 100644 --- a/apps/mtm/views.py +++ b/apps/mtm/views.py @@ -15,6 +15,7 @@ from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin from rest_framework.serializers import Serializer from django.db import transaction +from django.db.models import Q # Create your views here. @@ -34,6 +35,14 @@ class MaterialViewSet(CustomModelViewSet): ordering_fields = ['name', 'model', 'specification', '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'}) @transaction.atomic def daoru(self, request, *args, **kwargs):