feat: mlogbw增加质检保存bug
This commit is contained in:
parent
a20b15abed
commit
51123ee0c5
|
@ -270,7 +270,7 @@ class FtestProcessSerializer(CustomModelSerializer):
|
|||
class Meta:
|
||||
model = Ftest
|
||||
fields = ["id", "test_date",
|
||||
"test_user", "note", "ftestitems", "ftestdefects", "qct", "test_user_name"]
|
||||
"test_user", "note", "ftestitems", "ftestdefects", "qct", "test_user_name", "wpr"]
|
||||
extra_kwargs = {"qct": {"required": True}}
|
||||
|
||||
def validate(self, attrs):
|
||||
|
@ -286,8 +286,8 @@ class FtestProcessSerializer(CustomModelSerializer):
|
|||
FtestItem.objects.create(ftest=instance, **item)
|
||||
is_ok = True
|
||||
for item2 in ftestdefects:
|
||||
defect:Defect = item["defect"]
|
||||
if defect.okcate in [Defect.DEFECT_NOTOK] and item["has"]:
|
||||
defect:Defect = item2["defect"]
|
||||
if defect.okcate in [Defect.DEFECT_NOTOK] and item2["has"]:
|
||||
is_ok = False
|
||||
FtestDefect.objects.create(ftest=instance, **item2)
|
||||
instance.is_ok = is_ok
|
||||
|
|
|
@ -580,6 +580,8 @@ class MlogbwCreateUpdateSerializer(CustomModelSerializer):
|
|||
|
||||
def validate(self, attrs):
|
||||
mlogb:Mlogb = attrs["mlogb"]
|
||||
if mlogb.mlog.submit_time is not None:
|
||||
raise ParseError('生产日志已提交不可编辑')
|
||||
wpr:Wpr = attrs.get("wpr", None)
|
||||
in_or_out, tracking = mlogb.get_tracking()
|
||||
if tracking != Material.MA_TRACKING_SINGLE:
|
||||
|
@ -589,35 +591,39 @@ class MlogbwCreateUpdateSerializer(CustomModelSerializer):
|
|||
return attrs
|
||||
|
||||
def save_ftest(self, mlogbw, ftest_data):
|
||||
if "id" not in ftest_data:
|
||||
if "id" not in ftest_data or not ftest_data["id"]:
|
||||
ftest_sr = FtestProcessSerializer(data=ftest_data)
|
||||
ftest_sr.is_valid(raise_exception=True)
|
||||
ftest = ftest_sr.save()
|
||||
ftest = ftest_sr.create(ftest_data)
|
||||
mlogbw.ftest = ftest
|
||||
mlogbw.save()
|
||||
else:
|
||||
ftest_sr = FtestProcessSerializer(instance=Ftest.objects.get(id=ftest_data["id"]), data=ftest_data)
|
||||
ftest_sr.is_valid(raise_exception=True)
|
||||
ftest_sr.save()
|
||||
ftest_sr = FtestProcessSerializer()
|
||||
ftest_sr.update(instance=Ftest.objects.get(id=ftest_data["id"]), validated_data=ftest_data)
|
||||
return mlogbw
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, validated_data):
|
||||
ftest_data = validated_data.pop("ftest", None)
|
||||
mlogbw = super().create(validated_data)
|
||||
return self.save_ftest(mlogbw, ftest_data)
|
||||
if ftest_data:
|
||||
mlogbw = self.save_ftest(mlogbw, ftest_data)
|
||||
return mlogbw
|
||||
|
||||
@transaction.atomic
|
||||
def update(self, instance, validated_data):
|
||||
validated_data.pop("mlogb")
|
||||
ftest_data = validated_data.pop("ftest", None)
|
||||
mlogbw = super().update(instance, validated_data)
|
||||
return self.save_ftest(mlogbw, ftest_data)
|
||||
if ftest_data:
|
||||
mlogbw = self.save_ftest(mlogbw, ftest_data)
|
||||
return mlogbw
|
||||
|
||||
class MlogbOutUpdateSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
model = Mlogb
|
||||
fields = "__all__"
|
||||
read_only_fields = EXCLUDE_FIELDS_BASE + ['mlog', 'mtask', 'wm_in', 'material_in', 'material_out', 'count_use', 'count_break', 'count_pn_jgqbl']
|
||||
read_only_fields = EXCLUDE_FIELDS_BASE + ['mlog', 'mtask', 'wm_in', 'material_in', 'material_out',
|
||||
'count_use', 'count_break', 'count_pn_jgqbl']
|
||||
|
||||
def validate(self, attrs):
|
||||
count_notok_json = attrs.get('count_notok_json', [])
|
||||
|
|
|
@ -604,8 +604,6 @@ class MlogbwViewSet(CustomModelViewSet):
|
|||
def perform_create(self, serializer):
|
||||
ins:Mlogbw = serializer.save()
|
||||
mlogb:Mlogb = ins.mlogb
|
||||
if mlogb.mlog.submit_time is not None:
|
||||
raise ParseError('日志已提交不可修改')
|
||||
self.cal_mlogb_count(mlogb)
|
||||
# 如果是输入且输出追踪到个,需同步创建
|
||||
material_in:Material = mlogb.material_in
|
||||
|
@ -623,11 +621,9 @@ class MlogbwViewSet(CustomModelViewSet):
|
|||
@transaction.atomic
|
||||
def perform_destroy(self, instance:Mlogbw):
|
||||
mlogb = instance.mlogb
|
||||
if mlogb.mlog.submit_time is not None:
|
||||
raise ParseError('日志已提交不可修改')
|
||||
instance.delete()
|
||||
if instance.ftest:
|
||||
instance.ftest.delete()
|
||||
instance.delete()
|
||||
self.cal_mlogb_count(mlogb)
|
||||
# 如果是输入且输出追踪到个,需同步删除
|
||||
material_in: Material = mlogb.material_in
|
||||
|
@ -635,7 +631,10 @@ class MlogbwViewSet(CustomModelViewSet):
|
|||
mlogb_to = mlogb.mlogb_to
|
||||
material_out: Material = mlogb.mlog.material_out
|
||||
if mlogb_to and material_out.tracking == Material.MA_TRACKING_SINGLE:
|
||||
Mlogbw.objects.filter(mlogb=mlogb_to, wpr=instance.wpr).delete()
|
||||
mbw = Mlogbw.objects.get(mlogb=mlogb_to, wpr=instance.wpr)
|
||||
if mbw.ftest:
|
||||
mbw.ftest.delete()
|
||||
mbw.delete()
|
||||
self.cal_mlogb_count(mlogb_to)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue