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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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()