feat: mlogb 添加字段以记录分层检验信息
This commit is contained in:
parent
0148efba62
commit
bb311999e8
|
@ -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='备注'),
|
||||
),
|
||||
]
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue