73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
| from apps.qm.models import FtestWork
 | |
| from apps.wpm.models import WMaterial
 | |
| from apps.system.models import User
 | |
| from rest_framework.exceptions import ParseError
 | |
| from django.utils import timezone
 | |
| 
 | |
| 
 | |
| def ftestwork_submit(ins:FtestWork, user: User):
 | |
|     wm:WMaterial = ins.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_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,
 | |
|                 state=WMaterial.WM_OK,
 | |
|                 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:
 | |
|         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_', '')
 | |
|             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=WMaterial.WM_NOTOK,
 | |
|                 defaults={
 | |
|                     'count': v,
 | |
|                     'material': wm.material,
 | |
|                     'batch': wm.batch,
 | |
|                     'mgroup': wm.mgroup,
 | |
|                     'belong_dept': wm.belong_dept,
 | |
|                     'notok_sign': notok_sign,
 | |
|                     'state': WMaterial.WM_NOTOK,
 | |
|                 }
 | |
|             )
 | |
|             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() |