feat: wpr获取material_start

This commit is contained in:
caoqianming 2025-05-15 10:03:14 +08:00
parent 9c69711f38
commit bd7bbbef0e
1 changed files with 25 additions and 1 deletions

View File

@ -4,8 +4,10 @@ from apps.qm.models import FtestDefect, FtestItem
from apps.utils.models import BaseModel
from apps.mtm.models import Material
from rest_framework.exceptions import ParseError
from apps.wpm.models import WmStateOption
from apps.wpm.models import WmStateOption, Mlogbw, Handoverbw
from apps.utils.tools import update_dict
from apps.inm.models import MIOItemw
from django.db.models import F, Value
# Create your models here.
class Wpr(BaseModel):
@ -136,6 +138,28 @@ class Wpr(BaseModel):
@property
def wprdefect(self):
return WprDefect.objects.filter(wpr=self)
def timeline(self):
# 获取完整时间线
mioitemw_qs = MIOItemw.objects.filter(wpr=self, mioitem__mio__submit_time__isnull=False).values(
"id", timex=F("mioitem__mio__submit_time"), model=Value('mioitemw', output_field=models.CharField()))
mlogbw_qs = Mlogbw.objects.filter(wpr=self, mlogb__mlog__submit_time__isnull=False, mlogb__material_out__isnull=False).values(
"id", timex=F("mlogb__mlog__submit_time"), model=Value('mlogbw', output_field=models.CharField()))
h_qs = Handoverbw.objects.filter(wpr=self, handoverb__handover__submit_time__isnull=False).values(
"id", timex=F("handoverb__handover__submit_time"), model=Value('handoverbw', output_field=models.CharField()))
combined_qs = mioitemw_qs.union(mlogbw_qs, h_qs).order_by('timex')
return list(combined_qs)
def get_material_start(self):
timeline = self.timeline()
if timeline:
x = timeline[0]
if x['model'] == 'mioitemw':
return MIOItemw.objects.get(id=x['id']).mioitem.material
elif x['model'] == 'mlogbw':
return Mlogbw.objects.get(id=x['id']).mlogb.material_out
return None
class WprDefect(BaseModel):
"""TN:产物缺陷项关联表"""