feat: ftestwork的submit支持defect
This commit is contained in:
parent
942e54a7e4
commit
69daa63ea6
|
@ -181,7 +181,7 @@ class FtestWorkCreateUpdateSerializer(CustomModelSerializer):
|
|||
with transaction.atomic():
|
||||
ins: FtestWork = super().create(validated_data)
|
||||
for ftestworkdefect in ftestworkdefect:
|
||||
FtestworkDefect.objects.create(ftest=ins, **ftestworkdefect)
|
||||
FtestworkDefect.objects.create(ftestwork=ins, **ftestworkdefect)
|
||||
if ftestworkdefect:
|
||||
ins.cal_count()
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from apps.qm.models import FtestWork
|
||||
from apps.qm.models import FtestWork, FtestworkDefect
|
||||
from apps.wpm.models import WMaterial
|
||||
from apps.system.models import User
|
||||
from rest_framework.exceptions import ParseError
|
||||
from django.utils import timezone
|
||||
from apps.wf.models import Ticket
|
||||
from apps.qm.models import NotOkOption
|
||||
from apps.qm.models import NotOkOption, Defect
|
||||
from apps.utils.thread import MyThread
|
||||
from apps.wpm.services_2 import get_alldata_with_batch_and_store
|
||||
|
||||
|
@ -24,74 +24,101 @@ def ftestwork_submit_validate(ins: FtestWork):
|
|||
def ftestwork_submit(ins:FtestWork, user: User):
|
||||
wm:WMaterial = ins.wm
|
||||
if ins.need_update_wm:
|
||||
if wm.state == WMaterial.WM_TEST:
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
# 寻找count_notok_json中的b类不合格不进行处理
|
||||
if ins.qct is None:
|
||||
if wm.state == WMaterial.WM_TEST:
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
|
||||
# 寻找count_notok_json中的b类不合格不进行处理
|
||||
count_notok_json = ins.count_notok_json
|
||||
need_move_count = 0
|
||||
for k, v in count_notok_json.items():
|
||||
if v > 0:
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
if NotOkOption.get_extra_info(notok_sign)['cate'] == 'ok_b': # b类不合格在后续处理
|
||||
need_move_count = need_move_count + v
|
||||
count_ok = ins.count_ok - need_move_count
|
||||
if count_ok > 0:
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
state=WMaterial.WM_OK,
|
||||
notok_sign=None,
|
||||
defaults={
|
||||
'count': count_ok,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + count_ok
|
||||
wm.save()
|
||||
else: # 如果直接对工段库存检验 , 则直接扣减不合格数
|
||||
wm.count = wm.count - ins.count_notok
|
||||
if wm.count >= 0:
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("不合格数不可大于批次数量")
|
||||
|
||||
# 生成不合格的
|
||||
count_notok_json = ins.count_notok_json
|
||||
need_move_count = 0
|
||||
for k, v in count_notok_json.items():
|
||||
if v > 0:
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
if NotOkOption.get_extra_info(notok_sign)['cate'] == 'ok_b': # b类不合格在后续处理
|
||||
need_move_count = need_move_count + v
|
||||
count_ok = ins.count_ok - need_move_count
|
||||
if count_ok > 0:
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
state=WMaterial.WM_OK,
|
||||
notok_sign=None,
|
||||
defaults={
|
||||
'count': count_ok,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + count_ok
|
||||
wm.save()
|
||||
else: # 如果直接对工段库存检验 , 则直接扣减不合格数
|
||||
wm.count = wm.count - ins.count_notok
|
||||
if wm.count >= 0:
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("不合格数不可大于批次数量")
|
||||
|
||||
# 生成不合格的
|
||||
count_notok_json = ins.count_notok_json
|
||||
for k, v in count_notok_json.items():
|
||||
if v > 0:
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
astate = WMaterial.WM_NOTOK
|
||||
if NotOkOption.get_extra_info(notok_sign)['cate'] == 'ok_b':
|
||||
astate = WMaterial.WM_OK
|
||||
wm_n, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
notok_sign=notok_sign,
|
||||
state=astate,
|
||||
defaults={
|
||||
'count': v,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
'notok_sign': notok_sign,
|
||||
'state': astate,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm_n.count = wm_n.count + v
|
||||
wm_n.save()
|
||||
astate = WMaterial.WM_NOTOK
|
||||
if NotOkOption.get_extra_info(notok_sign)['cate'] == 'ok_b':
|
||||
astate = WMaterial.WM_OK
|
||||
wm_n, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
notok_sign=notok_sign,
|
||||
state=astate,
|
||||
defaults={
|
||||
'count': v,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
'notok_sign': notok_sign,
|
||||
'state': astate,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm_n.count = wm_n.count + v
|
||||
wm_n.save()
|
||||
else:
|
||||
wm:WMaterial = ins.wm
|
||||
# 此时调用了qct表
|
||||
for item in FtestworkDefect.objects.filter(ftestwork=ins):
|
||||
item:FtestworkDefect = item
|
||||
if item.count > 0 and item.defect.okcate == Defect.DEFECT_NOTOK:
|
||||
ins.count = ins.count - item.count
|
||||
if ins.count < 0:
|
||||
raise ParseError("数量不足,扣减失败")
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
material=wm.material,
|
||||
batch=wm.batch,
|
||||
mgroup=wm.mgroup,
|
||||
belong_dept=wm.belong_dept,
|
||||
state=WMaterial.WM_NOTOK,
|
||||
notok_sign=None,
|
||||
defect=item.defect,
|
||||
defaults={
|
||||
'count': item.count,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + item.count
|
||||
wm.save()
|
||||
ins.save()
|
||||
ins.submit_user = user
|
||||
ins.submit_time = timezone.now()
|
||||
ins.save()
|
||||
|
|
Loading…
Reference in New Issue