fix serializer for gov & free product on serializer
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user