Evgeny Polivanov hace 1 año
commit
6ccf5eeaf5
Se han modificado 13 ficheros con 169 adiciones y 0 borrados
  1. 6 0
      .gitignore
  2. 0 0
      __init__.py
  3. 3 0
      admin.py
  4. 1 0
      apiviews/__init__.py
  5. 63 0
      apiviews/orders_local.py
  6. 6 0
      apps.py
  7. 1 0
      models/__init__.py
  8. 30 0
      models/orders_local.py
  9. 1 0
      serializer/__init__.py
  10. 42 0
      serializer/orders_local.py
  11. 3 0
      tests.py
  12. 10 0
      urls.py
  13. 3 0
      views.py

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+# Python
+__pycache__/
+migrations/
+!__init___.py
+*.py[cod]
+*$py.class

+ 0 - 0
__init__.py


+ 3 - 0
admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 1 - 0
apiviews/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocalMVS

+ 63 - 0
apiviews/orders_local.py

@@ -0,0 +1,63 @@
+from django.http import Http404, HttpResponse
+from openlocal.serializer import OrdersLocalSerializer
+from rest_framework import viewsets, permissions, status
+from rest_framework.response import Response
+from rest_framework.exceptions import NotFound
+from openlocal.models import OrdersLocal
+from metaservicesynced.models import Orders, Service, ServiceType, Provider, Client
+from SharixAdmin.models import SharixUser
+from tickets.models import Task
+
+class OrdersLocalMVS(viewsets.ModelViewSet):
+
+    queryset = OrdersLocal.objects.all()
+    serializer_class = OrdersLocalSerializer
+    #permission_classes = [IsOwnerOrReadOnly]
+    permission_classes = [permissions.IsAuthenticated]
+    
+    
+    def update(self, request, *args, **kwargs):
+        if request.data['order_synced']:
+            order = Orders.objects.get(pk=int(request.data['order_synced']))        
+            try:
+                #Подумать над этим
+                if request.data['is_global'] == True:
+                    order.is_global = True
+                elif request.data['is_gloabl'] == False:
+                    order.is_global = False
+                if request.data['is_visible'] == True:
+                    order.is_visible = True
+                elif request.data['is_visible'] == False:
+                    order.is_visible = False
+                order.service = Service.objects.get(pk=request.data['service'])
+                order.service_type = ServiceType.objects.get(pk=request.data['service_type'])
+                order.provider = Provider.objects.get(pk=request.data['provider'])
+                order.receiver = SharixUser.objects.get(pk=request.data['receiver'])
+                order.client_id = Client.objects.get(pk=request.data['client_id'])
+                
+            except Exception as ex:
+                print(ex)
+                #raise NotFound(str(ex))
+            
+            order.id_metaservice = request.data['id_metaservice'] or order.id_metaservice
+            order.state = request.data['state'] or order.state
+            order.time_placed = request.data['time_placed'] or order.time_placed
+            order.time_start = request.data['time_start'] or order.time_start
+            order.time_start_real = request.data['time_start_real'] or order.time_start_real
+            order.time_start_predicted = request.data['time_start_predicted'] or order.time_start_predicted
+            order.time_finish_predicted = request.data['time_finish_predicted'] or order.time_finish_predicted
+            order.time_finish_real = request.data['time_finish_real'] or order.time_finish_real
+            order.predicted_price = request.data['predicted_price'] or order.predicted_price
+            order.real_price = request.data['real_price'] or order.real_price
+            
+            order.save()
+        if request.data['ticket']:
+            ticket = Task.objects.get(pk=request.data['ticket'])
+            ticket.status = request.data['status'] or ticket.status
+            ticket.priority = request.data['priority'] or ticket.priority
+            ticket.title = request.data['title'] or ticket.title
+            ticket.note = request.data['note'] or ticket.note
+            ticket.due_date = request.data['due_date'] or ticket.due_date
+            ticket.status_changed_date = request.data['status_changed_date'] or ticket.status_changed_date
+            ticket.save()
+        return super().update(request, *args, **kwargs)

+ 6 - 0
apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class OpenlocalConfig(AppConfig):
+    default_auto_field = "django.db.models.BigAutoField"
+    name = "openlocal"

+ 1 - 0
models/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocal

+ 30 - 0
models/orders_local.py

