From 19a26b3a1434541ab7bb535197f8815fc51feff5 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 22 Sep 2025 11:01:20 +0330 Subject: [PATCH] fix serializer for gov & free product on serializer --- apps/warehouse/pos/api/v1/serializers.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/warehouse/pos/api/v1/serializers.py b/apps/warehouse/pos/api/v1/serializers.py index 1a667b1..d7dd0b3 100644 --- a/apps/warehouse/pos/api/v1/serializers.py +++ b/apps/warehouse/pos/api/v1/serializers.py @@ -8,6 +8,7 @@ from apps.product.services.services import ( from apps.pos_device.services.services import pos_organizations_sharing_information from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer from apps.product.exceptions import DistributionWeightException +from apps.pos_device.models import POSFreeProducts from apps.warehouse.services.services import ( create_extra_sale, create_pre_sale @@ -137,14 +138,21 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer): # calculate total price of product items in shopping cart total_price = 0 for item_data in items_data: + # get product by type + gov_product = item_data.pop('gov_product') if 'gov_product' in item_data.keys() else None + free_product = item_data.pop('free_product') if 'free_product' in item_data.keys() else None + item = warehouse_models.InventoryQuotaSaleItem.objects.create( transaction=transaction, quota_distribution=QuotaDistribution.objects.get( id=item_data.pop('quota_distribution') ), - product=Product.objects.get( - id=item_data.pop('product') - ), + gov_product=Product.objects.get( + id=gov_product + ) if Product.objects.filter(id=gov_product).exists() else None, + free_product=POSFreeProducts.objects.get( + id=free_product + ) if POSFreeProducts.objects.filter(id=free_product).exists() else None, **item_data ) total_price += item.total_price @@ -190,6 +198,9 @@ class InventoryQuotaSaleTransactionSerializer(serializers.ModelSerializer): if instance.seller_organization: representation['seller_organization'] = instance.seller_organization.name + # get product items of transaction + representation['items'] = InventoryQuotaSaleItemSerializer(instance.items.all(), many=True).data + return representation