feat: added product batches and provider models
This commit is contained in:
@@ -6,6 +6,8 @@ from shop.api.v1.viewsets import (
|
||||
ProductPriceViewSet,
|
||||
OrderViewSet,
|
||||
OrderLineViewSet,
|
||||
ProviderViewSet,
|
||||
ProductBatchViewSet,
|
||||
)
|
||||
|
||||
|
||||
@@ -13,8 +15,10 @@ router = DefaultRouter()
|
||||
|
||||
router.register("taxes", TaxViewSet)
|
||||
router.register("customers", CustomerViewSet)
|
||||
router.register("providers", ProviderViewSet)
|
||||
router.register("products", ProductViewSet)
|
||||
router.register("product-prices", ProductPriceViewSet)
|
||||
router.register("product-batches", ProductBatchViewSet)
|
||||
router.register("orders", OrderViewSet)
|
||||
router.register("orders/(?P<order_id>[^/.]+)/lines", OrderLineViewSet)
|
||||
|
||||
|
||||
+59
-22
@@ -1,28 +1,16 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from files.api.v1.serializers import FileUploadSerializer
|
||||
from shop.models import Product, ProductPrice, Customer, Tax, OrderLine, Order
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
images = FileUploadSerializer(many=True, read_only=True)
|
||||
price = serializers.SerializerMethodField()
|
||||
|
||||
def get_price(self, product):
|
||||
last_price = product.prices.last()
|
||||
|
||||
return ProductPriceSerializer(last_price).data
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = (
|
||||
"name",
|
||||
"description",
|
||||
"stock",
|
||||
"is_digital_asset",
|
||||
"images",
|
||||
"price",
|
||||
)
|
||||
from shop.models import (
|
||||
Product,
|
||||
ProductPrice,
|
||||
Customer,
|
||||
Tax,
|
||||
OrderLine,
|
||||
Order,
|
||||
ProductBatch,
|
||||
Provider,
|
||||
)
|
||||
|
||||
|
||||
class TaxSerializer(serializers.ModelSerializer):
|
||||
@@ -47,6 +35,39 @@ class ProductPriceSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
images = FileUploadSerializer(many=True, read_only=True)
|
||||
price = ProductPriceSerializer()
|
||||
|
||||
def get_price(self, product):
|
||||
last_price = product.prices.last()
|
||||
|
||||
return ProductPriceSerializer(last_price).data
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = (
|
||||
"name",
|
||||
"description",
|
||||
"stock",
|
||||
"is_digital_asset",
|
||||
"images",
|
||||
"price",
|
||||
)
|
||||
|
||||
|
||||
class ProductBatchSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductBatch
|
||||
fields = (
|
||||
"code",
|
||||
"product",
|
||||
"quantity",
|
||||
"creation_date",
|
||||
"expiration_date",
|
||||
)
|
||||
|
||||
|
||||
class CustomerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Customer
|
||||
@@ -63,6 +84,22 @@ class CustomerSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
|
||||
|
||||
class ProviderSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Provider
|
||||
fields = (
|
||||
"vat_id",
|
||||
"name",
|
||||
"email",
|
||||
"phone",
|
||||
"address",
|
||||
"city",
|
||||
"state",
|
||||
"country",
|
||||
"zip",
|
||||
)
|
||||
|
||||
|
||||
class OrderSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Order
|
||||
|
||||
+22
-1
@@ -7,8 +7,19 @@ from shop.api.v1.serializers import (
|
||||
TaxSerializer,
|
||||
OrderSerializer,
|
||||
OrderLineSerializer,
|
||||
ProviderSerializer,
|
||||
ProductBatchSerializer,
|
||||
)
|
||||
from shop.models import (
|
||||
Product,
|
||||
ProductPrice,
|
||||
Customer,
|
||||
Tax,
|
||||
Order,
|
||||
OrderLine,
|
||||
Provider,
|
||||
ProductBatch,
|
||||
)
|
||||
from shop.models import Product, ProductPrice, Customer, Tax, Order, OrderLine
|
||||
|
||||
|
||||
class ProductViewSet(ModelViewSet):
|
||||
@@ -21,11 +32,21 @@ class ProductPriceViewSet(ModelViewSet):
|
||||
queryset = ProductPrice.objects.all()
|
||||
|
||||
|
||||
class ProductBatchViewSet(ModelViewSet):
|
||||
serializer_class = ProductBatchSerializer
|
||||
queryset = ProductBatch.objects.all()
|
||||
|
||||
|
||||
class CustomerViewSet(ModelViewSet):
|
||||
serializer_class = CustomerSerializer
|
||||
queryset = Customer.objects.all()
|
||||
|
||||
|
||||
class ProviderViewSet(ModelViewSet):
|
||||
serializer_class = ProviderSerializer
|
||||
queryset = Provider.objects.all()
|
||||
|
||||
|
||||
class TaxViewSet(ModelViewSet):
|
||||
serializer_class = TaxSerializer
|
||||
queryset = Tax.objects.all()
|
||||
|
||||
Reference in New Issue
Block a user