feat: qm增加最大不合格率字段
This commit is contained in:
parent
232ecb0f45
commit
da3c672dd1
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 3.2.12 on 2025-03-18 05:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('qm', '0047_ftestwork_count_ok_full'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='qct',
|
||||
name='max_defect_rate',
|
||||
field=models.FloatField(blank=True, default=0.5, null=True, verbose_name='最大不合格率'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='qctdefect',
|
||||
name='is_default',
|
||||
field=models.BooleanField(default=False, verbose_name='是否默认缺陷'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='qctmat',
|
||||
name='max_defect_rate',
|
||||
field=models.FloatField(blank=True, default=0.5, null=True, verbose_name='最大不合格率'),
|
||||
),
|
||||
]
|
|
@ -155,6 +155,7 @@ class Qct(CommonAModel):
|
|||
testitems = models.ManyToManyField(TestItem, verbose_name="检测项", blank=True, through='qm.qcttestitem')
|
||||
defects = models.ManyToManyField(Defect, verbose_name="缺陷项", blank=True, through='qm.qctdefect')
|
||||
materials = models.ManyToManyField(Material, verbose_name="物料", blank=True, through='qm.qctmat')
|
||||
max_defect_rate = models.FloatField('最大不合格率', default=0.5, null=True, blank=True)
|
||||
|
||||
@property
|
||||
def qct_testitems(self):
|
||||
|
@ -183,6 +184,14 @@ class Qct(CommonAModel):
|
|||
raise ParseError("存在多个质检表,请手动选择")
|
||||
return qct
|
||||
|
||||
@property
|
||||
def defect_default(self):
|
||||
qctdefect = QctDefect.objects.filter(qct=self, is_default=True)
|
||||
if qctdefect.exists():
|
||||
return qctdefect.first().defect
|
||||
else:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_qs(cls, materialId:str, tag:str):
|
||||
qct_qs = Qct.objects.filter(qctmat__material__id=materialId, tags__contains=tag)
|
||||
|
@ -199,6 +208,7 @@ class QctTestItem(BaseModel):
|
|||
|
||||
class QctDefect(BaseModel):
|
||||
qct = models.ForeignKey(Qct, verbose_name="质检模板", on_delete=models.CASCADE, related_name="qctdefect")
|
||||
is_default = models.BooleanField('是否默认缺陷', default=False)
|
||||
defect = models.ForeignKey(Defect, verbose_name="缺陷项", on_delete=models.CASCADE)
|
||||
rule_expression = models.TextField('判定表达式', null=True, blank=True)
|
||||
note = models.TextField('备注', null=True, blank=True)
|
||||
|
@ -209,6 +219,7 @@ class QctMat(BaseModel):
|
|||
material = models.ForeignKey(Material, verbose_name="物料", on_delete=models.CASCADE)
|
||||
tracing = models.CharField('追溯层级', default=QC_T, choices=QC_TRACE_CHOICES,
|
||||
max_length=20, help_text=str(QC_TRACE_CHOICES))
|
||||
max_defect_rate = models.FloatField('最大不合格率', default=0.5, null=True, blank=True)
|
||||
|
||||
|
||||
class QuaStat(CommonBDModel):
|
||||
|
|
|
@ -78,6 +78,17 @@ class QctDefectViewSet(CustomModelViewSet):
|
|||
filterset_fields = ["qct", "defect"]
|
||||
ordering = ["qct", "sort"]
|
||||
|
||||
@transaction.atomic
|
||||
def perform_create(self, serializer):
|
||||
ins: QctDefect = serializer.save()
|
||||
if ins.is_default:
|
||||
QctDefect.objects.filter(qct=ins.qct).exclude(id=ins.id).update(is_default=False)
|
||||
|
||||
def perform_update(self, serializer):
|
||||
ins: QctDefect = serializer.save()
|
||||
if ins.is_default:
|
||||
QctDefect.objects.filter(qct=ins.qct).exclude(id=ins.id).update(is_default=False)
|
||||
|
||||
class QctMatViewSet(CustomModelViewSet):
|
||||
"""检测物料
|
||||
|
||||
|
|
Loading…
Reference in New Issue