Files
RasadDam_Backend/apps/warehouse/pos/api/v1/api.py
2025-08-20 14:44:43 +03:30

56 lines
2.0 KiB
Python

from apps.warehouse.pos.api.v1 import serializers as warehouse_serializers
from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin
from apps.core.mixins.search_mixin import DynamicSearchMixin
from apps.warehouse import models as warehouse_models
from common.helpers import get_organization_by_user
from rest_framework.permissions import AllowAny
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import viewsets, filters
from django.db import transaction
from rest_framework import status
import typing
class InventoryEntryViewSet(viewsets.ModelViewSet, DynamicSearchMixin, POSDeviceMixin):
queryset = warehouse_models.InventoryEntry.objects.all()
serializer_class = warehouse_serializers.InventoryEntrySerializer
permission_classes = [AllowAny]
search_fields = [
"distribution__distribution_id",
"organization__name",
"weight",
"balance",
"lading_number",
"is_confirmed",
]
date_field = "create_date"
@action(
methods=['get'],
detail=False,
url_path='my_entries',
url_name='my_entries',
name='my_entries'
)
def inventory_entries(self, request):
""" list of pos inventory entries """
organization = self.get_device_organization()
entries = self.queryset.filter(organization=organization)
queryset = self.filter_query(entries) # return by search param or all objects
# paginate & response
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
class InventoryQuotaSaleTransactionViewSet(viewsets.ModelViewSet):
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
serializer_class = warehouse_serializers.InventoryQuotaSaleTransactionSerializer
filter_backends = [filters.SearchFilter]
search_fields = ['']