feat: 快速报工的bug

This commit is contained in:
caoqianming 2025-09-12 09:11:35 +08:00
parent 9d692b4d5d
commit aa72b0780a
1 changed files with 33 additions and 28 deletions

View File

@ -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)
# 如果是输入且输出追踪到个,需同步创建