feat: ftestwork增加检验人及不合格项

This commit is contained in:
caoqianming 2024-08-14 18:07:12 +08:00
parent a9acf6d187
commit db792a2de5
3 changed files with 46 additions and 5 deletions

View File

@ -0,0 +1,31 @@
# Generated by Django 3.2.12 on 2024-08-14 09:56
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('qm', '0019_alter_ftestwork_batch'),
]
operations = [
migrations.AddField(
model_name='ftestwork',
name='test_user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ftestwork_test_user', to=settings.AUTH_USER_MODEL, verbose_name='操作人'),
),
migrations.AlterField(
model_name='ftest',
name='type',
field=models.CharField(choices=[('first', '首件检验'), ('process', '过程检验'), ('prod', '成品检验')], max_length=20, verbose_name='检验类型'),
),
migrations.AlterField(
model_name='ftestwork',
name='type',
field=models.CharField(choices=[('first', '首件检验'), ('process', '过程检验'), ('prod', '成品检验')], default='prod', max_length=20, verbose_name='检验类型'),
),
]

View File

@ -47,15 +47,19 @@ class NotOkOption(models.TextChoices):
hqnjyd = "hqnjyd", _("黑圈内径圆度")
hqwj = "hqwj", _("黑圈外径")
hqwjyd = "hqwjyd", _("黑圈外径圆度")
wj = "wj", _("外径")
yd = "yd", _("圆度")
txd = "txd", _("同心度")
hd = "hd", _("厚度")
wj = "wj", _("外径不良")
yd = "yd", _("圆度不良")
txd = "txd", _("同心度不良")
hd = "hd", _("厚度不良")
z = "z", _("")
zhg = "zhg", _("准合格")
yz = "yz", _("圆准")
qt = "qt", _("其它")
FTEST_TYPE_CHOICES = (
('first', '首件检验'),
('process', '过程检验'),
('prod', '成品检验')
)
class TestItem(CommonAModel):
@ -113,6 +117,8 @@ class FtestWork(CommonBDModel):
count_ok = models.IntegerField('合格数量', default=0)
count_notok = models.IntegerField('不合格数量', default=0)
count_notok_json = models.JSONField('不合格项数量统计', default=dict, null=False, blank=True)
test_user = models.ForeignKey(
User, verbose_name='操作人', on_delete=models.CASCADE, related_name='ftestwork_test_user', null=True, blank=True)
submit_time = models.DateTimeField('提交时间', null=True, blank=True)
submit_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='提交人', null=True, blank=True)

View File

@ -62,7 +62,8 @@ class QuaStatUpdateSerializer(CustomModelSerializer):
class FtestWorkCreateUpdateSerializer(CustomModelSerializer):
class Meta:
model = FtestWork
fields = ['id', 'wm', 'type', 'type2', 'test_date', 'count', 'count_sampling', 'count_ok', 'count_notok', 'count_notok_json']
fields = ['id', 'wm', 'type', 'type2', 'test_date', 'count', 'count_sampling', 'count_ok', 'count_notok', 'count_notok_json', 'test_user']
extra_kwargs = {'test_user': {'required': True}, 'type': {'required': True}}
def validate(self, attrs):
type2 = attrs.get('type2', 20)
@ -126,7 +127,10 @@ class FtestSerializer(CustomModelSerializer):
def validate(self, attrs):
ftest_work: FtestWork = attrs.get('ftest_work', None)
if ftest_work:
test_user = attrs.get('test_user', None)
attrs['type'] = ftest_work.type
if test_user is None:
attrs['test_user'] = ftest_work.test_user
return attrs
def create(self, validated_data):