add party create api
This commit is contained in:
@@ -128,6 +128,7 @@ class MultipleOrderAddSerializer(serializers.Serializer):
|
|||||||
unit_amount = serializers.IntegerField()
|
unit_amount = serializers.IntegerField()
|
||||||
currency = serializers.ChoiceField(choices=[('uzs', 'uzs'), ('usd', 'usd')])
|
currency = serializers.ChoiceField(choices=[('uzs', 'uzs'), ('usd', 'usd')])
|
||||||
amount = serializers.IntegerField()
|
amount = serializers.IntegerField()
|
||||||
|
date = serializers.DateField()
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
product = Product.objects.filter(id=data['product_id']).first()
|
product = Product.objects.filter(id=data['product_id']).first()
|
||||||
@@ -136,7 +137,7 @@ class MultipleOrderAddSerializer(serializers.Serializer):
|
|||||||
unity = Unity.objects.filter(id=data['unity_id']).first()
|
unity = Unity.objects.filter(id=data['unity_id']).first()
|
||||||
if not unity:
|
if not unity:
|
||||||
raise serializers.ValidationError("Unity not found")
|
raise serializers.ValidationError("Unity not found")
|
||||||
wherehouse = WhereHouse.objects.filter(id=data['wherehouse_id'])
|
wherehouse = WhereHouse.objects.filter(id=data['wherehouse_id']).first()
|
||||||
if not wherehouse:
|
if not wherehouse:
|
||||||
raise serializers.ValidationError("WhereHouse not found")
|
raise serializers.ValidationError("WhereHouse not found")
|
||||||
counterparty = Counterparty.objects.filter(id=data['counterparty_id']).first()
|
counterparty = Counterparty.objects.filter(id=data['counterparty_id']).first()
|
||||||
|
|||||||
@@ -42,8 +42,23 @@ class PartyCreateSerializer(serializers.Serializer):
|
|||||||
quantity=resource.get('quantity'),
|
quantity=resource.get('quantity'),
|
||||||
unit_amount=resource.get('unit_amount'),
|
unit_amount=resource.get('unit_amount'),
|
||||||
currency=resource.get('currency'),
|
currency=resource.get('currency'),
|
||||||
amount=resource.get('amount'),
|
total_price=resource.get('amount'),
|
||||||
|
date=resource.get('date'),
|
||||||
))
|
))
|
||||||
total_price += resource.get('amount')
|
total_price += resource.get('amount')
|
||||||
created_orders = Order.objects.bulk_create(orders)
|
created_orders = Order.objects.bulk_create(orders)
|
||||||
|
party = Party.objects.create(
|
||||||
|
mediator=validated_data.get('user'),
|
||||||
|
delivery_date=validated_data.get('delivery_date'),
|
||||||
|
payment_date=validated_data.get('payment_date'),
|
||||||
|
comment=validated_data.get('comment'),
|
||||||
|
audit=validated_data.get('audit'),
|
||||||
|
audit_comment=validated_data.get('audit_comment')
|
||||||
|
)
|
||||||
|
party.orders.add(*created_orders)
|
||||||
|
party.save()
|
||||||
|
PartyAmount.objects.create(
|
||||||
|
total_price=total_price,
|
||||||
|
party=party,
|
||||||
|
)
|
||||||
|
return party
|
||||||
@@ -2,6 +2,7 @@ from django.urls import path, include
|
|||||||
|
|
||||||
from core.apps.orders.views import order as order_views
|
from core.apps.orders.views import order as order_views
|
||||||
from core.apps.orders.views import offer as offer_views
|
from core.apps.orders.views import offer as offer_views
|
||||||
|
from core.apps.orders.views import party as party_views
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -24,4 +25,9 @@ urlpatterns = [
|
|||||||
path('<uuid:id>/update/', offer_views.OfferUpdateApiView.as_view()),
|
path('<uuid:id>/update/', offer_views.OfferUpdateApiView.as_view()),
|
||||||
]
|
]
|
||||||
)),
|
)),
|
||||||
|
path('party/', include(
|
||||||
|
[
|
||||||
|
path('create/', party_views.PartyCreateApiView.as_view()),
|
||||||
|
]
|
||||||
|
)),
|
||||||
]
|
]
|
||||||
26
core/apps/orders/views/party.py
Normal file
26
core/apps/orders/views/party.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from rest_framework import generics, views
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from core.apps.accounts.permissions.permissions import HasRolePermission
|
||||||
|
from core.apps.orders.serializers import party as serializers
|
||||||
|
from core.apps.orders.models import Order, Party, PartyAmount
|
||||||
|
|
||||||
|
|
||||||
|
class PartyCreateApiView(generics.GenericAPIView):
|
||||||
|
serializer_class = serializers.PartyCreateSerializer
|
||||||
|
queryset = Party.objects.all()
|
||||||
|
permission_classes = [HasRolePermission]
|
||||||
|
required_permissions = []
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
serializer = self.serializer_class(data=request.data)
|
||||||
|
if serializer.is_valid(raise_exception=True):
|
||||||
|
serializer.save()
|
||||||
|
return Response(
|
||||||
|
{'success': True, 'message': "party created"},
|
||||||
|
status=200
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
{'success': False, 'message': 'error while party created', 'error': serializer.errors},
|
||||||
|
status=400
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user