feat: 工艺步骤中辅料使用的校验

This commit is contained in:
caoqianming 2025-09-08 14:29:19 +08:00
parent 2e2ac78bad
commit 8cc9c46a95
1 changed files with 9 additions and 5 deletions

View File

@ -10,7 +10,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, Route, Mgroup, RoutePack
from apps.mtm.models import Material, Process, Route, Mgroup, RoutePack, RouteMat
from apps.utils.viewsets import CustomGenericViewSet, CustomModelViewSet
from apps.utils.mixins import CustomListModelMixin, BulkCreateModelMixin, ComplexQueryMixin
@ -702,13 +702,15 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
material_out:Material = material_in if is_fix else route.material_out
if material_out is None:
raise ParseError('产物不可为空')
if route and route.material_in != material_in:
raise ParseError('工艺步骤输入与实际输入不符')
# 如果是主要输入物料且是主批次,才需生成输出
if is_fix is False and route and route.material_in != material_in or mlogbin.parent is not None:
# 如果次批且是结合工序,需要触发产生输出
if mtype and mtype == Process.PRO_DIV:
if mlogbin_parent is not None:
if mtype and mtype == Process.PRO_MERGE:
pass
else:
return
wm_in: WMaterial = mlogbin.wm_in
@ -803,7 +805,9 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
count_pn_jgqbl_sum = Mlogb.objects.filter(Q(id=mlogbin_parent.id)|Q(parent=mlogbin_parent), material_in=mlogbin.material_in).aggregate(Sum('count_pn_jgqbl'))['count_pn_jgqbl__sum'] or 0
xcount = math.floor( (count_use_sum-count_pn_jgqbl_sum) / div_number)
else:
raise ParseError("暂不支持主次物料不一致")
# 获取可用的辅料
if not RouteMat.objects.filter(material=mlogbin.material_in, route=route).exists():
raise ParseError("工艺步骤中不存在该辅料")
# 使用主批作为后续引用
mlogbin = mlogbin_parent
else: