Преглед на файлове

remake for new api and fixes for orders

stucked_s преди 10 месеца
родител
ревизия
56448cb40b
променени са 2 файла, в които са добавени 56 реда и са изтрити 30 реда
  1. 48 17
      handlers/jsonAndRequest.py
  2. 8 13
      handlers/open_servicerequest_booked.py

+ 48 - 17
handlers/jsonAndRequest.py

@@ -59,7 +59,6 @@ https://wiki.sharix-app.org/doku.php/open/tech/dev/sharix_open_-_primery_json
 "attempts": null
 }
 '''
-
 #надо адаптировать класс к новому формату JSON
 class Order(object):
     def __init__(self, order_synced, ticket, status, title, note, due_date, id_metaservice, is_global, is_visible, service, service_type, status_changed_date, time_placed, time_start=None, time_start_predicted=None, time_finish_predicted=None, time_start_real=None, time_finish_real=None, order_place_type=None, order_place_start=None, order_place_start_gps=None, order_place_start_real=None, order_place_start_real_gps=None, order_place_finish_predicted=None, order_place_finish_predicted_gps=None, order_place_finish_real=None, order_place_finish_real_gps=None, predicted_price=None, real_price=None, payment_transaction_id=None, rating_id=None, provider=None, provider_screen_name=None, receiver=None, receiver_screen_name=None, client_id=None, resource_id=None, attempts=None, asap=None):
@@ -151,25 +150,57 @@ class Order(object):
         "type": 1,
         "assigned_to": null
 }
-'''
+{
+  "serviceType": 2,
+  "driverSearchEngine": 0,
+  "comment": "Yyyy",
+  "arrivalTime": "2023-12-07T14:39:54Z",
+  "additionalServices": [],
+  "tasks": [
+    {
+      "text": "Eeee",
+      "address": "Jjjj"
+    }
+  ],
+  "spendingLimit": 6668,
+  "isWithPaymentDocument": true,
+  "id": 294830,
+  "isProceedBeforeArrival": true
+}
 
