pos device transaction list
This commit is contained in:
@@ -72,8 +72,45 @@ class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDevice
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet):
|
||||
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
|
||||
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
|
||||
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['']
|
||||
search_fields = [
|
||||
"rancher__union_name",
|
||||
"rancher__union_code",
|
||||
"rancher__first_name",
|
||||
"rancher__last_name",
|
||||
"rancher__national_code",
|
||||
"pos_device__device_identity",
|
||||
"pos_device__serial",
|
||||
"transaction_id",
|
||||
"seller_organization__name",
|
||||
"quota_distribution__distribution_id",
|
||||
"inventory_entry__distribution__distribution_id",
|
||||
"product__name",
|
||||
"transaction_status",
|
||||
]
|
||||
date_field = "create_date"
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
url_path='transactions',
|
||||
url_name='transactions',
|
||||
name='transactions',
|
||||
)
|
||||
@transaction.atomic
|
||||
def transactions(self, request):
|
||||
""" pos transactions list """
|
||||
|
||||
# get device object
|
||||
device = self.get_pos_device()
|
||||
|
||||
queryset = self.queryset.filter(pos_device=device)
|
||||
queryset = self.filter_query(queryset)
|
||||
|
||||
# paginate & response
|
||||
page = self.paginate_queryset(queryset)
|
||||
if page is not None:
|
||||
serializer = self.get_serializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
@@ -1,10 +1,9 @@
|
||||
from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer
|
||||
from apps.herd.pos.api.v1.serializers import RancherSerializer
|
||||
from apps.warehouse.exceptions import (
|
||||
InventoryEntryWeightException,
|
||||
TotalInventorySaleException
|
||||
)
|
||||
from apps.product.exceptions import QuotaExpiredTimeException
|
||||
from apps.warehouse import models as warehouse_models
|
||||
from apps.authorization.models import UserRelations
|
||||
from rest_framework import serializers
|
||||
from django.db import models
|
||||
|
||||
@@ -52,7 +51,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
class Meta: # noqa
|
||||
model = warehouse_models.InventoryQuotaSaleTransaction
|
||||
fields = '__all__'
|
||||
depth = 0
|
||||
@@ -74,20 +73,15 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer):
|
||||
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
""" Custom create & set some parameters like seller & buyer """
|
||||
def to_representation(self, instance):
|
||||
""" customize output of transactions serializer """
|
||||
|
||||
distribution = validated_data['quota_distribution']
|
||||
seller_organization = distribution.assigned_organization
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
user = self.context['request'].user
|
||||
buyer_user = user
|
||||
seller_user = validated_data['inventory_entry'].created_by
|
||||
representation['rancher'] = RancherSerializer(instance.rancher).data
|
||||
representation['pos_device'] = DeviceSerializer(instance.pos_device).data
|
||||
representation['seller_organization'] = instance.seller_organization.name
|
||||
representation['inventory_entry'] = InventoryEntrySerializer(instance.inventory_entry).data
|
||||
|
||||
return warehouse_models.InventoryQuotaSaleTransaction.objects.create(
|
||||
seller_organization=seller_organization,
|
||||
seller_user=seller_user,
|
||||
buyer_user=buyer_user,
|
||||
**validated_data
|
||||
)
|
||||
return representation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user