Subversion Repositories SmartDukaan

Rev

Rev 9173 | Rev 20088 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9173 Rev 13085
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 LogisticUtils import enqueueMailForFDA
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.clients.UserClient import UserClient
32
from shop2020.config.client.ConfigClient import ConfigClient
33
from shop2020.config.client.ConfigClient import ConfigClient
-
 
34
from shop2020.model.v1.order.script.LogisticUtils import \
33
from LogisticUtils import enqueueMailForFDA
35
    create_crm_tickets_for_delivey_attempted_orders
34
from shop2020.thriftpy.config.ttypes import ConfigException
36
from shop2020.thriftpy.config.ttypes import ConfigException
35
from shop2020.thriftpy.crm.ttypes import *
37
from shop2020.thriftpy.crm.ttypes import *
36
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
38
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
37
    OrderStatus
39
    OrderStatus
38
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
40
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
Line 57... Line 59...
57
except ConfigException as cex:
59
except ConfigException as cex:
58
    print cex.message
60
    print cex.message
59
    traceback.print_exc()
61
    traceback.print_exc()
60
 
62
 
61
defaultUndeliveredAsssigneeId = 47
63
defaultUndeliveredAsssigneeId = 47
-
 
64
dtrUndeliveredAsssigneeId = 33
62
from_user = 'cnc.center@shop2020.in'
65
from_user = 'cnc.center@shop2020.in'
63
from_pwd = '5h0p2o2o'
66
from_pwd = '5h0p2o2o'
64
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
67
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
65
 
68
 
66
def process_dao_pickup_orders(provider):
69
def process_dao_pickup_orders(provider):
Line 640... Line 643...
640
        statusDescription = ''
643
        statusDescription = ''
641
        if order.statusDescription is not None:
644
        if order.statusDescription is not None:
642
            statusDescription = order.statusDescription.replace(","," ")
645
            statusDescription = order.statusDescription.replace(","," ")
643
        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'])
646
        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'])
644
 
647
 
645
def create_crm_tickets_for_delivey_attempted_orders(provider):
-
 
646
    try:
-
 
647
        tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
-
 
648
        userClient = UserClient().get_client()
-
 
649
        crmServiceClient = CRMClient().get_client()
-
 
650
        for order in tickets_tobe_created:
-
 
651
            ticket_created = False
-
 
652
            searchFilter = SearchFilter()
-
 
653
            user = userClient.getUserByEmail(order.customer_email)
-
 
654
            if user is None or user.userId == -1:
-
 
655
                searchFilter.customerEmailId = order.customer_email
-
 
656
                searchFilter.customerMobileNumber = order.customer_mobilenumber
-
 
657
            else:
-
 
658
                searchFilter.customerId = user.userId
-
 
659
            searchFilter.ticketCategory = TicketCategory.UNDELIVERED
-
 
660
            tickets = crmServiceClient.getTickets(searchFilter)
-
 
661
            print tickets
-
 
662
            for old_ticket in tickets:
-
 
663
                if old_ticket.orderId == order.id:
-
 
664
                    ticket_created = True
-
 
665
                    break
-
 
666
            if not ticket_created:
-
 
667
                print "creating ticket for orderId:"+str(order.id)
-
 
668
                ticket = Ticket()
-
 
669
                activity = Activity()
-
 
670
                description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
-
 
671
                ticket.creatorId = 1
-
 
672
                ticket.assigneeId = defaultUndeliveredAsssigneeId
-
 
673
                ticket.category = TicketCategory.UNDELIVERED
-
 
674
                ticket.priority = TicketPriority.HIGH
-
 
675
                ticket.status = TicketStatus.OPEN
-
 
676
                ticket.description = description
-
 
677
                ticket.orderId = order.id
-
 
678
                ticket.airwayBillNo = order.airwaybill_no
-
 
679
                
-
 
680
                activity.creatorId = 1
-
 
681
                activity.ticketAssigneeId = ticket.assigneeId
-
 
682
                activity.type = ActivityType.OTHER
-
 
683
                activity.description = description
-
 
684
                activity.ticketCategory = ticket.category
-
 
685
                activity.ticketDescription = ticket.description
-
 
686
                activity.ticketPriority = ticket.priority
-
 
687
                activity.ticketStatus = ticket.status
-
 
688
                
-
 
689
                if user is None or user.userId == -1:
-
 
690
                    ticket.customerEmailId = order.customer_email
-
 
691
                    ticket.customerMobileNumber = order.customer_mobilenumber
-
 
692
                    ticket.customerName = order.customer_name
-
 
693
                    activity.customerEmailId = order.customer_email
-
 
694
                    activity.customerMobileNumber = order.customer_mobilenumber
-
 
695
                    activity.customerName = order.customer_name
-
 
696
                else:
-
 
697
                    ticket.customerId = user.userId
-
 
698
                    activity.customerId = user.userId
-
 
699
                
-
 
700
                crmServiceClient.insertTicket(ticket, activity)
-
 
701
                '''
-
 
702
                Inform user about first delivery attempt
-
 
703
                '''
-
 
704
                enqueueMailForFDA(order)
-
 
705
    except:
-
 
706
        print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
-
 
707
        traceback.print_exc()
-
 
708
 
-
 
709
def auto_close_crm_tickets_created():
648
def auto_close_crm_tickets_created():
710
    try:
649
    try:
711
        ticket_created_orders = []
650
        ticket_created_orders = []
712
        tickets_map = {}
651
        tickets_map = {}
713
        crmServiceClient = CRMClient().get_client()
652
        crmServiceClient = CRMClient().get_client()
Line 723... Line 662...
723
            tickets_map[old_ticket.orderId] = old_ticket
662
            tickets_map[old_ticket.orderId] = old_ticket
724
        print ticket_created_orders
663
        print ticket_created_orders
725
        txnClient = TransactionClient().get_client()
664
        txnClient = TransactionClient().get_client()
726
        orders = txnClient.getOrderList(ticket_created_orders)
665
        orders = txnClient.getOrderList(ticket_created_orders)
727
        for order in orders:
666
        for order in orders:
728
            if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
667
            if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT]:
729
                old_ticket = tickets_map.get(order.id)
668
                old_ticket = tickets_map.get(order.id)
730
                old_ticket.status = TicketStatus.CLOSED
669
                old_ticket.status = TicketStatus.CLOSED
731
                activity = Activity()
670
                activity = Activity()
732
                activity.creatorId = 1
671
                activity.creatorId = 1
733
                activity.ticketAssigneeId = old_ticket.assigneeId
672
                activity.ticketAssigneeId = old_ticket.assigneeId