feat: wpr获取material_start
This commit is contained in:
parent
9c69711f38
commit
bd7bbbef0e
|
@ -4,8 +4,10 @@ from apps.qm.models import FtestDefect, FtestItem
|
||||||
from apps.utils.models import BaseModel
|
from apps.utils.models import BaseModel
|
||||||
from apps.mtm.models import Material
|
from apps.mtm.models import Material
|
||||||
from rest_framework.exceptions import ParseError
|
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.utils.tools import update_dict
|
||||||
|
from apps.inm.models import MIOItemw
|
||||||
|
from django.db.models import F, Value
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class Wpr(BaseModel):
|
class Wpr(BaseModel):
|
||||||
|
@ -137,6 +139,28 @@ class Wpr(BaseModel):
|
||||||
def wprdefect(self):
|
def wprdefect(self):
|
||||||
return WprDefect.objects.filter(wpr=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):
|
class WprDefect(BaseModel):
|
||||||
"""TN:产物缺陷项关联表"""
|
"""TN:产物缺陷项关联表"""
|
||||||
wpr = models.ForeignKey(Wpr, verbose_name="关联产物", on_delete=models.CASCADE)
|
wpr = models.ForeignKey(Wpr, verbose_name="关联产物", on_delete=models.CASCADE)
|
||||||
|
|
Loading…
Reference in New Issue