fix: mlog update时mlogb不更新

This commit is contained in:
caoqianming 2024-01-28 00:18:10 +08:00
parent 08f9fa106a
commit d483bb6b61
1 changed files with 4 additions and 14 deletions

View File

@ -271,20 +271,10 @@ class MlogSerializer(CustomModelSerializer):
with transaction.atomic():
mlogb = validated_data.pop('mlogb', [])
instance = super().update(instance, validated_data)
brotherId_should_list = instance.material_out.brothers
if brotherId_should_list:
if mlogb:
Mlogb.objects.filter(mlog=instance).update(count_ok=0)
for item in mlogb:
id = item.get('id', None)
if id:
mlogb = Mlogb.objects.get(id=id)
mlogb.count_ok = item['count_ok']
mlogb.save()
# elif item['material_out'].id in brotherId_should_list:
# Mlogb.objects.create(
# mlog=instance, material_out=item['material_out'], count_ok=item['count_ok'])
else:
raise ValidationError('缺少产出物信息')
Mlogb.objects.filter(mlog=instance, material_out=item['material_out']).update(count_ok=item['count_ok'])
return instance
def validate(self, attrs):