feat: 完成返工交接
This commit is contained in:
parent
19cac7729a
commit
9c67675ca7
|
@ -9,7 +9,7 @@ from apps.system.models import Dept, User
|
|||
from apps.system.serializers import UserSimpleSerializer
|
||||
from apps.pm.models import Mtask
|
||||
from apps.wpm.tasks import cal_enstat_when_pcoal_heat_change, cal_enstat_when_team_change, cal_exp_duration_sec
|
||||
from apps.wpm.services import get_sflog
|
||||
from apps.wpm.services import get_sflog, find_material_can_change
|
||||
from apps.mtm.models import Mgroup, TeamMember, Shift, Material, Route
|
||||
from apps.mtm.serializers import MaterialSimpleSerializer
|
||||
from django.db import transaction
|
||||
|
@ -467,6 +467,15 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
"material": {"required": False},
|
||||
"batch": {"required": False},
|
||||
}
|
||||
|
||||
def create(self, validated_data):
|
||||
type = validated_data['type']
|
||||
if type == Handover.H_REPAIR:
|
||||
mgroup_to = validated_data.get("mgroup", None)
|
||||
if mgroup_to is None:
|
||||
raise ParseError('返工交接需指定工段')
|
||||
validated_data['material_changed'] = find_material_can_change(validated_data['material'], mgroup_to)
|
||||
return super().create(validated_data)
|
||||
|
||||
class HandoverUpdateSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
|
|
|
@ -11,12 +11,21 @@ from rest_framework.exceptions import ParseError
|
|||
from apps.system.models import User
|
||||
from apps.inm.models import MIO, MIOItem, MIOItemA
|
||||
from apps.pm.models import Mtask
|
||||
from apps.mtm.models import Mgroup, Shift, Material, Route
|
||||
from apps.mtm.models import Mgroup, Shift, Material, Route, RoutePack
|
||||
|
||||
from .models import SfLog, SfLogExp, WMaterial, Mlog, Mlogb, Handover
|
||||
from apps.mtm.models import Process
|
||||
from apps.mtm.services import cal_material_count
|
||||
|
||||
def find_material_can_change(material: Material, mgroup_to: Mgroup):
|
||||
"""
|
||||
找到可转变为的物料(返工交接用)
|
||||
"""
|
||||
routepackIds = Route.objects.filter(material_out=material, routepack__state=RoutePack.RP_S_CONFIRM).values_list('routepack', flat=True)
|
||||
matIds = list(Route.objects.filter(routepack__id__in=routepackIds, process=mgroup_to.process).values_list('material_in', flat=True).distinct())
|
||||
if matIds and len(matIds) == 1:
|
||||
return Material.objects.get(id=matIds[0])
|
||||
raise ParseError("无法返工到该工段")
|
||||
|
||||
def get_sflog(mgroup: Mgroup, happen_time: datetime):
|
||||
sflog = SfLog.objects.filter(
|
||||
|
@ -497,9 +506,28 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
|||
wm_from.save()
|
||||
if need_add:
|
||||
if handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, mgroup=handover.recive_mgroup, defaults={
|
||||
'batch': batch, 'material': material, 'mgroup': handover.recive_mgroup, 'belong_dept': handover.recive_dept
|
||||
})
|
||||
# 处理返工交接
|
||||
if handover.type == Handover.H_NORMAL:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, mgroup=handover.recive_mgroup, defaults={
|
||||
'batch': batch, 'material': material, 'mgroup': handover.recive_mgroup, 'belong_dept': handover.recive_dept
|
||||
})
|
||||
elif handover.type == Handover.H_REPAIR:
|
||||
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,
|
||||
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
|
||||
})
|
||||
else:
|
||||
raise ParseError('不支持的交接类型')
|
||||
else:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, belong_dept=handover.recive_dept, defaults={
|
||||
'batch': batch, 'material': material, 'belong_dept': handover.recive_dept
|
||||
|
|
Loading…
Reference in New Issue