feat: ftestwork_submit增加抽检逻辑
This commit is contained in:
parent
23dd745192
commit
bfad89bf2f
|
@ -7,36 +7,69 @@ from django.utils import timezone
|
|||
|
||||
def ftestwork_submit(ins:FtestWork, user: User):
|
||||
wm:WMaterial = ins.wm
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
if wm.count_xtest is not None: # 如果关心检验数量 一般是全检
|
||||
# 更新对应的车间库存
|
||||
wm.count = wm.count - ins.count
|
||||
if wm.count >= 0:
|
||||
# 已检测的数量
|
||||
wm.count_xtest = wm.count_xtest + ins.count
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
# 生成合格的
|
||||
count_ok = ins.count_ok
|
||||
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,
|
||||
notok_sign=None,
|
||||
material_origin=None,
|
||||
count_xtest=None,
|
||||
defaults={
|
||||
'count': count_ok,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm.count = wm.count + count_ok
|
||||
wm.save()
|
||||
else:
|
||||
raise ParseError("超过待检数量")
|
||||
# 生成合格的
|
||||
count_ok = ins.count_ok
|
||||
if count_ok > 0:
|
||||
wm_ok = WMaterial()
|
||||
wm_ok.material = wm.material
|
||||
wm_ok.count = count_ok
|
||||
wm_ok.batch = wm.batch
|
||||
wm_ok.mgroup = wm.mgroup
|
||||
wm_ok.belong_dept = wm.belong_dept
|
||||
wm_ok.save()
|
||||
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:
|
||||
wm_n = WMaterial()
|
||||
wm_n.material = wm.material
|
||||
wm_n.count = v
|
||||
wm_n.batch = wm.batch
|
||||
wm_n.mgroup = wm.mgroup
|
||||
wm_n.belong_dept = wm.belong_dept
|
||||
wm_n.notok_sign = k.replace('count_n_', '')
|
||||
wm_n.save()
|
||||
notok_sign = k.replace('count_n_', '')
|
||||
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,
|
||||
material_origin=None,
|
||||
count_xtest=None,
|
||||
defaults={
|
||||
'count': v,
|
||||
'material': wm.material,
|
||||
'batch': wm.batch,
|
||||
'mgroup': wm.mgroup,
|
||||
'belong_dept': wm.belong_dept,
|
||||
'notok_sign': notok_sign
|
||||
}
|
||||
)
|
||||
if not new_create:
|
||||
wm_n.count = wm_n.count + v
|
||||
wm_n.save()
|
||||
ins.submit_user = user
|
||||
ins.submit_time = timezone.now()
|
||||
ins.save()
|
Loading…
Reference in New Issue