pos device transaction list
This commit is contained in:
@@ -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