|
@@ -1,5 +1,5 @@
|
|
|
from rest_framework import serializers
|
|
|
-from openlocal.models import OrdersLocal
|
|
|
+from webservice_running.models import OrdersLocal
|
|
|
from tickets.models import *
|
|
|
from metaservicesynced.models import Orders
|
|
|
from SharixAdmin.models import SharixUser
|
|
@@ -8,14 +8,25 @@ from tickets.serializer import TaskSerializer
|
|
|
from rest_framework.utils import model_meta
|
|
|
import pprint
|
|
|
from django.db import connection
|
|
|
+from webservice_running.exceptions import *
|
|
|
+
|
|
|
+
|
|
|
+class OrderNotDefined(Exception):
|
|
|
+ """
|
|
|
+ If order_synced field is not defined throw exception
|
|
|
+ """
|
|
|
+ def __init__(self, message="order_synced is not defined"):
|
|
|
+ self.message = message
|
|
|
+ super().__init__(self.message)
|
|
|
+
|
|
|
|
|
|
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)
|
|
|
+ service = serializers.IntegerField(source="order_synced.service.pk", allow_null=True)
|
|
|
+ service_type = serializers.IntegerField(source="order_synced.service_type.pk", 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 = serializers.IntegerField(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)
|
|
@@ -54,9 +65,12 @@ class OrdersLocalSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
def update(self, instance, validated_data):
|
|
|
# pprint.pprint(connection.queries)
|
|
|
- order_instance = instance.order_synced
|
|
|
+
|
|
|
+ order_instance = instance.order_synced #if "order_synced" not in validated_data else validated_data["order_synced"]
|
|
|
+ if not order_instance:
|
|
|
+ raise OrderNotDefined()
|
|
|
ticket_instance = instance.order_synced.ticket
|
|
|
-
|
|
|
+
|
|
|
for attr, value in validated_data.items():
|
|
|
if attr == "order_synced":
|
|
|
for order_synced_attr, order_synced_value in value.items():
|