feat: mio 列表接口新增 total_price 返回明细金额合计
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4d2a88ab1e
commit
3129cc0e54
|
|
@ -10,6 +10,7 @@ from apps.utils.serializers import CustomModelSerializer
|
|||
from apps.mtm.models import Material
|
||||
from .models import MIO, MaterialBatch, MIOItem, WareHouse, MIOItemA, MaterialBatchA, MIOItemw, Pack
|
||||
from django.db import transaction
|
||||
from django.db.models import F, Sum, DecimalField
|
||||
from server.settings import get_sysconfig
|
||||
from apps.wpmw.models import Wpr
|
||||
from decimal import Decimal
|
||||
|
|
@ -97,6 +98,7 @@ class MIOListSerializer(CustomModelSerializer):
|
|||
order_number = serializers.CharField(source='order.number', read_only=True)
|
||||
pu_order_number = serializers.CharField(
|
||||
source='pu_order.number', read_only=True)
|
||||
total_price = serializers.SerializerMethodField(label='总价格')
|
||||
|
||||
class Meta:
|
||||
model = MIO
|
||||
|
|
@ -104,6 +106,12 @@ class MIOListSerializer(CustomModelSerializer):
|
|||
read_only_fields = EXCLUDE_FIELDS + \
|
||||
['state', 'submit_time', 'submit_user', 'number']
|
||||
|
||||
def get_total_price(self, obj):
|
||||
res = MIOItem.objects.filter(mio=obj, unit_price__isnull=False).aggregate(
|
||||
total=Sum(F('count') * F('unit_price'),
|
||||
output_field=DecimalField(max_digits=18, decimal_places=4)))
|
||||
return res['total']
|
||||
|
||||
|
||||
class MIOItemACreateSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
|
|
|
|||
Loading…
Reference in New Issue