change party list api
This commit is contained in:
@@ -11,4 +11,12 @@ class CounterpartySerializer(serializers.ModelSerializer):
|
|||||||
model = Counterparty
|
model = Counterparty
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'name', 'type', 'status', 'description', 'start_date', 'person'
|
'id', 'name', 'type', 'status', 'description', 'start_date', 'person'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CounterpartyListPartySerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Counterparty
|
||||||
|
fields = [
|
||||||
|
'id', 'name',
|
||||||
]
|
]
|
||||||
@@ -5,6 +5,7 @@ from rest_framework import serializers
|
|||||||
from core.apps.orders.models import Party, PartyAmount, Order, DeletedParty
|
from core.apps.orders.models import Party, PartyAmount, Order, DeletedParty
|
||||||
from core.apps.orders.serializers.order import MultipleOrderAddSerializer, OrderListSerializer
|
from core.apps.orders.serializers.order import MultipleOrderAddSerializer, OrderListSerializer
|
||||||
from core.apps.accounts.models import User
|
from core.apps.accounts.models import User
|
||||||
|
from core.apps.counterparty.serializers.counterparty import CounterpartyListPartySerializer
|
||||||
|
|
||||||
|
|
||||||
class PartyCreateSerializer(serializers.Serializer):
|
class PartyCreateSerializer(serializers.Serializer):
|
||||||
@@ -81,27 +82,50 @@ class PartyAmountSerializer(serializers.ModelSerializer):
|
|||||||
class PartyDetailSerializer(serializers.ModelSerializer):
|
class PartyDetailSerializer(serializers.ModelSerializer):
|
||||||
orders = OrderListSerializer(many=True)
|
orders = OrderListSerializer(many=True)
|
||||||
party_amount = PartyAmountSerializer()
|
party_amount = PartyAmountSerializer()
|
||||||
|
mediator = serializers.SerializerMethodField(method_name='get_mediator')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Party
|
model = Party
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'number', 'delivery_date', 'closed_date', 'order_date', 'payment_date', 'status',
|
'id', 'number', 'delivery_date', 'closed_date', 'order_date', 'payment_date', 'status',
|
||||||
'payment_status', 'process', 'confirmation', 'comment', 'audit', 'audit_comment',
|
'payment_status', 'process', 'confirmation', 'comment', 'audit', 'audit_comment',
|
||||||
'orders', 'party_amount'
|
'orders', 'party_amount', 'mediator',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_mediator(self, obj):
|
||||||
|
return {
|
||||||
|
'id': obj.mediator.id,
|
||||||
|
'full_name': obj.mediator.full_name
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PartyListSerializer(serializers.ModelSerializer):
|
class PartyListSerializer(serializers.ModelSerializer):
|
||||||
party_amount = PartyAmountSerializer()
|
party_amount = PartyAmountSerializer()
|
||||||
|
mediator = serializers.SerializerMethodField(method_name='get_mediator')
|
||||||
|
counterparty = serializers.SerializerMethodField(method_name='get_counterparty')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Party
|
model = Party
|
||||||
fields = [
|
fields = [
|
||||||
'id','number', 'delivery_date', 'closed_date', 'order_date', 'payment_date', 'status',
|
'id','number', 'delivery_date', 'closed_date', 'order_date', 'payment_date', 'status',
|
||||||
'payment_status', 'process', 'confirmation', 'comment', 'audit', 'audit_comment',
|
'payment_status', 'process', 'confirmation', 'comment', 'audit', 'audit_comment',
|
||||||
'party_amount'
|
'party_amount', 'mediator', 'counterparty'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_mediator(self, obj):
|
||||||
|
return {
|
||||||
|
'id': obj.mediator.id,
|
||||||
|
'full_name': obj.mediator.full_name
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_counterparty(self, obj):
|
||||||
|
counterparties = obj.orders.values("counterparty__id", "counterparty__name").distinct()
|
||||||
|
counterparties = [
|
||||||
|
{"id": c["counterparty__id"], "name": c["counterparty__name"]}
|
||||||
|
for c in counterparties
|
||||||
|
]
|
||||||
|
return CounterpartyListPartySerializer(counterparties, many=True).data
|
||||||
|
|
||||||
|
|
||||||
class DeletedPartyCreateSerializer(serializers.Serializer):
|
class DeletedPartyCreateSerializer(serializers.Serializer):
|
||||||
comment = serializers.CharField(required=False)
|
comment = serializers.CharField(required=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user