2021-11-04 23:49:56 +08:00
|
|
|
from extensions.permissions import *
|
|
|
|
from extensions.exceptions import *
|
|
|
|
from extensions.viewsets import *
|
2021-11-11 23:58:18 +08:00
|
|
|
from apps.purchase.serializers import *
|
|
|
|
from apps.purchase.permissions import *
|
|
|
|
from apps.purchase.filters import *
|
|
|
|
from apps.purchase.schemas import *
|
|
|
|
from apps.purchase.models import *
|
2021-11-04 17:35:34 +08:00
|
|
|
|
2021-11-04 23:49:56 +08:00
|
|
|
|
2021-11-11 23:58:18 +08:00
|
|
|
class PurchaseOrderViewSet(BaseViewSet, ListModelMixin, RetrieveModelMixin, CreateModelMixin):
|
|
|
|
"""采购单据"""
|
|
|
|
|
|
|
|
serializer_class = PurchaseOrderSerializer
|
|
|
|
permission_classes = [IsAuthenticated, PurchaseOrderPermission]
|
|
|
|
filterset_class = PurchaseOrderFilter
|
|
|
|
search_fields = ['number', 'supplier__number', 'supplier__name', 'remark']
|
|
|
|
ordering_fields = ['id', 'number', 'total_quantity', 'total_amount', 'create_time']
|
|
|
|
ordering = ['-number', 'id']
|
2021-11-12 01:03:17 +08:00
|
|
|
select_related_fields = ['warehouse', 'supplier', 'handler', 'creator']
|
|
|
|
prefetch_related_fields = ['purchase_goods_set', 'purchase_goods_set__goods__unit',
|
|
|
|
'payment_order__payment_accounts']
|
2021-11-11 23:58:18 +08:00
|
|
|
queryset = PurchaseOrder.objects.all()
|
2021-11-04 23:49:56 +08:00
|
|
|
|
2021-11-12 01:03:17 +08:00
|
|
|
@extend_schema(responses={200: NumberResponse})
|
|
|
|
@action(detail=False, methods=['get'])
|
|
|
|
def number(self, request, *args, **kwargs):
|
|
|
|
"""获取编号"""
|
|
|
|
|
|
|
|
number = PurchaseOrder.get_number(self.team)
|
|
|
|
return Response(data={'number': number}, status=status.HTTP_200_OK)
|
|
|
|
|
2021-11-11 23:58:18 +08:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'PurchaseOrderViewSet',
|
2021-11-04 23:49:56 +08:00
|
|
|
]
|