Django 6 + DRF resource server against the Gooyal accounts OAuth2 service, matching the Winsoo ecosystem's conventions. Covers locations, stores, catalog, cart, checkout/orders (with the multi-store-cart split and the status stepper), reviews, and notifications, plus a demo-data seed command. Payment integration (wallet debits, online gateway, seller payouts) is intentionally left out here — see feature/payment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
58 lines
2 KiB
Python
58 lines
2 KiB
Python
from rest_framework import serializers
|
|
|
|
from apps.stores.serializers import StoreListSerializer
|
|
|
|
from .models import Product, ProductCategory
|
|
|
|
|
|
class ProductCategorySerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ProductCategory
|
|
fields = ('uuid', 'name', 'parent', 'icon', 'order')
|
|
|
|
|
|
class ProductListSerializer(serializers.ModelSerializer):
|
|
is_out_of_stock = serializers.BooleanField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Product
|
|
fields = (
|
|
'uuid', 'name', 'image', 'price', 'unit_type', 'unit_value',
|
|
'is_active', 'is_out_of_stock',
|
|
)
|
|
|
|
|
|
class ProductDetailSerializer(ProductListSerializer):
|
|
category = ProductCategorySerializer(read_only=True)
|
|
store = StoreListSerializer(read_only=True)
|
|
|
|
class Meta(ProductListSerializer.Meta):
|
|
fields = ProductListSerializer.Meta.fields + ('description', 'category', 'store')
|
|
|
|
|
|
class SellerProductSerializer(serializers.ModelSerializer):
|
|
"""Read/write serializer for the seller's own products (S06/S07/S08)."""
|
|
|
|
category = ProductCategorySerializer(read_only=True)
|
|
category_uuid = serializers.PrimaryKeyRelatedField(
|
|
source='category', queryset=ProductCategory.objects.all(), write_only=True,
|
|
)
|
|
is_out_of_stock = serializers.BooleanField(read_only=True)
|
|
is_low_stock = serializers.BooleanField(read_only=True)
|
|
|
|
class Meta:
|
|
model = Product
|
|
fields = (
|
|
'uuid', 'name', 'description', 'image', 'category', 'category_uuid',
|
|
'price', 'unit_type', 'unit_value', 'stock_quantity', 'low_stock_threshold',
|
|
'is_active', 'sold_count', 'is_out_of_stock', 'is_low_stock', 'created_at',
|
|
)
|
|
read_only_fields = ('sold_count',)
|
|
|
|
def create(self, validated_data):
|
|
validated_data['store'] = self.context['request'].user.store
|
|
return super().create(validated_data)
|
|
|
|
|
|
class StockAdjustSerializer(serializers.Serializer):
|
|
stock_quantity = serializers.IntegerField(min_value=0)
|