fix: handover_submit针对混料特殊处理的bug

This commit is contained in:
caoqianming 2024-03-06 21:45:17 +08:00
parent b429ad9059
commit 3ddb050330
1 changed files with 25 additions and 20 deletions

View File

@ -281,19 +281,24 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
if handover.submit_time is not None: if handover.submit_time is not None:
return return
now = timezone.now() now = timezone.now()
if handover.wm:
wm: WMaterial = handover.wm
need_add = True need_add = True
if '混料' in wm.material.name: # hard code material = handover.material
batch = handover.batch
try:
wm_from = WMaterial.objects.get(
material=material, batch=batch, belong_dept=handover.send_dept)
except Exception as e:
raise ParseError(f'找不到车间库存:{e}')
if '混料' in material.name: # hard code
need_add = False need_add = False
count_x = wm.count - handover.count count_x = wm_from.count - handover.count
if count_x < 0: if count_x < 0:
raise ParseError('车间库存不足!') raise ParseError('车间库存不足!')
elif count_x == 0: elif count_x == 0:
wm.delete() wm_from.delete()
else: else:
wm.count = count_x wm_from.count = count_x
wm.save() wm_from.save()
if need_add: if need_add:
wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={ wm_to, _ = WMaterial.objects.get_or_create(batch=handover.batch, material=handover.material, belong_dept=handover.send_dept, defaults={
'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept 'batch': handover.batch, 'material': handover.material, 'belong_dept': handover.send_dept