@@ -0,0 +1,30 @@
+from django.db import models
+from metaservicesynced.models import Orders, Resource
+
+class OrdersLocal(models.Model):
+    """
+    OrdersLocal - таблица с заказами
+    """
+    order_synced = models.ForeignKey(Orders, null=True, on_delete=models.DO_NOTHING)
+    resource_id = models.ForeignKey(Resource, null=True, on_delete=models.DO_NOTHING)
+    rating_id = models.IntegerField(null=True)#Need create table with rating
+    payment_transaction_id = models.IntegerField(null=True)#Need create table with payment_transaction or it get from platform (i dont know)
+    attempts = models.IntegerField(null=True, help_text="Попытки")
+
+    order_place_type = models.CharField(null=True, max_length=150)
+    order_place_start = models.CharField(null=True, max_length=150)
+    order_place_start_gps = models.CharField(null=True, max_length=150)
+    order_place_start_sector = models.IntegerField(null=True)
+    order_place_start_real = models.CharField(null=True, max_length=150)
+    order_place_start_real_gps = models.CharField(null=True, max_length=150)
+    order_place_finish_predicted = models.CharField(null=True, max_length=150)
+    order_place_finish_predicted_gps = models.CharField(null=True, max_length=150)
+    order_place_finish_sector = models.IntegerField(null=True)
+    order_place_finish_real = models.CharField(null=True, max_length=150)
+    order_place_finish_real_gps = models.CharField(null=True, max_length=150)
+
+
+    class Meta:
+        db_table = "orders_local"
+        verbose_name = "Заказ (local)"
+        verbose_name_plural = "Заказы (local)"

+ 1 - 0
serializer/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocalSerializer

+ 42 - 0
serializer/orders_local.py

@@ -0,0 +1,42 @@
+from rest_framework import serializers
+from openlocal.models import OrdersLocal
+
+class OrdersLocalSerializer(serializers.ModelSerializer):
+    service = serializers.IntegerField(source="order_synced.service", allow_null=True)    
+    service_type = serializers.IntegerField(source="order_synced.service_type", allow_null=True) 
+    state = serializers.CharField(source="order_synced.state", allow_null=True) 
+    id_metaservice = serializers.IntegerField(source="order_synced.id_metaservice", allow_null=True) 
+    
+    provider = serializers.CharField(source="order_synced.provider.pk", allow_null=True) 
+    provider_screen_name = serializers.CharField(source="order_synced.provider.user_id.full_name", allow_null=True) 
+
+    receiver = serializers.IntegerField(source="order_synced.receiver.pk", allow_null=True)
+    receiver_screen_name = serializers.CharField(source="order_synced.receiver.full_name", allow_null=True) 
+    
+    client_id = serializers.CharField(source="order_synced.client_id.pk", allow_null=True) 
+    client_screen_name = serializers.CharField(source="order_synced.client.user.full_name", allow_null=True) 
+
+    #time_created = serializers.DateTimeField(source="order_synced.time_created", allow_null=True) 
+    time_placed = serializers.DateTimeField(source="order_synced.time_placed", allow_null=True) 
+    time_start = serializers.DateTimeField(source="order_synced.time_start", allow_null=True) 
+    time_start_real = serializers.DateTimeField(source="order_synced.time_start_real", allow_null=True)
+    time_start_predicted = serializers.DateTimeField(source="order_synced.time_start_predicted", allow_null=True)
+    time_finish_predicted = serializers.DateTimeField(source="order_synced.time_finish_predicted", allow_null=True) 
+    time_finish_real = serializers.DateTimeField(source="order_synced.time_finish_real", allow_null=True) 
+    
+    predicted_price = serializers.FloatField(source="order_synced.predicted_price", allow_null=True) 
+    real_price = serializers.FloatField(source="order_synced.real_price", allow_null=True) 
+    is_global = serializers.BooleanField(source="order_synced.is_global", allow_null=True) 
+    is_visible = serializers.BooleanField(source="order_synced.is_visible", allow_null=True) 
+    ticket = serializers.IntegerField(source="order_synced.ticket.pk", allow_null=True) 
+    status = serializers.IntegerField(source="order_synced.ticket.stauts", allow_null=True)
+    priority = serializers.IntegerField(source="order_synced.ticket.priority", allow_null=True)
+    title = serializers.CharField(source="order_synced.ticket.title", allow_null=True)
+    note = serializers.CharField(source="order_synced.ticket.note", allow_null=True)
+    due_date = serializers.DateField(source="order_synced.ticket.due_date", allow_null=True)
+    status_changed_date = serializers.DateTimeField(source="order_synced.ticket.status_changed_date", allow_null=True)
+    
+
+    class Meta:
+        model = OrdersLocal
+        fields = '__all__'

+ 3 - 0
tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 10 - 0
urls.py

@@ -0,0 +1,10 @@
+from openlocal.apiviews import *
+from rest_framework import routers
+from django.urls import path, include
+
+router = routers.DefaultRouter()
+router.register(r'orderslocal', OrdersLocalMVS)
+
+urlpatterns = [  
+    path('api/', include(router.urls), name="openlocalapi"),
+]

+ 3 - 0
views.py

@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.