feat: mlog quick增加wprs_in传参

This commit is contained in:
caoqianming 2025-09-26 14:07:14 +08:00
parent 34e217e468
commit fb71f0697a
2 changed files with 27 additions and 8 deletions

View File

@ -721,6 +721,7 @@ class CountJsonFromSerializer(serializers.Serializer):
class MlogbInSerializer(CustomModelSerializer):
mlogbdefect = MlogbDefectSerializer(many=True, required=False)
count_json_from = CountJsonFromSerializer(required=False, many=True)
wprs_in = serializers.ListField(child=serializers.CharField(), label="单个ID的列表", required=False)
class Meta:
model = Mlogb
@ -878,7 +879,9 @@ class MlogbwCreateUpdateSerializer(CustomModelSerializer):
if wpr:
mlogb: Mlogb = validated_data["mlogb"]
if Mlogbw.objects.filter(mlogb=mlogb, wpr=wpr).exists():
raise ParseError('该产品已选入')
raise ParseError(f'{wpr.number}-该产品已选入')
if Mlogbw.objects.filter(mlogb__mlog__submit_time__isnull=True, wpr=wpr).exists():
raise ParseError(f'{wpr.number}-该产品已在其他日志中选入')
ftest_data = validated_data.pop("ftest", None)
mlogbw = super().create(validated_data)
if ftest_data:
@ -1520,6 +1523,7 @@ class MlogQuickSerializer(serializers.Serializer):
team = serializers.CharField(label="班组ID", required=False)
equipment = serializers.CharField(label="设备ID", required=False)
wm_in = serializers.CharField(label="输入车间库存ID")
wprs_in = serializers.ListField(child=serializers.CharField(), label="单个ID的列表", required=False)
count_use = serializers.IntegerField(label="领用数量")
is_fix = serializers.BooleanField(label="是否返修")
mgroup = serializers.CharField(label="工段ID")

View File

@ -481,10 +481,11 @@ class MlogViewSet(CustomModelViewSet):
mlogbin_data["mtask"] = vdata["mtask"]
if "route" in vdata:
mlogbin_data["route"] = vdata["route"]
wprIds = vdata.get("wprs_in", [])
sr_2 = MlogbInSerializer(data=mlogbin_data)
sr_2.is_valid(raise_exception=True)
mlogbin = sr_2.save()
MlogbInViewSet.p_create_after(mlogbin, skip_mlogbw=True)
MlogbInViewSet.p_create_after(mlogbin, wprIds=wprIds)
return Response({"mlog": str(mlog.id), "mlogbin": str(mlogbin.id)})
class HandoverViewSet(CustomModelViewSet):
@ -714,7 +715,7 @@ class MlogbInViewSet(BulkCreateModelMixin, BulkUpdateModelMixin, BulkDestroyMode
mlog.cal_mlog_count_from_mlogb()
@classmethod
def p_create_after(cls, mlogbin:Mlogb, skip_mlogbw=False):
def p_create_after(cls, mlogbin:Mlogb, wprIds:list=[]):
mlogbin_parent:Mlogb = mlogbin.parent
mlog:Mlog = mlogbin.mlog
mgroup:Mgroup = mlog.mgroup
@ -743,12 +744,25 @@ class MlogbInViewSet(BulkCreateModelMixin, BulkUpdateModelMixin, BulkDestroyMode
wm_in: WMaterial = mlogbin.wm_in
if material_in.tracking == Material.MA_TRACKING_SINGLE and skip_mlogbw is False: # 自动创建mlogbw
if material_in.tracking == Material.MA_TRACKING_SINGLE: # 自动创建mlogbw
if wprIds:
wprs_can_use_qs = Wpr.objects.filter(id__in=wprIds).exclude(wpr_mlogbw__mlogb__mlog__submit_time__isnull=True).order_by("number")
wm_ids = wprs_can_use_qs.values_list("wm__id", flat=True).distinct()
if len(wm_ids) == 1 and wm_ids[0] == wm_in.id:
pass
else:
raise ParseError("单个产品列表不属于当前批次")
for wpr in wprs_can_use_qs:
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbin, defaults={"number": wpr.number})
mlogbin.count_use = Mlogbw.objects.filter(mlogb=mlogbin).count()
mlogbin.save(update_fields=["count_use"])
else:
wprs_can_use_qs = Wpr.objects.filter(wm=wm_in).exclude(wpr_mlogbw__mlogb__mlog__submit_time__isnull=True).order_by("number")
if wprs_can_use_qs.count() == mlogbin.count_use:
for wpr in wprs_can_use_qs:
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbin, defaults={"number": wpr.number})
# if qct is None:
# mlog.qct = Qct.get(material_out, "process")
# mlog.save(update_fields = ["qct"])
@ -892,9 +906,10 @@ class MlogbInViewSet(BulkCreateModelMixin, BulkUpdateModelMixin, BulkDestroyMode
def perform_create(self, serializer):
vdata = serializer.validated_data
mlogbin: Mlogb = serializer.save()
MlogViewSet.lock_and_check_can_update(mlogbin.mlog)
MlogbInViewSet.p_create_after(mlogbin)
MlogbInViewSet.p_create_after(mlogbin, wprIds=vdata.get('wprIds', []))
@classmethod
def gen_number_with_rule(cls, rule, material_out:Material, mlog:Mlog, gen_count=1):