diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 600a52ad..02195c10 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -125,6 +125,10 @@ class WMaterial(CommonBDModel): def count_working(self): return Mlogb.objects.filter(wm_in=self, mlog__submit_time__isnull=True).aggregate(count=Sum('count_use'))['count'] or 0 + @property + def count_handovering(self): + return Handoverb.objects.filter(wm=self, submit_time__isnull=True).aggregate(count=Sum('count'))['count'] or 0 + @classmethod def mat_in_qs(cls, mtask: Mtask, qs=None): """ diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index e1f79d87..c0928944 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -192,6 +192,7 @@ class WMaterialSerializer(CustomModelSerializer): notok_sign_name = serializers.SerializerMethodField() defect_name = serializers.CharField(source="defect.name", read_only=True) count_working = serializers.IntegerField(read_only=True, label='在制数量') + count_handovering = 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 @@ -202,8 +203,10 @@ class WMaterialSerializer(CustomModelSerializer): def to_representation(self, instance): ret = super().to_representation(instance) - if 'count' in ret: + if 'count' in ret and 'count_working' in ret: ret['count_cando'] = str(Decimal(ret['count']) - Decimal(ret['count_working'])) + if 'count' in ret and 'count_handovering' in ret: + ret['count_canhandover'] = str(Decimal(ret['count']) - Decimal(ret['count_handovering'])) return ret class MlogbDefectSerializer(CustomModelSerializer):