From aa72b0780a7fce123b5d40f99c949e0f5c2bb0e1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 12 Sep 2025 09:11:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E9=80=9F=E6=8A=A5=E5=B7=A5?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index dda7f01c..962a7d21 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -454,6 +454,7 @@ class MlogViewSet(CustomModelViewSet): return Response(res) @action(methods=['post'], detail=False, perms_map={'post': 'mlog.create'}, serializer_class=MlogQuickSerializer) + @transaction.atomic def quick(self, request, *args, **kwargs): """快速创建日志 @@ -848,35 +849,36 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust mlogbin = mlogbin_parent else: xcount = math.floor( (mlogbin.count_use-mlogbin.count_pn_jgqbl) / div_number) - d_count_real = xcount - d_count_ok = xcount - number_to_batch = process.number_to_batch - if not number_to_batch: - mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok, "count_ok_full": d_count_ok})) - mlogbout.count_json_from = mlogbin.count_json_from - mlogbout.save(update_fields=["count_json_from"]) - wpr_number_rule = process.wpr_number_rule - if material_out.tracking == Material.MA_TRACKING_SINGLE: - number = mlogbin.batch - if mlogbin.number_from: - number = mlogbin.number_from - if d_count_real == 1: - if wpr_number_rule: - number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog) - if number_to_batch: - mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number})) - Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout) - else: - if wpr_number_rule: - number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real) - for i in range(d_count_real): + if xcount >0: + d_count_real = xcount + d_count_ok = xcount + number_to_batch = process.number_to_batch + if not number_to_batch: + mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok, "count_ok_full": d_count_ok})) + mlogbout.count_json_from = mlogbin.count_json_from + mlogbout.save(update_fields=["count_json_from"]) + wpr_number_rule = process.wpr_number_rule + if material_out.tracking == Material.MA_TRACKING_SINGLE: + number = mlogbin.batch + if mlogbin.number_from: + number = mlogbin.number_from + if d_count_real == 1: if wpr_number_rule: - numberx = number_list[i] - else: - numberx = f'{number}-{i+1}' + number = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog) if number_to_batch: - mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": numberx})) - Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout) + mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": number})) + Mlogbw.objects.get_or_create(number=number, mlogb=mlogbout) + else: + if wpr_number_rule: + number_list = MlogbInViewSet.gen_number_with_rule(wpr_number_rule, material_out, mlog, gen_count=d_count_real) + for i in range(d_count_real): + if wpr_number_rule: + numberx = number_list[i] + else: + numberx = f'{number}-{i+1}' + if number_to_batch: + mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": 1, "count_ok": 1, "count_ok_full": 1, "batch": numberx})) + Mlogbw.objects.get_or_create(number=numberx, mlogb=mlogbout) else: raise ParseError("不支持生成产出物料!") mlog.cal_mlog_count_from_mlogb() @@ -896,7 +898,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust m_model = material_out.model # 按生产日志查询 wpr = Wpr.objects.filter(wpr_mlogbw__mlogb__material_out__isnull=False, - wpr_mlogbw__mlogb__mlog__mgroup=mlog.mgroup, + wpr_mlogbw__mlogb__mlog__mgroup__process=mlog.mgroup.process, wpr_mlogbw__mlogb__mlog__is_fix=False, wpr_mlogbw__mlogb__mlog__submit_time__isnull=False, wpr_mlogbw__mlogb__mlog__handle_date__year=c_year, @@ -997,7 +999,10 @@ class MlogbwViewSet(CustomModelViewSet): else: if mlog != ins.mlogb.mlog: raise ParseError("所有记录必须属于同一张日志") + wpr:Wpr = ins.wpr mlogb:Mlogb = ins.mlogb + if wpr.wm != mlogb.wm_in: + raise ParseError("单个与所属批次不一致") route:Route = mlogb.route if mlogb.route else mlog.route Mlogbw.cal_count_notok(mlogb) # 如果是输入且输出追踪到个,需同步创建