feat: wmaterial添加can_handover字段

This commit is contained in:
caoqianming 2025-06-18 10:31:35 +08:00
parent 39c86a14d5
commit 6af708d4f0
2 changed files with 8 additions and 1 deletions

View File

@ -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):
"""

View File

@ -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):