feat: 单填写mlog支持返工
This commit is contained in:
parent
6033216869
commit
d6fe5af39c
|
@ -359,6 +359,9 @@ class MlogSerializer(CustomModelSerializer):
|
|||
with transaction.atomic():
|
||||
mlogb = validated_data.pop('mlogb', [])
|
||||
instance: Mlog = super().create(validated_data)
|
||||
## 返工没有加工前不良
|
||||
if instance.is_fix and instance.count_pn_jgqbl >0:
|
||||
raise ParseError("返工不支持加工前不良")
|
||||
# 自动生成mlogb
|
||||
batch_in = instance.batch
|
||||
wm_in = instance.wm_in
|
||||
|
@ -457,6 +460,9 @@ class MlogSerializer(CustomModelSerializer):
|
|||
with transaction.atomic():
|
||||
mlogb = validated_data.pop('mlogb', [])
|
||||
instance: Mlog = super().update(instance, validated_data)
|
||||
## 返工没有加工前不良
|
||||
if instance.is_fix and instance.count_pn_jgqbl >0:
|
||||
raise ParseError("返工不支持加工前不良")
|
||||
wm_in = instance.wm_in
|
||||
batch_in = instance.batch
|
||||
if wm_in:
|
||||
|
@ -541,33 +547,37 @@ class MlogSerializer(CustomModelSerializer):
|
|||
attrs['mtype'] = Mlog.MTYPE_SELF # 默认为自生产
|
||||
fmlog:Fmlog = attrs.get('fmlog', None)
|
||||
mtaskb = attrs.get('mtaskb', None)
|
||||
wm_in: WMaterial = attrs.get('wm_in', None)
|
||||
if fmlog:
|
||||
attrs['fill_way'] = Mlog.MLOG_12
|
||||
wm_in: WMaterial = attrs.get('wm_in', None)
|
||||
if wm_in:
|
||||
pass
|
||||
else:
|
||||
if not wm_in:
|
||||
raise ParseError('未提供消耗的车间物料')
|
||||
attrs['mgroup'] = fmlog.mgroup
|
||||
attrs['is_fix'] = fmlog.is_fix
|
||||
attrs['mtask'] = fmlog.mtask
|
||||
attrs['route'] = fmlog.route
|
||||
attrs['mtype'] = fmlog.mgroup.mtype
|
||||
if attrs['mtask'] and attrs['mtask'].route:
|
||||
attrs['route'] = attrs['mtask'].route
|
||||
# if attrs['mtask'].mtaskb and mtaskb is None:
|
||||
# raise ParseError('子任务不能为空')
|
||||
if mtaskb and mtaskb.mtask != fmlog.mtask:
|
||||
raise ParseError('子任务不一致')
|
||||
if wm_in.state in [WMaterial.WM_OK]:
|
||||
pass
|
||||
else:
|
||||
if wm_in:
|
||||
attrs["material_in"] = wm_in.material
|
||||
attrs["batch"] = wm_in.batch
|
||||
if attrs["is_fix"]:
|
||||
attrs["material_out"] = attrs["material_in"]
|
||||
if wm_in.state in [WMaterial.WM_REPAIR, WMaterial.WM_NOTOK]:
|
||||
pass
|
||||
else:
|
||||
raise ParseError('返修或复检需使用返修品/不合格品')
|
||||
elif wm_in.state != WMaterial.WM_OK:
|
||||
raise ParseError('非合格品不可使用')
|
||||
if wm_in.material != attrs['route'].material_in:
|
||||
if attrs['route'] and wm_in.material != attrs['route'].material_in:
|
||||
raise ParseError('消耗物料与工艺步骤不一致')
|
||||
if attrs['mtype'] == Mlog.MTYPE_OUT:
|
||||
supplier = attrs.get('supplier', None)
|
||||
if not supplier:
|
||||
raise ParseError('外协必须选择外协单位')
|
||||
if attrs['mtype'] == Mlog.MTYPE_OUT:
|
||||
supplier = attrs.get('supplier', None)
|
||||
if not supplier:
|
||||
raise ParseError('外协必须选择外协单位')
|
||||
mtask = attrs.get('mtask', None)
|
||||
count_notok = 0
|
||||
for i in attrs:
|
||||
|
@ -588,8 +598,6 @@ class MlogSerializer(CustomModelSerializer):
|
|||
else:
|
||||
if attrs.get('work_end_time', None):
|
||||
attrs['handle_date'] = localdate(attrs['work_end_time'])
|
||||
elif attrs.get('work_start_time', None):
|
||||
attrs['handle_date'] = localdate(attrs['work_start_time'])
|
||||
mtaskb: Mtaskb = attrs.get('mtaskb', None)
|
||||
if mtaskb:
|
||||
mtask = mtaskb.mtask
|
||||
|
@ -599,6 +607,8 @@ class MlogSerializer(CustomModelSerializer):
|
|||
attrs['mgroup'] = mtask.mgroup
|
||||
attrs['material_in'] = mtask.material_in
|
||||
material_out = mtask.material_out
|
||||
if wm_in and wm_in.material != mtask.material_in:
|
||||
raise ParseError('消耗物料与任务不一致')
|
||||
attrs['material_out'] = material_out
|
||||
if mtask.start_date == mtask.end_date:
|
||||
attrs['handle_date'] = mtask.end_date
|
||||
|
@ -1223,6 +1233,7 @@ class FmlogSerializer(CustomModelSerializer):
|
|||
is_fix = attrs.get("is_fix", False)
|
||||
if is_fix:
|
||||
attrs["mtask"] = None
|
||||
attrs['route'] = None
|
||||
elif not attrs.get("mtask", None) and not attrs.get("route", None):
|
||||
raise ParseError("请选择任务或工艺步骤")
|
||||
mtask: Mtask = attrs['mtask']
|
||||
|
|
Loading…
Reference in New Issue