| Line 22... |
Line 22... |
| 22 |
|
22 |
|
| 23 |
to track DOA orders and for other orders ConfigClient is called to get Delhivery_update_url
|
23 |
to track DOA orders and for other orders ConfigClient is called to get Delhivery_update_url
|
| 24 |
|
24 |
|
| 25 |
@author: Phani Kumar
|
25 |
@author: Phani Kumar
|
| 26 |
'''
|
26 |
'''
|
| 27 |
from shop2020.clients import HelperClient
|
- |
|
| 28 |
from shop2020.clients.CRMClient import CRMClient
|
27 |
from shop2020.clients.CRMClient import CRMClient
|
| 29 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
28 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 30 |
from shop2020.clients.TransactionClient import TransactionClient
|
29 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 31 |
from shop2020.clients.UserClient import UserClient
|
- |
|
| 32 |
from shop2020.config.client.ConfigClient import ConfigClient
|
30 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| - |
|
31 |
from shop2020.model.v1.order.script.LogisticUtils import \
|
| 33 |
from LogisticUtils import enqueueMailForFDA
|
32 |
create_crm_tickets_for_delivey_attempted_orders
|
| 34 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
33 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
| 35 |
from shop2020.thriftpy.crm.ttypes import *
|
34 |
from shop2020.thriftpy.crm.ttypes import SearchFilter, TicketCategory, \
|
| - |
|
35 |
TicketPriority, TicketStatus, Activity, ActivityType
|
| 36 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
36 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 37 |
OrderStatus
|
37 |
OrderStatus
|
| 38 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
38 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| 39 |
from shop2020.utils.Utils import to_py_date
|
39 |
from shop2020.utils.Utils import to_py_date
|
| 40 |
from xml.etree.ElementTree import parse
|
40 |
from xml.etree.ElementTree import parse
|
| Line 44... |
Line 44... |
| 44 |
import sys
|
44 |
import sys
|
| 45 |
import time
|
45 |
import time
|
| 46 |
import traceback
|
46 |
import traceback
|
| 47 |
import urllib2
|
47 |
import urllib2
|
| 48 |
|
48 |
|
| - |
|
49 |
|
| 49 |
if __name__ == '__main__' and __package__ is None:
|
50 |
if __name__ == '__main__' and __package__ is None:
|
| 50 |
import os
|
51 |
import os
|
| 51 |
sys.path.insert(0, os.getcwd())
|
52 |
sys.path.insert(0, os.getcwd())
|
| 52 |
|
53 |
|
| 53 |
|
54 |
|
| Line 57... |
Line 58... |
| 57 |
except ConfigException as cex:
|
58 |
except ConfigException as cex:
|
| 58 |
print cex.message
|
59 |
print cex.message
|
| 59 |
traceback.print_exc()
|
60 |
traceback.print_exc()
|
| 60 |
|
61 |
|
| 61 |
defaultUndeliveredAsssigneeId = 47
|
62 |
defaultUndeliveredAsssigneeId = 47
|
| - |
|
63 |
dtrUndeliveredAsssigneeId = 33
|
| 62 |
from_user = 'cnc.center@shop2020.in'
|
64 |
from_user = 'cnc.center@shop2020.in'
|
| 63 |
from_pwd = '5h0p2o2o'
|
65 |
from_pwd = '5h0p2o2o'
|
| 64 |
to = ["amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in"]
|
66 |
to = ["amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in"]
|
| 65 |
|
67 |
|
| 66 |
def process_dao_pickup_orders(provider):
|
68 |
def process_dao_pickup_orders(provider):
|
| Line 585... |
Line 587... |
| 585 |
statusDescription = ''
|
587 |
statusDescription = ''
|
| 586 |
if order.statusDescription is not None:
|
588 |
if order.statusDescription is not None:
|
| 587 |
statusDescription = order.statusDescription.replace(","," ")
|
589 |
statusDescription = order.statusDescription.replace(","," ")
|
| 588 |
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'])
|
590 |
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'])
|
| 589 |
|
591 |
|
| 590 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
- |
|
| 591 |
try:
|
- |
|
| 592 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
- |
|
| 593 |
userClient = UserClient().get_client()
|
- |
|
| 594 |
crmServiceClient = CRMClient().get_client()
|
- |
|
| 595 |
for order in tickets_tobe_created:
|
- |
|
| 596 |
ticket_created = False
|
- |
|
| 597 |
searchFilter = SearchFilter()
|
- |
|
| 598 |
user = userClient.getUserByEmail(order.customer_email)
|
- |
|
| 599 |
if user is None or user.userId == -1:
|
- |
|
| 600 |
searchFilter.customerEmailId = order.customer_email
|
- |
|
| 601 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 602 |
else:
|
- |
|
| 603 |
searchFilter.customerId = user.userId
|
- |
|
| 604 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
- |
|
| 605 |
tickets = crmServiceClient.getTickets(searchFilter)
|
- |
|
| 606 |
print tickets
|
- |
|
| 607 |
for old_ticket in tickets:
|
- |
|
| 608 |
if old_ticket.orderId == order.id:
|
- |
|
| 609 |
ticket_created = True
|
- |
|
| 610 |
break
|
- |
|
| 611 |
if not ticket_created:
|
- |
|
| 612 |
print "creating ticket for orderId:"+str(order.id)
|
- |
|
| 613 |
ticket = Ticket()
|
- |
|
| 614 |
activity = Activity()
|
- |
|
| 615 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
- |
|
| 616 |
ticket.creatorId = 1
|
- |
|
| 617 |
ticket.assigneeId = defaultUndeliveredAsssigneeId
|
- |
|
| 618 |
ticket.category = TicketCategory.UNDELIVERED
|
- |
|
| 619 |
ticket.priority = TicketPriority.HIGH
|
- |
|
| 620 |
ticket.status = TicketStatus.OPEN
|
- |
|
| 621 |
ticket.description = description
|
- |
|
| 622 |
ticket.orderId = order.id
|
- |
|
| 623 |
ticket.airwayBillNo = order.airwaybill_no
|
- |
|
| 624 |
|
- |
|
| 625 |
activity.creatorId = 1
|
- |
|
| 626 |
activity.ticketAssigneeId = ticket.assigneeId
|
- |
|
| 627 |
activity.type = ActivityType.OTHER
|
- |
|
| 628 |
activity.description = description
|
- |
|
| 629 |
activity.ticketCategory = ticket.category
|
- |
|
| 630 |
activity.ticketDescription = ticket.description
|
- |
|
| 631 |
activity.ticketPriority = ticket.priority
|
- |
|
| 632 |
activity.ticketStatus = ticket.status
|
- |
|
| 633 |
|
- |
|
| 634 |
if user is None or user.userId == -1:
|
- |
|
| 635 |
ticket.customerEmailId = order.customer_email
|
- |
|
| 636 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 637 |
ticket.customerName = order.customer_name
|
- |
|
| 638 |
activity.customerEmailId = order.customer_email
|
- |
|
| 639 |
activity.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 640 |
activity.customerName = order.customer_name
|
- |
|
| 641 |
else:
|
- |
|
| 642 |
ticket.customerId = user.userId
|
- |
|
| 643 |
activity.customerId = user.userId
|
- |
|
| 644 |
|
- |
|
| 645 |
crmServiceClient.insertTicket(ticket, activity)
|
- |
|
| 646 |
'''
|
- |
|
| 647 |
Inform user about first delivery attempt
|
- |
|
| 648 |
'''
|
- |
|
| 649 |
enqueueMailForFDA(order)
|
- |
|
| 650 |
|
- |
|
| 651 |
except:
|
- |
|
| 652 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
- |
|
| 653 |
traceback.print_exc()
|
- |
|
| 654 |
|
592 |
|
| 655 |
def auto_close_crm_tickets_created():
|
593 |
def auto_close_crm_tickets_created():
|
| 656 |
try:
|
594 |
try:
|
| 657 |
ticket_created_orders = []
|
595 |
ticket_created_orders = []
|
| 658 |
tickets_map = {}
|
596 |
tickets_map = {}
|
| Line 669... |
Line 607... |
| 669 |
tickets_map[old_ticket.orderId] = old_ticket
|
607 |
tickets_map[old_ticket.orderId] = old_ticket
|
| 670 |
print ticket_created_orders
|
608 |
print ticket_created_orders
|
| 671 |
txnClient = TransactionClient().get_client()
|
609 |
txnClient = TransactionClient().get_client()
|
| 672 |
orders = txnClient.getOrderList(ticket_created_orders)
|
610 |
orders = txnClient.getOrderList(ticket_created_orders)
|
| 673 |
for order in orders:
|
611 |
for order in orders:
|
| 674 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
612 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT]:
|
| 675 |
old_ticket = tickets_map.get(order.id)
|
613 |
old_ticket = tickets_map.get(order.id)
|
| 676 |
old_ticket.status = TicketStatus.CLOSED
|
614 |
old_ticket.status = TicketStatus.CLOSED
|
| 677 |
activity = Activity()
|
615 |
activity = Activity()
|
| 678 |
activity.creatorId = 1
|
616 |
activity.creatorId = 1
|
| 679 |
activity.ticketAssigneeId = old_ticket.assigneeId
|
617 |
activity.ticketAssigneeId = old_ticket.assigneeId
|