37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from apps.wf.mixins import TicketMixin
|
|
from apps.utils.viewsets import CustomModelViewSet
|
|
from apps.asm.models import Asset, AssetAudit
|
|
from rest_framework.exceptions import ParseError
|
|
from apps.asm.serializers import AssetSerializer, AssetlogSerializer
|
|
from apps.wf.models import Ticket
|
|
|
|
class AssetAuditViewSet(TicketMixin, CustomModelViewSet):
|
|
"""
|
|
list: 固定资产审核
|
|
|
|
固定资产审核
|
|
"""
|
|
queryset = Asset.objects.all()
|
|
serializer_class = AssetSerializer
|
|
search_fields = ['assetlog']
|
|
workflow_key = 'wf_asset'
|
|
|
|
@staticmethod
|
|
def add_asset(ticket:Ticket, transition, new_ticket_data: dict):
|
|
asset = AssetAudit.objects.get(ticket=ticket)
|
|
if Asset.objects.filter(code=asset.code).exists():
|
|
raise ParseError('资产名称已存在')
|
|
Asset.objects.create(**new_ticket_data)
|
|
|
|
|
|
class AssetViewSet(CustomModelViewSet):
|
|
"""
|
|
list: 固定资产台账
|
|
|
|
固定资产台账
|
|
"""
|
|
queryset = Asset.objects.all()
|
|
serializer_class = AssetlogSerializer
|
|
search_fields = ['name', 'code', 'category']
|
|
filterset_fields = ['category']
|