connect transaction serializer create to viewset create
This commit is contained in:
@@ -8,9 +8,11 @@ from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework import viewsets
|
||||
from apps.herd.models import Rancher
|
||||
from rest_framework import status
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
@@ -104,6 +106,25 @@ class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, DynamicSearchM
|
||||
]
|
||||
date_field = "create_date"
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" create transaction with product items """
|
||||
|
||||
organization = self.get_device_organization()
|
||||
device = self.get_pos_device()
|
||||
|
||||
serializer = self.serializer_class(data=request.data, context={
|
||||
'organization': organization,
|
||||
'pos_device': device,
|
||||
'request': self.request
|
||||
|
||||
})
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
return Response(serializer.errors, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
|
||||
@@ -132,6 +132,8 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
|
||||
# create transaction record
|
||||
transaction = warehouse_models.InventoryQuotaSaleTransaction.objects.create(
|
||||
seller_organization=self.context['organization'],
|
||||
pos_device=self.context['pos_device'],
|
||||
**validated_data
|
||||
)
|
||||
|
||||
@@ -231,7 +233,3 @@ class QuotaPreSaleItemSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = warehouse_models.QuotaPreSaleItem
|
||||
fields = '__all__'
|
||||
|
||||
def create(self, validated_data):
|
||||
with atomic():
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user