feat: MaterialBatch返回can_mio

This commit is contained in:
caoqianming 2025-08-07 15:39:43 +08:00
parent 783f288926
commit d3f83605aa
2 changed files with 11 additions and 1 deletions

View File

@ -5,7 +5,7 @@ from apps.sam.models import Customer, Order
from apps.mtm.models import Material, Mgroup
from apps.system.models import User
from datetime import datetime
from django.db.models import Max
from django.db.models import Max, Sum
# Create your models here.
@ -39,6 +39,10 @@ class MaterialBatch(BaseModel):
defect = models.ForeignKey('qm.defect', verbose_name='缺陷', on_delete=models.PROTECT, null=True, blank=True)
@property
def count_mioing(self):
return MIOItem.objects.filter(mb=self, mio__submit_time__isnull=True).aggregate(count=Sum('count'))['count'] or 0
class MaterialBatchA(BaseModel):
"""
TN:组合件物料批次

View File

@ -53,6 +53,12 @@ class MaterialBatchSerializer(CustomModelSerializer):
model = MaterialBatch
fields = '__all__'
read_only_fields = EXCLUDE_FIELDS_BASE
def to_representation(self, instance):
ret = super().to_representation(instance)
if 'count' in ret and 'count_mioing' in ret:
ret['count_canmio'] = str(Decimal(ret['count']) - Decimal(ret['count_mioing']))
return ret
class MaterialBatchDetailSerializer(CustomModelSerializer):