feat: MaterialBatch返回can_mio
This commit is contained in:
parent
783f288926
commit
d3f83605aa
|
@ -5,7 +5,7 @@ from apps.sam.models import Customer, Order
|
||||||
from apps.mtm.models import Material, Mgroup
|
from apps.mtm.models import Material, Mgroup
|
||||||
from apps.system.models import User
|
from apps.system.models import User
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from django.db.models import Max
|
from django.db.models import Max, Sum
|
||||||
# Create your models here.
|
# 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)
|
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):
|
class MaterialBatchA(BaseModel):
|
||||||
"""
|
"""
|
||||||
TN:组合件物料批次
|
TN:组合件物料批次
|
||||||
|
|
|
@ -54,6 +54,12 @@ class MaterialBatchSerializer(CustomModelSerializer):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = EXCLUDE_FIELDS_BASE
|
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):
|
class MaterialBatchDetailSerializer(CustomModelSerializer):
|
||||||
warehouse_name = serializers.CharField(
|
warehouse_name = serializers.CharField(
|
||||||
|
|
Loading…
Reference in New Issue