From 3ddb050330d2df4ca9fcc8e2eb8a8d91a0bc50c0 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 6 Mar 2024 21:45:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20handover=5Fsubmit=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E6=B7=B7=E6=96=99=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/services.py | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index ed73d607..57e63bbe 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -281,26 +281,31 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime if handover.submit_time is not None: return now = timezone.now() - if handover.wm: - wm: WMaterial = handover.wm - need_add = True - if '混料' in wm.material.name: # hard code - need_add = False - count_x = wm.count - handover.count - if count_x < 0: - raise ParseError('车间库存不足!') - elif count_x == 0: - wm.delete() - else: - wm.count = count_x - wm.save() - if need_add: - 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 - }) - wm_to.count = wm_to.count + handover.count - wm_to.count_eweight = handover.count_eweight - wm_to.save() + need_add = True + 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 + count_x = wm_from.count - handover.count + if count_x < 0: + raise ParseError('车间库存不足!') + elif count_x == 0: + wm_from.delete() + else: + wm_from.count = count_x + wm_from.save() + if need_add: + 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 + }) + wm_to.count = wm_to.count + handover.count + wm_to.count_eweight = handover.count_eweight + wm_to.save() handover.submit_user = user handover.submit_time = now handover.save()