feat: 添加mlogbw接口

This commit is contained in:
caoqianming 2025-01-02 15:36:55 +08:00
parent 0a2f671f0f
commit 426be9d805
3 changed files with 43 additions and 5 deletions

View File

@ -570,7 +570,11 @@ class MlogbInUpdateSerializer(CustomModelSerializer):
class MlogbwCreateUpdateSerializer(CustomModelSerializer):
class Meta:
model = Mlogbw
fields = ["number", "note"]
fields = ["id", "number", "note", "mlogb"]
def update(self, instance, validated_data):
validated_data.pop("mlogb")
return super().update(instance, validated_data)
class MlogbOutUpdateSerializer(CustomModelSerializer):

View File

@ -4,7 +4,7 @@ from rest_framework.routers import DefaultRouter
from apps.wpm.views import (SfLogViewSet, StLogViewSet, SfLogExpViewSet,
WMaterialViewSet, MlogViewSet, HandoverViewSet,
AttlogViewSet, OtherLogViewSet, MlogbViewSet, MlogbInViewSet,
MlogbOutViewSet, FmlogViewSet, BatchStViewSet)
MlogbOutViewSet, FmlogViewSet, BatchStViewSet, MlogbwViewSet)
from apps.wpm.datax import AnaViewSet
@ -26,7 +26,7 @@ router.register('attlog', AttlogViewSet, basename='attlog')
router.register('otherlog', OtherLogViewSet, basename='otherlog')
router.register('ana', AnaViewSet, basename='ana')
router.register('batchst', BatchStViewSet, basename='batchst')
router.register('mlogbw', MlogbwViewSet, basename='mlogbw')
urlpatterns = [
path(API_BASE_URL, include(router.urls)),
]

View File

@ -12,13 +12,15 @@ from apps.mtm.models import Material, Process
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
from .filters import StLogFilter, SfLogFilter, WMaterialFilter, MlogFilter, HandoverFilter, MlogbFilter, BatchStFilter
from .models import SfLog, SfLogExp, StLog, WMaterial, Mlog, Handover, Mlogb, AttLog, OtherLog, Fmlog, BatchSt
from .models import (SfLog, SfLogExp, StLog, WMaterial, Mlog, Handover, Mlogb,
Mlogbw, AttLog, OtherLog, Fmlog, BatchSt)
from .serializers import (SflogExpSerializer, SfLogSerializer, StLogSerializer, WMaterialSerializer, MlogRevertSerializer,
MlogSerializer, MlogRelatedSerializer, DeptBatchSerializer, HandoverSerializer, HandoverUpdateSerializer,
GenHandoverSerializer, GenHandoverWmSerializer, MlogAnaSerializer,
AttLogSerializer, OtherLogSerializer, MlogInitSerializer, MlogChangeSerializer,
MlogbDetailSerializer, MlogbInSerializer, MlogbInUpdateSerializer,
MlogbOutUpdateSerializer, FmlogSerializer, FmlogUpdateSerializer, BatchStSerializer)
MlogbOutUpdateSerializer, FmlogSerializer, FmlogUpdateSerializer, BatchStSerializer,
MlogbwCreateUpdateSerializer)
from .services import mlog_submit, handover_submit, mlog_revert
from apps.wpm.services import mlog_submit_validate, generate_new_batch
from apps.wf.models import State
@ -527,3 +529,35 @@ class BatchStViewSet(ListModelMixin, CustomGenericViewSet):
ordering = ["batch"]
filterset_class = BatchStFilter
class MlogbwViewSet(CustomModelViewSet):
perms_map = {"get": "*", "post": "mlog.update", "put": "mlog.update", "delete": "mlog.update"}
queryset = Mlogbw.objects.all()
serializer_class = MlogbwCreateUpdateSerializer
filterset_fields = ['mlogb']
ordering = ["number"]
ordering_fields = ["number", "create_time"]
def filter_queryset(self, queryset):
if not self.detail and not self.request.query_params.get('mlogb', None):
raise ParseError('请指定所属日志明细')
return super().filter_queryset(queryset)
def cal_mlogb_count(self, mlogb):
count_real = Mlogbw.objects.filter(mlogb=mlogb).count()
mlogb.count_real = count_real
mlogb.save()
@transaction.atomic
def perform_create(self, serializer):
ins = super().perform_create(serializer)
self.cal_mlogb_count(ins.mlogb)
return ins
@transaction.atomic
def perform_destroy(self, instance):
mlogb = instance.mlogb
super().perform_destroy(instance)
self.cal_mlogb_count(mlogb)