You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
838 B

from rest_framework.viewsets import ModelViewSet
from .models import GoodsReception
from .serializers import GoodsReceptionSerializer
from warehouse.models import Stock
class GoodsReceptionViewSet(ModelViewSet):
"""
API для работы с приемкой товаров.
"""
queryset = GoodsReception.objects.all()
serializer_class = GoodsReceptionSerializer
def perform_create(self, serializer):
reception = serializer.save()
if reception.is_accepted:
# Добавление на склад
stock, created = Stock.objects.get_or_create(
product=reception.product,
location="Основной склад",
defaults={'quantity': 0},
)
stock.quantity += reception.quantity
stock.save()