diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 42c3872e..28e5a2f3 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -755,7 +755,7 @@ class HandoverSerializer(CustomModelSerializer): for item in Wpr.get_qs_by_wm(wm): Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb) elif handoverbw: - raise ParseError("暂不支持") + Handoverbwserializer(data=handoverbw, many=True, context=self.context).save() else: raise ParseError(f'请提供交接物料明细编号') return ins @@ -780,7 +780,8 @@ class HandoverSerializer(CustomModelSerializer): Handoverbw.objects.get_or_create(wpr=item, handoverb=handoverb, defaults={"number": item.number}) elif handoverbw: - raise ParseError("暂不支持") + Handoverbw.objects.filter(handoverb=hb).delete() + Handoverbwserializer(data=handoverbw, many=True, context=self.context).save() else: raise ParseError(f'请提供交接物料明细编号') Handoverb.objects.filter(handover=instance).exclude(wm__in=wmIds).delete() diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 6c46889f..6d6aa05e 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -8,7 +8,7 @@ from django.db.models import Sum from django.utils import timezone from apps.system.models import User -from apps.mtm.models import Material, Process +from apps.mtm.models import Material, Process, Route from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet from .filters import StLogFilter, SfLogFilter, WMaterialFilter, MlogFilter, HandoverFilter, MlogbFilter, BatchStFilter @@ -480,7 +480,8 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust @transaction.atomic def perform_create(self, serializer): mlogbin: Mlogb = serializer.save() - mlog: Mlog = mlogbin.mlog + mlog:Mlog = mlogbin.mlog + route:Route = mlog.route # 创建输出 # 以及mlogbw if mlogbin.mtask and mlogbin.material_in: @@ -495,17 +496,26 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust } m_dict['batch'] = generate_new_batch(mlogbin.batch, mlog) wm_in: WMaterial = mlogbin.wm_in - mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults={"batch_ofrom": wm_in.batch_ofrom, - "material_ofrom": wm_in.material_ofrom}) + d_count_real = 0 + d_count_ok = 0 + if route: + if route.process.mtype == Process.PRO_NORMAL: + d_count_real = mlogbin.count_use + d_count_ok = mlogbin.count_use + elif route.process.mtype == Process.PRO_DIV: + d_count_real = mlogbin.count_use*route.div_number + d_count_ok = mlogbin.count_use*route.div_number + elif route.process.mtype == Process.PRO_MERGE: + d_count_real = 1 + d_count_ok = 1 + mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults= + {"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, + "count_real": d_count_real, "count_ok": d_count_ok}) mlogbin.mlogb_to = mlogbout mlogbin.save() if material_in.tracking == Material.MA_TRACKING_SINGLE: + m_out_t = material_out.tracking if mlogbin.count_use == wm_in.count: # 自动创建mlogbw - # 先暂时不考虑合并与拆分 - mlogbout.count_real = wm_in.count - mlogbout.count_ok = wm_in.count - mlogbout.save() - m_out_t = material_out.tracking for wpr in Wpr.objects.filter(wm=wm_in).order_by("number"): Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbin, defaults={"number": wpr.number}) if m_out_t == Material.MA_TRACKING_SINGLE: