feat: wmaterialserializer 增加count_cando返回

This commit is contained in:
caoqianming 2024-09-18 09:34:55 +08:00
parent 6c6a6ce440
commit 305fda44c2
2 changed files with 7 additions and 2 deletions

View File

@ -109,7 +109,7 @@ class WMaterial(CommonBDModel):
@property
def count_working(self):
return int(Mlogb.objects.filter(wm_in=self, mlog__work_end_time__isnull=True).aggregate(count=Sum('count_use'))['count'] or 0)
return Mlogb.objects.filter(wm_in=self, mlog__work_end_time__isnull=True).aggregate(count=Sum('count_use'))['count'] or 0
class Fmlog(CommonADModel):
route = models.ForeignKey(Route, verbose_name='生产路线', on_delete=models.SET_NULL, null=True, blank=True)

View File

@ -181,7 +181,7 @@ class WMaterialSerializer(CustomModelSerializer):
source='belong_dept.name', read_only=True)
material_origin_name = serializers.StringRelatedField(source='material_origin', read_only=True)
notok_sign_name = serializers.SerializerMethodField()
count_working = serializers.CharField(read_only=True, label='在制数量')
count_working = serializers.IntegerField(read_only=True, label='在制数量')
def get_notok_sign_name(self, obj):
return getattr(NotOkOption, obj.notok_sign, NotOkOption.qt).label if obj.notok_sign else None
@ -189,6 +189,11 @@ class WMaterialSerializer(CustomModelSerializer):
class Meta:
model = WMaterial
fields = '__all__'
def to_representation(self, instance):
ret = super().to_representation(instance)
ret['count_cando'] = ret['count'] - ret['count_working']
return ret
class MlogbSerializer(CustomModelSerializer):