fix: mlogserializer material_outs_ bug修复
This commit is contained in:
parent
6accd25620
commit
2cd4a68e23
|
@ -120,9 +120,11 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Mlog
|
model = Mlog
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = EXCLUDE_FIELDS + ['submit_time', 'submit_user']
|
read_only_fields = EXCLUDE_FIELDS + \
|
||||||
|
['submit_time', 'submit_user', 'material_outs']
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
print(1, validated_data)
|
||||||
mtask = validated_data.get('mtask', None)
|
mtask = validated_data.get('mtask', None)
|
||||||
batch = validated_data['batch']
|
batch = validated_data['batch']
|
||||||
handle_date = validated_data['handle_date']
|
handle_date = validated_data['handle_date']
|
||||||
|
@ -141,12 +143,12 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
if Mlog.objects.filter(mtask=mtask, batch=batch, handle_date=handle_date, handle_user=handle_user).exists():
|
if Mlog.objects.filter(mtask=mtask, batch=batch, handle_date=handle_date, handle_user=handle_user).exists():
|
||||||
raise ValidationError('存在相同的日志记录')
|
raise ValidationError('存在相同的日志记录')
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
material_outs = validated_data.pop('material_outs', [])
|
material_outs_ = validated_data.pop('material_outs_', [])
|
||||||
instance = super().create(validated_data)
|
instance = super().create(validated_data)
|
||||||
brotherId_should_list = material_out.brothers
|
brotherId_should_list = material_out.brothers
|
||||||
if brotherId_should_list:
|
if brotherId_should_list:
|
||||||
if material_outs:
|
if material_outs_:
|
||||||
for item in material_outs:
|
for item in material_outs_:
|
||||||
if item['material_out'].id in brotherId_should_list:
|
if item['material_out'].id in brotherId_should_list:
|
||||||
Mlogb.objects.create(
|
Mlogb.objects.create(
|
||||||
mlog=instance, material_out=item['material_out'], count_ok=item['count_ok'])
|
mlog=instance, material_out=item['material_out'], count_ok=item['count_ok'])
|
||||||
|
@ -161,12 +163,12 @@ class MlogSerializer(CustomModelSerializer):
|
||||||
validated_data.pop('handle_user', None)
|
validated_data.pop('handle_user', None)
|
||||||
validated_data.pop('mgroup', None)
|
validated_data.pop('mgroup', None)
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
material_outs = validated_data.pop('material_outs', [])
|
material_outs_ = validated_data.pop('material_outs_', [])
|
||||||
instance = super().update(instance, validated_data)
|
instance = super().update(instance, validated_data)
|
||||||
brotherId_should_list = instance.material_out.brothers
|
brotherId_should_list = instance.material_out.brothers
|
||||||
if brotherId_should_list:
|
if brotherId_should_list:
|
||||||
if material_outs:
|
if material_outs_:
|
||||||
for item in material_outs:
|
for item in material_outs_:
|
||||||
id = item.get('id', None)
|
id = item.get('id', None)
|
||||||
if id:
|
if id:
|
||||||
mlogb = Mlogb.objects.get(id=id)
|
mlogb = Mlogb.objects.get(id=id)
|
||||||
|
|
Loading…
Reference in New Issue