diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 61ccac0e..a85f9c46 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -566,26 +566,26 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime material = handover.material if '混料' in material.name: # hard code need_add = False - if need_add: - if handoverb_qs.exists(): - handoverb_list = [(item.wm, item.count) for item in handoverb_qs] + if handoverb_qs.exists(): + handoverb_list = [(item.wm, item.count) for item in handoverb_qs] + else: + handoverb_list = [(handover.wm, handover.count)] + + recive_mgroup = handover.recive_mgroup + recive_dept = handover.recive_dept + for item in handoverb_list: + wm_from, xcount = item + batch = wm_from.batch + if wm_from is None: + raise ParseError('找不到车间库存') + + count_x = wm_from.count - xcount + if count_x < 0: + raise ParseError('车间库存不足!') else: - handoverb_list = [(handover.wm, handover.count)] - - recive_mgroup = handover.recive_mgroup - recive_dept = handover.recive_dept - for item in handoverb_list: - wm_from, xcount = item - batch = wm_from.batch - if wm_from is None: - raise ParseError('找不到车间库存') - - count_x = wm_from.count - xcount - if count_x < 0: - raise ParseError('车间库存不足!') - else: - wm_from.count = count_x - wm_from.save() + wm_from.count = count_x + wm_from.save() + if need_add: # 开始变动 if handover.type == Handover.H_NORMAL: wm_to, _ = WMaterial.objects.get_or_create(