orders_local.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from django.http import Http404, HttpResponse
  2. from openlocal.serializer import OrdersLocalSerializer
  3. from rest_framework import viewsets, permissions, status
  4. from rest_framework.response import Response
  5. from rest_framework.exceptions import NotFound
  6. from openlocal.models import OrdersLocal
  7. from metaservicesynced.models import Orders, Service, ServiceType, Provider, Client
  8. from SharixAdmin.models import SharixUser
  9. from tickets.models import Task
  10. class OrdersLocalMVS(viewsets.ModelViewSet):
  11. queryset = OrdersLocal.objects.all()
  12. serializer_class = OrdersLocalSerializer
  13. #permission_classes = [IsOwnerOrReadOnly]
  14. permission_classes = [permissions.IsAuthenticated]
  15. def update(self, request, *args, **kwargs):
  16. if request.data['order_synced']:
  17. order = Orders.objects.get(pk=int(request.data['order_synced']))
  18. try:
  19. #Подумать над этим
  20. if request.data['is_global'] == True:
  21. order.is_global = True
  22. elif request.data['is_gloabl'] == False:
  23. order.is_global = False
  24. if request.data['is_visible'] == True:
  25. order.is_visible = True
  26. elif request.data['is_visible'] == False:
  27. order.is_visible = False
  28. order.service = Service.objects.get(pk=request.data['service'])
  29. order.service_type = ServiceType.objects.get(pk=request.data['service_type'])
  30. order.provider = Provider.objects.get(pk=request.data['provider'])
  31. order.receiver = SharixUser.objects.get(pk=request.data['receiver'])
  32. order.client_id = Client.objects.get(pk=request.data['client_id'])
  33. except Exception as ex:
  34. print(ex)
  35. #raise NotFound(str(ex))
  36. order.id_metaservice = request.data['id_metaservice'] or order.id_metaservice
  37. order.state = request.data['state'] or order.state
  38. order.time_placed = request.data['time_placed'] or order.time_placed
  39. order.time_start = request.data['time_start'] or order.time_start
  40. order.time_start_real = request.data['time_start_real'] or order.time_start_real
  41. order.time_start_predicted = request.data['time_start_predicted'] or order.time_start_predicted
  42. order.time_finish_predicted = request.data['time_finish_predicted'] or order.time_finish_predicted
  43. order.time_finish_real = request.data['time_finish_real'] or order.time_finish_real
  44. order.predicted_price = request.data['predicted_price'] or order.predicted_price
  45. order.real_price = request.data['real_price'] or order.real_price
  46. order.save()
  47. if request.data['ticket']:
  48. ticket = Task.objects.get(pk=request.data['ticket'])
  49. ticket.status = request.data['status'] or ticket.status
  50. ticket.priority = request.data['priority'] or ticket.priority
  51. ticket.title = request.data['title'] or ticket.title
  52. ticket.note = request.data['note'] or ticket.note
  53. ticket.due_date = request.data['due_date'] or ticket.due_date
  54. ticket.status_changed_date = request.data['status_changed_date'] or ticket.status_changed_date
  55. ticket.save()
  56. return super().update(request, *args, **kwargs)