fix: mlog update 没有消耗时的校验
This commit is contained in:
parent
cb36aac9ca
commit
84f7de61bc
|
|
@ -283,19 +283,20 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
instance: Mlog = super().create(validated_data)
|
instance: Mlog = super().create(validated_data)
|
||||||
# 自动生成mlogb
|
# 自动生成mlogb
|
||||||
batch_in = instance.batch
|
batch_in = instance.batch
|
||||||
wm_in = instance.wm_in
|
if instance.material_in: # 如果有消耗
|
||||||
if wm_in:
|
wm_in = instance.wm_in
|
||||||
batch_in = wm_in.batch
|
if wm_in:
|
||||||
add_dict = {
|
batch_in = wm_in.batch
|
||||||
'mlog': instance, 'batch': batch_in, 'wm_in': wm_in,
|
add_dict = {
|
||||||
'mtask': instance.mtask, 'material_in': instance.material_in,
|
'mlog': instance, 'batch': batch_in, 'wm_in': wm_in,
|
||||||
'count_use': instance.count_use, 'count_break': instance.count_break,
|
'mtask': instance.mtask, 'material_in': instance.material_in,
|
||||||
'count_pn_jgqbl': instance.count_pn_jgqbl
|
'count_use': instance.count_use, 'count_break': instance.count_break,
|
||||||
}
|
'count_pn_jgqbl': instance.count_pn_jgqbl
|
||||||
if wm_in:
|
}
|
||||||
add_dict['batch_ofrom'] = wm_in.batch_ofrom
|
if wm_in:
|
||||||
add_dict['material_ofrom'] = wm_in.material_ofrom
|
add_dict['batch_ofrom'] = wm_in.batch_ofrom
|
||||||
Mlogb.objects.create(**add_dict)
|
add_dict['material_ofrom'] = wm_in.material_ofrom
|
||||||
|
Mlogb.objects.create(**add_dict)
|
||||||
|
|
||||||
# mlogb只用于组合件输出物填写
|
# mlogb只用于组合件输出物填写
|
||||||
brotherId_should_list = material_out.brothers
|
brotherId_should_list = material_out.brothers
|
||||||
|
|
@ -308,6 +309,7 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
batch=instance.batch,
|
batch=instance.batch,
|
||||||
mtask=instance.mtask,
|
mtask=instance.mtask,
|
||||||
material_out=item['material_out'],
|
material_out=item['material_out'],
|
||||||
|
count_real=item['count_ok'],
|
||||||
count_ok=item['count_ok'])
|
count_ok=item['count_ok'])
|
||||||
if wm_in:
|
if wm_in:
|
||||||
mlogbx.batch_ofrom = wm_in.batch_ofrom
|
mlogbx.batch_ofrom = wm_in.batch_ofrom
|
||||||
|
|
@ -326,6 +328,7 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
add_dict_2 = {
|
add_dict_2 = {
|
||||||
'mlog': instance, 'batch': batch_out,
|
'mlog': instance, 'batch': batch_out,
|
||||||
'mtask': instance.mtask, 'material_out': instance.material_out,
|
'mtask': instance.mtask, 'material_out': instance.material_out,
|
||||||
|
'count_real': instance.count_real,
|
||||||
'count_ok': instance.count_ok, 'count_notok': instance.count_notok,
|
'count_ok': instance.count_ok, 'count_notok': instance.count_notok,
|
||||||
'count_break_t': instance.count_break_t
|
'count_break_t': instance.count_break_t
|
||||||
}
|
}
|
||||||
|
|
@ -354,31 +357,33 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
# 修改消耗
|
# 修改消耗
|
||||||
if instance.fill_way in [Mlog.MLOG_12, Mlog.MLOG_2]:
|
if instance.fill_way in [Mlog.MLOG_12, Mlog.MLOG_2]:
|
||||||
# 自动生成mlogb
|
# 自动生成mlogb
|
||||||
batch_in = instance.batch
|
if instance.material_in: # 有消耗的情况
|
||||||
if wm_in:
|
batch_in = instance.batch
|
||||||
batch_in = wm_in.batch
|
if wm_in:
|
||||||
minx, _ = Mlogb.objects.get_or_create(
|
batch_in = wm_in.batch
|
||||||
mlog=instance,
|
minx, _ = Mlogb.objects.get_or_create(
|
||||||
batch=batch_in,
|
mlog=instance,
|
||||||
wm_in=instance.wm_in,
|
batch=batch_in,
|
||||||
mtask=instance.mtask,
|
wm_in=instance.wm_in,
|
||||||
material_in=instance.material_in
|
mtask=instance.mtask,
|
||||||
)
|
material_in=instance.material_in
|
||||||
if wm_in:
|
)
|
||||||
minx.batch_ofrom = wm_in.batch_ofrom
|
if wm_in:
|
||||||
minx.material_ofrom = wm_in.material_ofrom
|
minx.batch_ofrom = wm_in.batch_ofrom
|
||||||
minx.count_use = instance.count_use
|
minx.material_ofrom = wm_in.material_ofrom
|
||||||
minx.count_break = instance.count_break
|
minx.count_use = instance.count_use
|
||||||
minx.count_pn_jgqbl = instance.count_pn_jgqbl
|
minx.count_break = instance.count_break
|
||||||
minx.save()
|
minx.count_pn_jgqbl = instance.count_pn_jgqbl
|
||||||
Mlogb.objects.filter(mlog=instance, material_in__isnull=False).exclude(id=minx.id).delete()
|
minx.save()
|
||||||
|
Mlogb.objects.filter(mlog=instance, material_in__isnull=False).exclude(id=minx.id).delete()
|
||||||
|
|
||||||
# 修改产出
|
# 修改产出
|
||||||
if instance.fill_way == Mlog.MLOG_2 and instance.material_out.brothers:
|
if instance.fill_way == Mlog.MLOG_2 and instance.material_out.brothers:
|
||||||
# 针对兄弟件的情况
|
# 针对兄弟件的情况
|
||||||
Mlogb.objects.filter(mlog=instance, material_out__isnull=False).update(count_ok=0)
|
Mlogb.objects.filter(mlog=instance, material_out__isnull=False).update(count_real=0, count_ok=0)
|
||||||
for item in mlogb:
|
for item in mlogb:
|
||||||
Mlogb.objects.filter(mlog=instance, material_out=item['material_out']).update(
|
Mlogb.objects.filter(mlog=instance, material_out=item['material_out']).update(
|
||||||
|
count_real=item['count_ok'],
|
||||||
count_ok=item['count_ok'])
|
count_ok=item['count_ok'])
|
||||||
|
|
||||||
elif instance.fill_way in [Mlog.MLOG_12, Mlog.MLOG_2]:
|
elif instance.fill_way in [Mlog.MLOG_12, Mlog.MLOG_2]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue