feat: handover_submit优化
This commit is contained in:
parent
e5ac627834
commit
e2f4cd1612
|
|
@ -12,7 +12,7 @@ from apps.inm.models import MIO, MIOItem, MIOItemA
|
|||
from apps.pm.models import Mtask
|
||||
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.wf.models import Ticket
|
||||
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:
|
||||
return
|
||||
now = timezone.now()
|
||||
handoverb_qs = Handover.objects.filter(handover=handover)
|
||||
need_add = True
|
||||
material = handover.material
|
||||
batch = handover.batch
|
||||
wm_from = handover.wm
|
||||
if wm_from is None:
|
||||
raise ParseError('找不到车间库存')
|
||||
if '混料' in material.name: # hard code
|
||||
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 handover.type == Handover.H_NORMAL:
|
||||
if handover.recive_mgroup:
|
||||
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 - 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(
|
||||
batch=batch,
|
||||
material=material,
|
||||
mgroup=handover.recive_mgroup,
|
||||
state=WMaterial.WM_OK,
|
||||
defaults={"batch": batch, "material": material, "mgroup": handover.recive_mgroup, "belong_dept": handover.recive_dept},
|
||||
mgroup=recive_mgroup,
|
||||
belong_dept=recive_dept,
|
||||
state=WMaterial.WM_OK
|
||||
)
|
||||
else:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=material,
|
||||
belong_dept=handover.recive_dept,
|
||||
mgroup=None,
|
||||
state=WMaterial.WM_OK,
|
||||
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept}
|
||||
)
|
||||
elif handover.type == Handover.H_REPAIR:
|
||||
if handover.recive_mgroup:
|
||||
elif handover.type == Handover.H_REPAIR:
|
||||
if handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=handover.material_changed,
|
||||
mgroup=recive_mgroup,
|
||||
belong_dept=recive_dept,
|
||||
notok_sign=wm_from.notok_sign,
|
||||
material_origin=material,
|
||||
state=WMaterial.WM_REPAIR
|
||||
)
|
||||
else:
|
||||
raise ParseError("返工交接必须指定接收工段")
|
||||
elif handover.type == Handover.H_TEST:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=handover.material_changed,
|
||||
mgroup=handover.recive_mgroup,
|
||||
notok_sign=handover.wm.notok_sign,
|
||||
material_origin=handover.material,
|
||||
state=WMaterial.WM_REPAIR,
|
||||
material=material,
|
||||
mgroup=recive_mgroup,
|
||||
state=WMaterial.WM_TEST,
|
||||
belong_dept=recive_dept,
|
||||
defaults={
|
||||
"batch": batch,
|
||||
"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
|
||||
"count_xtest": 0,
|
||||
},
|
||||
)
|
||||
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:
|
||||
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("不支持交接类型")
|
||||
raise ParseError("不支持该交接类型")
|
||||
|
||||
wm_to.count = wm_to.count + handover.count
|
||||
wm_to.count_eweight = handover.count_eweight # 这行代码有隐患
|
||||
wm_to.save()
|
||||
wm_to.count = wm_to.count + xcount
|
||||
wm_to.count_eweight = handover.count_eweight # 这行代码有隐患
|
||||
wm_to.save()
|
||||
handover.submit_user = user
|
||||
handover.submit_time = now
|
||||
handover.save()
|
||||
|
|
|
|||
Loading…
Reference in New Issue