+'''
 class OrderTicket(object):
-    def __init__(self, id, status, created_date, status_changed_date, priority, title=None, note=None, due_date=None, task_list=None, created_by=None, type=None, assigned_to=None):
+    def __init__(self, serviceType, driverSearchEngine, comment, arrivalTime, additionalServices, tasks, spendingLimit, isWithPaymentDocument, id, isProceedBeforeArrival):
+        self.serviceType = serviceType
+        self.driverSearchEngine = driverSearchEngine
+        self.comment = comment
+        self.arrivalTime = arrivalTime
+        self.additionalServices = additionalServices
+        self.tasks = tasks
+        self.spendingLimit = spendingLimit
+        self.isWithPaymentDocument = isWithPaymentDocument
         self.id = id
-        self.status = status
-        self.created_date = created_date
-        self.status_changed_date = status_changed_date
-        self.priority = priority
-        self.title = title
-        self.note = note
-        self.due_date = due_date
-        self.task_list = task_list
-        self.created_by = created_by
-        self.type = type
-        self.assigned_to = assigned_to
-
-    def  __str__(self):
-        return "{0}, {1}, {2}, {3}, {4}, {5}, {6},\n{7}, {8}, {9}, {10}, {11}\n".format(self.id, self.status, self.created_date, self.status_changed_date, self.priority, self.title, self.note, self.due_date, self.task_list, self.created_by, self.type, self.assigned_to) 
+        self.isProceedBeforeArrival = isProceedBeforeArrival
+
+
+
+# class OrderTicketOLD(object):
+#     def __init__(self, id, status, created_date, status_changed_date, priority, title=None, note=None, due_date=None, task_list=None, created_by=None, type=None, assigned_to=None):
+#         self.id = id
+#         self.status = status
+#         self.created_date = created_date
+#         self.status_changed_date = status_changed_date
+#         self.priority = priority
+#         self.title = title
+#         self.note = note
+#         self.due_date = due_date
+#         self.task_list = task_list
+#         self.created_by = created_by
+#         self.type = type
+#         self.assigned_to = assigned_to
+
+#     def  __str__(self):
+#         return "{0}, {1}, {2}, {3}, {4}, {5}, {6},\n{7}, {8}, {9}, {10}, {11}\n".format(self.id, self.status, self.created_date, self.status_changed_date, self.priority, self.title, self.note, self.due_date, self.task_list, self.created_by, self.type, self.assigned_to) 
 
 #Функция преобразования json в объект класса Order
 def jsonToOrder(jsonstring) -> Order:

+ 8 - 13
handlers/open_servicerequest_booked.py

@@ -27,7 +27,7 @@ PASSWORD=hashlib.md5((botname+config.PASSWORD).encode('utf-8')).hexdigest()
 print(JID, PASSWORD)
 
 #таким образом хранится список jid, от которых можно получать сообщения этому боту
-listen_to=["9090@ej.sharix-app.org","test@ej.sharix-app.org", "open_template_bot@ej.sharix-app.org","799999999990@ej.shaix-app.org"]
+listen_to=["9090@ej.sharix-app.org","test@ej.sharix-app.org", "open_template_bot@ej.sharix-app.org","799999999990@ej.sharix-app.org"]
 
 #тут хранится список jid, кому бот может отправлять сообщения в результате обработки заявки
 proceed_to=["open_servicerequest_assigned@ej.sharix-app.org", "open_servicerequest_pending@ej.sharix-app.org", "open_servicerequest_forcemajeure@ej.sharix-app.org"]
@@ -39,12 +39,8 @@ idle_value=10
 def message_handler(conn, mess):
     text = mess.getBody()#текст сообщения боту
     user = mess.getFrom()#отправитель сообщения
-
-    print (str(user).split("/")[0])
     if (str(user).split("/")[0]) in listen_to:
-        print(text)
-        print(mess)
-
+        # print (str(user).split("/")[0])
         if text is not None:
             orderObj = jsreq.jsonToOrderTicket(text)
             print (orderObj)
@@ -54,7 +50,6 @@ def message_handler(conn, mess):
 def open_servicerequest_booked_wait(period,localtask):
     bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ ожидает\n")
     time.sleep(period)
-    
     #ВАЖНО! Надо скорее всего через API редактировать заказ, иначе возможна потеря данных
     localtask.title=localtask.title+"1"
 
@@ -134,10 +129,10 @@ def open_servicerequest_booked():
         bot.bot_log(botname + " " + datetime.now().strftime('%Y-%m-%d') + " "+ "Заказ в очереди на обработке\n")
         print("EACH TASKLIST", tasklist)
 
-        if (localtask.status!=operating_status):
-            bot.proceed_status(proceed_to[-1],localtask)
-            bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ не по адресу, перенаправляем на форсмажор\n")
-            continue
+        # if (localtask.status!=operating_status):
+        #     bot.proceed_status(proceed_to[-1],localtask)
+        #     bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ не по адресу, перенаправляем на форсмажор\n")
+        #     continue
 
         # if (localtask.title!="10"):
         #     t1=threading.Thread(target=open_servicerequest_booked_wait, args=(5,localtask))
@@ -161,9 +156,9 @@ def open_servicerequest_booked():
 tasklist = []
 
 #надо инициализировать tasklist при запуске из API
-token = jsreq.requestGetToken(botname, PASSWORD, config.API_URL+"/base/auth/token/login/")
+token = jsreq.requestGetToken(botname, PASSWORD, config.API_URL+"/api/v1/auth/token/login/")
 #ВАЖНО! Надо еще фильтровать список по статусу обработки заявки
-tasklist=jsreq.requestGetList(token, config.API_URL+"/webservice/api/webservice/")
+tasklist=jsreq.requestGetList(token, config.API_URL+"/metaservicesynced/api/orders/")
 
 print (len(tasklist))