feat: mlogbin 和 update时cal_count_notok cal_mlog传False

This commit is contained in:
caoqianming 2025-06-13 15:56:43 +08:00
parent b9a7138e72
commit 4bd6eab9f4
2 changed files with 30 additions and 12 deletions

View File

@ -761,7 +761,7 @@ class MlogbInSerializer(CustomModelSerializer):
]
if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_pn_jgqbl(cal_mlog=True)
ins.cal_count_pn_jgqbl(cal_mlog=False)
return ins
class MlogbInUpdateSerializer(CustomModelSerializer):
@ -781,16 +781,22 @@ class MlogbInUpdateSerializer(CustomModelSerializer):
raise ParseError('生产日志已提交不可编辑')
ins:Mlogb = super().update(instance, validated_data)
if mlogbdefect is not None and ins.material_in.tracking == Material.MA_TRACKING_BATCH:
MlogbDefect.objects.filter(mlogb=ins).delete()
mlogb_defect_objects = [
MlogbDefect(**{**item, "mlogb": ins, "id": idWorker.get_id()})
for item in mlogbdefect if item["count"] > 0
]
if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_notok(cal_mlog=True)
# 找到对应的产出
MlogbDefect.objects.filter(mlogb=ins).delete()
mlogb_defect_objects = [
MlogbDefect(**{**item, "mlogb": ins, "id": idWorker.get_id()})
for item in mlogbdefect if item["count"] > 0
]
if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_notok(cal_mlog=False)
# 只有普通工序的才可联动
# route:Route = mlog.route
# if route and route.process and route.process.mtype == Process.PRO_NORMAL:
# mlogbout_qs = Mlogb.objects.filter(mlog=ins.mlog, mlogb_from=ins)
# if mlogbout_qs.count() == 1:
# mlogbout = mlogbout_qs.first()
# mlogbout.count_real = ins.count_use - ins.count_pn_jgqbl
return ins
class MlogbwCreateUpdateSerializer(CustomModelSerializer):
@ -906,7 +912,7 @@ class MlogbOutUpdateSerializer(CustomModelSerializer):
]
if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_notok(cal_mlog=True)
ins.cal_count_notok(cal_mlog=False)
return ins
def validate(self, attrs):

View File

@ -563,7 +563,13 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
if ins.mlog.submit_time is not None:
raise ParseError('生产日志已提交不可编辑')
ins.delete()
ins.mlog.cal_mlog_count_from_mlogb()
@transaction.atomic
def perform_update(self, serializer):
ins = serializer.save()
ins.mlog.cal_mlog_count_from_mlogb()
@transaction.atomic
def perform_create(self, serializer):
mlogbin: Mlogb = serializer.save()
@ -687,6 +693,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
Mlogbw.objects.get_or_create(wpr=wpr_, mlogb=mlogbout, defaults={"number": wpr_.number, "mlogbw_from": mlogbwin})
else:
raise ParseError("不支持生成产出物料!")
mlog.cal_mlog_count_from_mlogb()
@classmethod
def gen_number_with_rule(cls, rule, material_out:Material, gen_count=1):
@ -719,6 +726,11 @@ class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet):
queryset = Mlogb.objects.filter(material_out__isnull=False)
serializer_class = MlogbOutUpdateSerializer
@transaction.atomic
def perform_update(self, serializer):
ins:Mlogb = serializer.save()
ins.mlog.cal_mlog_count_from_mlogb()
class FmlogViewSet(CustomModelViewSet):
perms_map = {'get': '*', 'post': 'mlog.create', 'put': 'mlog.update', 'delete': 'mlog.delete'}