feat: handover_submit优化

This commit is contained in:
caoqianming 2024-09-05 12:44:40 +08:00
parent e5ac627834
commit e2f4cd1612
1 changed files with 61 additions and 71 deletions

View File

@ -12,7 +12,7 @@ from apps.inm.models import MIO, MIOItem, MIOItemA
from apps.pm.models import Mtask from apps.pm.models import Mtask
from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack
from .models import SfLog, WMaterial, Mlog, Mlogb, Handover from .models import SfLog, WMaterial, Mlog, Mlogb, Handover, Handoverb
from apps.mtm.services import cal_material_count from apps.mtm.services import cal_material_count
from apps.wf.models import Ticket from apps.wf.models import Ticket
from django.db import transaction from django.db import transaction
@ -561,92 +561,82 @@ 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()
handoverb_qs = Handover.objects.filter(handover=handover)
need_add = True need_add = True
material = handover.material material = handover.material
batch = handover.batch
wm_from = handover.wm
if wm_from is None:
raise ParseError('找不到车间库存')
if '混料' in material.name: # hard code if '混料' in material.name: # hard code
need_add = False need_add = False
count_x = wm_from.count - handover.count
if count_x < 0:
raise ParseError('车间库存不足!')
else:
wm_from.count = count_x
wm_from.save()
if need_add: if need_add:
if handover.type == Handover.H_NORMAL: if handoverb_qs.exists():
if handover.recive_mgroup: 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 - handover.count
if count_x < 0:
raise ParseError('车间库存不足!')
else:
wm_from.count = count_x
wm_from.save()
# 开始变动
if handover.type == Handover.H_NORMAL:
wm_to, _ = WMaterial.objects.get_or_create( wm_to, _ = WMaterial.objects.get_or_create(
batch=batch, batch=batch,
material=material, material=material,
mgroup=handover.recive_mgroup, mgroup=recive_mgroup,
state=WMaterial.WM_OK, belong_dept=recive_dept,
defaults={"batch": batch, "material": material, "mgroup": handover.recive_mgroup, "belong_dept": handover.recive_dept}, state=WMaterial.WM_OK
) )
else: elif handover.type == Handover.H_REPAIR:
wm_to, _ = WMaterial.objects.get_or_create( if handover.recive_mgroup:
batch=batch, wm_to, _ = WMaterial.objects.get_or_create(
material=material, batch=batch,
belong_dept=handover.recive_dept, material=handover.material_changed,
mgroup=None, mgroup=recive_mgroup,
state=WMaterial.WM_OK, belong_dept=recive_dept,
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept} notok_sign=wm_from.notok_sign,
) material_origin=material,
elif handover.type == Handover.H_REPAIR: state=WMaterial.WM_REPAIR
if handover.recive_mgroup: )
else:
raise ParseError("返工交接必须指定接收工段")
elif handover.type == Handover.H_TEST:
wm_to, _ = WMaterial.objects.get_or_create( wm_to, _ = WMaterial.objects.get_or_create(
batch=batch, batch=batch,
material=handover.material_changed, material=material,
mgroup=handover.recive_mgroup, mgroup=recive_mgroup,
notok_sign=handover.wm.notok_sign, state=WMaterial.WM_TEST,
material_origin=handover.material, belong_dept=recive_dept,
state=WMaterial.WM_REPAIR,
defaults={ defaults={
"batch": batch, "count_xtest": 0,
"material": handover.material_changed,
"mgroup": handover.recive_mgroup,
"notok_sign": handover.wm.notok_sign,
"material_origin": handover.material,
"belong_dept": handover.recive_dept,
"state": WMaterial.WM_REPAIR
}, },
) )
elif handover.type == Handover.H_SCRAP:
if recive_mgroup:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
mgroup=recive_mgroup,
belong_dept=recive_dept,
notok_sign=wm_from.notok_sign,
state=WMaterial.WM_SCRAP
)
else:
raise ParseError("不支持非工段报废")
else: else:
raise ParseError("返工交接必须指定接收工段") raise ParseError("不支持该交接类型")
elif handover.type == Handover.H_TEST:
if handover.recive_mgroup:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
mgroup=handover.recive_mgroup,
state=WMaterial.WM_TEST,
defaults={
"batch": batch,
"material": material,
"mgroup": handover.recive_mgroup,
"belong_dept": handover.recive_dept,
"count_xtest": 0,
"state": WMaterial.WM_TEST},
)
else:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
belong_dept=handover.recive_dept,
mgroup=None,
state=WMaterial.WM_TEST,
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept, "count_xtest": 0, "state": WMaterial.WM_TEST},
)
elif handover.type == Handover.H_SCRAP:
raise ParseError("不支持交接类型")
else:
raise ParseError("不支持交接类型")
wm_to.count = wm_to.count + handover.count wm_to.count = wm_to.count + xcount
wm_to.count_eweight = handover.count_eweight # 这行代码有隐患 wm_to.count_eweight = handover.count_eweight # 这行代码有隐患
wm_to.save() wm_to.save()
handover.submit_user = user handover.submit_user = user
handover.submit_time = now handover.submit_time = now
handover.save() handover.save()