From bb311999e8f81762c4f51506d835bea7b3ead9f7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 3 Sep 2024 14:16:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mlogb=20=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=BB=A5=E8=AE=B0=E5=BD=95=E5=88=86=E5=B1=82=E6=A3=80?= =?UTF-8?q?=E9=AA=8C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wpm/migrations/0066_auto_20240903_1401.py | 28 +++++++++++++++++++ apps/wpm/models.py | 3 ++ apps/wpm/serializers.py | 27 ++++++++++++++++-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 apps/wpm/migrations/0066_auto_20240903_1401.py diff --git a/apps/wpm/migrations/0066_auto_20240903_1401.py b/apps/wpm/migrations/0066_auto_20240903_1401.py new file mode 100644 index 00000000..98e1ff94 --- /dev/null +++ b/apps/wpm/migrations/0066_auto_20240903_1401.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.12 on 2024-09-03 06:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0065_auto_20240903_0904'), + ] + + operations = [ + migrations.AddField( + model_name='mlog', + name='test_file', + field=models.TextField(blank=True, null=True, verbose_name='检验文件'), + ), + migrations.AddField( + model_name='mlogb', + name='count_notok_json', + field=models.JSONField(blank=True, default=list, verbose_name='不合格情况'), + ), + migrations.AddField( + model_name='mlogb', + name='note', + field=models.TextField(blank=True, default='', verbose_name='备注'), + ), + ] diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 7085bdcb..9c91e58a 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -215,6 +215,7 @@ class Mlog(CommonADModel): oinfo_json = models.JSONField('其他信息', default=dict, blank=True) ticket = models.ForeignKey('wf.ticket', verbose_name='关联工单', on_delete=models.SET_NULL, related_name='mlog_ticket', null=True, blank=True, db_constraint=False) + test_file = models.TextField('检验文件', null=True, blank=True) @property def mlogb(self): @@ -233,6 +234,7 @@ class Mlog(CommonADModel): class Mlogb(BaseModel): mlog = models.ForeignKey(Mlog, verbose_name='关联日志', on_delete=models.CASCADE, related_name='b_mlog') + note = models.TextField('备注', default='', blank=True) batch = models.CharField('批次号', max_length=50, null=True, blank=True) mtask = models.ForeignKey(Mtask, verbose_name='关联任务', on_delete=models.CASCADE, related_name='mlogb_mtask', null=True, blank=True) @@ -265,6 +267,7 @@ class Mlogb(BaseModel): count_n_txd = models.PositiveIntegerField('同心度', default=0) count_n_hd = models.PositiveIntegerField('厚度', default=0) count_n_qt = models.PositiveIntegerField('其他', default=0) + count_notok_json = models.JSONField('不合格情况', default=list, blank=True) class Handover(CommonADModel): """ diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index b40352cc..46fdf69e 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -371,7 +371,7 @@ class MlogInitSerializer(CustomModelSerializer): class MlogChangeSerializer(CustomModelSerializer): class Meta: model = Mlog - fields = ['id', 'work_end_time', 'handle_user', 'note', 'oinfo_json'] + fields = ['id', 'work_end_time', 'handle_user', 'note', 'oinfo_json', 'test_file'] def validate(self, attrs): if attrs.get('work_end_time', None): @@ -382,7 +382,7 @@ class MlogChangeSerializer(CustomModelSerializer): class MlogbInSerializer(CustomModelSerializer): class Meta: model = Mlogb - fields = ['id', 'mlog', 'mtask', 'wm_in', 'count_use', 'count_n_jgqbl', 'count_break'] + fields = ['id', 'mlog', 'mtask', 'wm_in', 'count_use', 'count_n_jgqbl', 'count_break', 'note'] extra_kwargs = {'count_use': {'required': True}, 'mtask': {'required': True}, 'wm_in': {'required': True}} def validate(self, attrs): @@ -420,7 +420,7 @@ class MlogbInSerializer(CustomModelSerializer): class MlogbInUpdateSerializer(CustomModelSerializer): class Meta: model = Mlogb - fields = ['id', 'count_use', 'count_break', 'count_n_jqgbl'] + fields = ['id', 'count_use', 'count_break', 'count_n_jgqbl', 'note'] class MlogbOutUpdateSerializer(CustomModelSerializer): class Meta: @@ -429,6 +429,27 @@ class MlogbOutUpdateSerializer(CustomModelSerializer): read_only_fields = EXCLUDE_FIELDS_BASE + ['mlog', 'mtask', 'wm_in', 'material_in', 'material_out', 'count_use', 'count_break', 'count_n_jgqbl'] def validate(self, attrs): + count_notok_json = attrs.get('count_notok_json', []) + # count_notok_json字段处理 + if count_notok_json: + # 先置0字段 + for i in attrs: + if 'count_n_' in i: + i = 0 + count_notok_dict = {} + for item in count_notok_json: + notok = item['notok'] + count = item['count'] + full_notok = f'count_n_{notok}' + if not hasattr(Mlogb, full_notok): + raise ValidationError(f'{notok}-该不合格项不存在') + if full_notok in count_notok_dict: + count_notok_dict[full_notok] = count_notok_dict[full_notok] + count + else: + count_notok_dict[full_notok] = count + for k, v in count_notok_dict.items(): + attrs[k] = v + count_notok = 0 for i in attrs: if 'count_n_' in i: