chore: extracted product batch creation
This commit is contained in:
@@ -40,6 +40,7 @@ from shop.models import (
|
||||
)
|
||||
|
||||
from shop.api.v1.permissions import ProductPermissions, ProductPricePermissions
|
||||
from shop.utils import delete_product_batch
|
||||
|
||||
|
||||
class ProductViewSet(ModelViewSet):
|
||||
@@ -107,10 +108,16 @@ class ProductBatchViewSet(ModelViewSet):
|
||||
product.save()
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
delete_product_batch(instance)
|
||||
|
||||
def perform_update(self, serializer):
|
||||
instance = self.get_object()
|
||||
product = instance.product
|
||||
product.stock = max(product.stock - instance.quantity, 0)
|
||||
product.stock -= instance.quantity
|
||||
|
||||
updated_batch = serializer.save()
|
||||
product.stock += updated_batch.quantity
|
||||
product.save()
|
||||
instance.delete()
|
||||
|
||||
|
||||
class CustomerViewSet(ModelViewSet):
|
||||
|
||||
Reference in New Issue
Block a user