feat: mlogbin支持mtask非必填

This commit is contained in:
caoqianming 2025-02-19 14:29:55 +08:00
parent 5f0d34f9c3
commit c585f2fc11
2 changed files with 5 additions and 5 deletions

View File

@ -530,20 +530,20 @@ class MlogbInSerializer(CustomModelSerializer):
model = Mlogb
fields = ['id', 'mlog', 'mtask', 'wm_in', 'count_use', 'count_pn_jgqbl',
'count_break', 'note', "parent"]
extra_kwargs = {'count_use': {'required': True}, 'mtask': {'required': True},
extra_kwargs = {'count_use': {'required': True}, 'mtask': {'required': False},
'wm_in': {'required': True, "allow_empty": False}}
def validate(self, attrs):
mlog: Mlog = attrs['mlog']
mtask: Mtask = attrs['mtask']
if mtask.state != Mtask.MTASK_ASSGINED:
mtask: Mtask = attrs.get("mtask", None)
if mtask and mtask.state != Mtask.MTASK_ASSGINED:
raise ValidationError('该任务非下达中不可选择')
wm_in: WMaterial = attrs['wm_in']
if wm_in.state in [WMaterial.WM_OK, WMaterial.WM_REPAIR]:
pass
else:
raise ValidationError('非合格/返修品不可使用')
if mlog.route != mtask.route:
if mtask and mlog.route != mtask.route:
raise ValidationError('工序不匹配')
route = mlog.route
attrs['material_in'] = wm_in.material

View File

@ -542,7 +542,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
mlog:Mlog = mlogbin.mlog
route:Route = mlog.route
# 以及mlogbw
if mlogbin.mtask and mlogbin.material_in:
if mlogbin.material_in:
material_in:Material = mlogbin.material_in
material_out:Material = mlog.material_out
if material_out is None: