| Line 23... |
Line 23... |
| 23 |
http://www.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery&loginid=DEL24119&awb=ref&format=XML&lickey=6265d61bafa6292c5ddfdb1ee335ca80&verno=1.3&scan=1&numbers={variable1} is hard coded
|
23 |
http://www.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery&loginid=DEL24119&awb=ref&format=XML&lickey=6265d61bafa6292c5ddfdb1ee335ca80&verno=1.3&scan=1&numbers={variable1} is hard coded
|
| 24 |
to track DOA orders and for other orders ConfigClient is called to get bluedart_update_url
|
24 |
to track DOA orders and for other orders ConfigClient is called to get bluedart_update_url
|
| 25 |
|
25 |
|
| 26 |
@author: Phani Kumar
|
26 |
@author: Phani Kumar
|
| 27 |
'''
|
27 |
'''
|
| - |
|
28 |
from datetime import datetime
|
| 28 |
from shop2020.clients.CRMClient import CRMClient
|
29 |
from shop2020.clients.CRMClient import CRMClient
|
| 29 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
30 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 30 |
from shop2020.clients.TransactionClient import TransactionClient
|
31 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 31 |
from shop2020.clients.UserClient import UserClient
|
32 |
from shop2020.model.v1.order.script.LogisticUtils import \
|
| 32 |
from LogisticUtils import enqueueMailForFDA
|
33 |
create_crm_tickets_for_delivey_attempted_orders
|
| 33 |
from shop2020.thriftpy.crm.ttypes import *
|
34 |
from shop2020.thriftpy.crm.ttypes import TicketCategory, TicketPriority, \
|
| - |
|
35 |
TicketStatus, Activity, ActivityType, SearchFilter
|
| 34 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
36 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 35 |
OrderStatus
|
37 |
OrderStatus
|
| 36 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
38 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| 37 |
from shop2020.utils.Utils import to_py_date
|
39 |
from shop2020.utils.Utils import to_py_date
|
| - |
|
40 |
from suds.client import Client
|
| 38 |
from xml.etree.ElementTree import parse, XML, fromstring
|
41 |
from xml.etree.ElementTree import parse, fromstring
|
| 39 |
from datetime import datetime
|
42 |
import StringIO
|
| - |
|
43 |
import ast
|
| 40 |
import csv
|
44 |
import csv
|
| 41 |
import datetime
|
45 |
import gzip
|
| - |
|
46 |
import json
|
| 42 |
import optparse
|
47 |
import optparse
|
| 43 |
import sys
|
48 |
import sys
|
| 44 |
import time
|
49 |
import time
|
| 45 |
import traceback
|
50 |
import traceback
|
| 46 |
import urllib2
|
51 |
import urllib2
|
| 47 |
from suds.client import Client
|
- |
|
| 48 |
import json
|
- |
|
| 49 |
import StringIO
|
- |
|
| 50 |
import zlib
|
- |
|
| 51 |
import gzip
|
- |
|
| 52 |
import xmltodict
|
52 |
import xmltodict
|
| 53 |
import ast
|
53 |
import zlib
|
| 54 |
if __name__ == '__main__' and __package__ is None:
|
54 |
if __name__ == '__main__' and __package__ is None:
|
| 55 |
import os
|
55 |
import os
|
| 56 |
sys.path.insert(0, os.getcwd())
|
56 |
sys.path.insert(0, os.getcwd())
|
| 57 |
|
57 |
|
| 58 |
|
58 |
|
| Line 79... |
Line 79... |
| 79 |
if client is None:
|
79 |
if client is None:
|
| 80 |
client = Client(RED_EXPRESS_URL, timeout=70)
|
80 |
client = Client(RED_EXPRESS_URL, timeout=70)
|
| 81 |
return client
|
81 |
return client
|
| 82 |
|
82 |
|
| 83 |
defaultUndeliveredAsssigneeId = 47
|
83 |
defaultUndeliveredAsssigneeId = 47
|
| - |
|
84 |
dtrUndeliveredAsssigneeId = 33
|
| - |
|
85 |
|
| 84 |
from_user = 'cnc.center@shop2020.in'
|
86 |
from_user = 'cnc.center@shop2020.in'
|
| 85 |
from_pwd = '5h0p2o2o'
|
87 |
from_pwd = '5h0p2o2o'
|
| 86 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
88 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
| 87 |
|
89 |
|
| 88 |
|
90 |
|
| 89 |
def get_updates(awb_number):
|
91 |
def get_updates(awb_number):
|
| 90 |
str = getClient().service.ProcessTrackingRequest('<TrackingRequest><Request><UserID>' + username + '</UserID><Password>' + password + '</Password><TrackingID>' + awb_number + '</TrackingID><TrackingLevel>ALL_DETAILS</TrackingLevel></Request></TrackingRequest>')
|
92 |
str1 = getClient().service.ProcessTrackingRequest('<TrackingRequest><Request><UserID>' + username + '</UserID><Password>' + password + '</Password><TrackingID>' + awb_number + '</TrackingID><TrackingLevel>ALL_DETAILS</TrackingLevel></Request></TrackingRequest>')
|
| 91 |
print str
|
- |
|
| 92 |
return str
|
93 |
return str1
|
| 93 |
|
94 |
|
| 94 |
def get_updates_for_user(awb_number):
|
95 |
def get_updates_for_user(awb_number):
|
| 95 |
root = fromstring(str(get_updates(awb_number)))
|
96 |
root = fromstring(str(get_updates(awb_number)))
|
| 96 |
children = root.getchildren()
|
97 |
children = root.getchildren()
|
| 97 |
results = []
|
98 |
results = []
|
| Line 704... |
Line 705... |
| 704 |
statusDescription = ''
|
705 |
statusDescription = ''
|
| 705 |
if order.statusDescription is not None:
|
706 |
if order.statusDescription is not None:
|
| 706 |
statusDescription = order.statusDescription.replace(","," ")
|
707 |
statusDescription = order.statusDescription.replace(","," ")
|
| 707 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp), to_py_date(order.promised_delivery_time), to_py_date(order.expected_delivery_time), 'True' if order.otg else 'False'])
|
708 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp), to_py_date(order.promised_delivery_time), to_py_date(order.expected_delivery_time), 'True' if order.otg else 'False'])
|
| 708 |
|
709 |
|
| 709 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
- |
|
| 710 |
try:
|
- |
|
| 711 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
- |
|
| 712 |
userClient = UserClient().get_client()
|
- |
|
| 713 |
crmServiceClient = CRMClient().get_client()
|
- |
|
| 714 |
for order in tickets_tobe_created:
|
- |
|
| 715 |
ticket_created = False
|
- |
|
| 716 |
searchFilter = SearchFilter()
|
- |
|
| 717 |
user = userClient.getUserByEmail(order.customer_email)
|
- |
|
| 718 |
if user is None or user.userId == -1:
|
- |
|
| 719 |
searchFilter.customerEmailId = order.customer_email
|
- |
|
| 720 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 721 |
else:
|
- |
|
| 722 |
searchFilter.customerId = user.userId
|
- |
|
| 723 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
- |
|
| 724 |
tickets = crmServiceClient.getTickets(searchFilter)
|
- |
|
| 725 |
print tickets
|
- |
|
| 726 |
for old_ticket in tickets:
|
- |
|
| 727 |
if old_ticket.orderId == order.id:
|
- |
|
| 728 |
ticket_created = True
|
- |
|
| 729 |
break
|
- |
|
| 730 |
if not ticket_created:
|
- |
|
| 731 |
print "creating ticket for orderId:"+str(order.id)
|
- |
|
| 732 |
ticket = Ticket()
|
- |
|
| 733 |
activity = Activity()
|
- |
|
| 734 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
- |
|
| 735 |
ticket.creatorId = 1
|
- |
|
| 736 |
ticket.assigneeId = defaultUndeliveredAsssigneeId
|
- |
|
| 737 |
ticket.category = TicketCategory.UNDELIVERED
|
- |
|
| 738 |
ticket.priority = TicketPriority.HIGH
|
- |
|
| 739 |
ticket.status = TicketStatus.OPEN
|
- |
|
| 740 |
ticket.description = description
|
- |
|
| 741 |
ticket.orderId = order.id
|
- |
|
| 742 |
ticket.airwayBillNo = order.airwaybill_no
|
- |
|
| 743 |
|
- |
|
| 744 |
activity.creatorId = 1
|
- |
|
| 745 |
activity.ticketAssigneeId = ticket.assigneeId
|
- |
|
| 746 |
activity.type = ActivityType.OTHER
|
- |
|
| 747 |
activity.description = description
|
- |
|
| 748 |
activity.ticketCategory = ticket.category
|
- |
|
| 749 |
activity.ticketDescription = ticket.description
|
- |
|
| 750 |
activity.ticketPriority = ticket.priority
|
- |
|
| 751 |
activity.ticketStatus = ticket.status
|
- |
|
| 752 |
|
- |
|
| 753 |
if user is None or user.userId == -1:
|
- |
|
| 754 |
ticket.customerEmailId = order.customer_email
|
- |
|
| 755 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 756 |
ticket.customerName = order.customer_name
|
- |
|
| 757 |
activity.customerEmailId = order.customer_email
|
- |
|
| 758 |
activity.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 759 |
activity.customerName = order.customer_name
|
- |
|
| 760 |
else:
|
- |
|
| 761 |
ticket.customerId = user.userId
|
- |
|
| 762 |
activity.customerId = user.userId
|
- |
|
| 763 |
|
- |
|
| 764 |
crmServiceClient.insertTicket(ticket, activity)
|
- |
|
| 765 |
'''
|
- |
|
| 766 |
Inform user about first delivery attempt
|
- |
|
| 767 |
'''
|
- |
|
| 768 |
enqueueMailForFDA(order)
|
- |
|
| 769 |
except:
|
- |
|
| 770 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
- |
|
| 771 |
traceback.print_exc()
|
- |
|
| 772 |
|
- |
|
| 773 |
def auto_close_crm_tickets_created():
|
710 |
def auto_close_crm_tickets_created():
|
| 774 |
try:
|
711 |
try:
|
| 775 |
ticket_created_orders = []
|
712 |
ticket_created_orders = []
|
| 776 |
tickets_map = {}
|
713 |
tickets_map = {}
|
| 777 |
crmServiceClient = CRMClient().get_client()
|
714 |
crmServiceClient = CRMClient().get_client()
|
| Line 787... |
Line 724... |
| 787 |
tickets_map[old_ticket.orderId] = old_ticket
|
724 |
tickets_map[old_ticket.orderId] = old_ticket
|
| 788 |
print ticket_created_orders
|
725 |
print ticket_created_orders
|
| 789 |
txnClient = TransactionClient().get_client()
|
726 |
txnClient = TransactionClient().get_client()
|
| 790 |
orders = txnClient.getOrderList(ticket_created_orders)
|
727 |
orders = txnClient.getOrderList(ticket_created_orders)
|
| 791 |
for order in orders:
|
728 |
for order in orders:
|
| 792 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
729 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT]:
|
| 793 |
old_ticket = tickets_map.get(order.id)
|
730 |
old_ticket = tickets_map.get(order.id)
|
| 794 |
old_ticket.status = TicketStatus.CLOSED
|
731 |
old_ticket.status = TicketStatus.CLOSED
|
| 795 |
activity = Activity()
|
732 |
activity = Activity()
|
| 796 |
activity.creatorId = 1
|
733 |
activity.creatorId = 1
|
| 797 |
activity.ticketAssigneeId = old_ticket.assigneeId
|
734 |
activity.ticketAssigneeId = old_ticket.assigneeId
|