| Line 24... |
Line 24... |
| 24 |
@author: Manish Sharma
|
24 |
@author: Manish Sharma
|
| 25 |
'''
|
25 |
'''
|
| 26 |
from shop2020.clients.CRMClient import CRMClient
|
26 |
from shop2020.clients.CRMClient import CRMClient
|
| 27 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
27 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 28 |
from shop2020.clients.TransactionClient import TransactionClient
|
28 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 29 |
from shop2020.clients.UserClient import UserClient
|
29 |
from shop2020.model.v1.order.script.LogisticUtils import \
|
| 30 |
from shop2020.config.client.ConfigClient import ConfigClient
|
- |
|
| 31 |
from LogisticUtils import enqueueMailForFDA
|
30 |
create_crm_tickets_for_delivey_attempted_orders
|
| 32 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
31 |
from shop2020.thriftpy.crm.ttypes import SearchFilter, TicketCategory, Activity, \
|
| 33 |
from shop2020.thriftpy.crm.ttypes import *
|
32 |
TicketPriority, TicketStatus, ActivityType
|
| 34 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
33 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 35 |
OrderStatus
|
34 |
OrderStatus
|
| 36 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
35 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| 37 |
from shop2020.utils.Utils import to_py_date
|
36 |
from shop2020.utils.Utils import to_py_date
|
| 38 |
import csv
|
37 |
import csv
|
| 39 |
import datetime
|
- |
|
| 40 |
import optparse
|
38 |
import optparse
|
| 41 |
import sys
|
39 |
import sys
|
| 42 |
import time
|
- |
|
| 43 |
import traceback
|
40 |
import traceback
|
| 44 |
|
41 |
|
| 45 |
if __name__ == '__main__' and __package__ is None:
|
42 |
if __name__ == '__main__' and __package__ is None:
|
| 46 |
import os
|
43 |
import os
|
| 47 |
sys.path.insert(0, os.getcwd())
|
44 |
sys.path.insert(0, os.getcwd())
|
| 48 |
|
45 |
|
| 49 |
defaultUndeliveredAsssigneeId = 47
|
46 |
defaultUndeliveredAsssigneeId = 47
|
| - |
|
47 |
dtrUndeliveredAsssigneeId = 33
|
| 50 |
from_user = 'cnc.center@shop2020.in'
|
48 |
from_user = 'cnc.center@shop2020.in'
|
| 51 |
from_pwd = '5h0p2o2o'
|
49 |
from_pwd = '5h0p2o2o'
|
| 52 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
50 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
| 53 |
|
51 |
|
| 54 |
|
52 |
|
| Line 322... |
Line 320... |
| 322 |
break
|
320 |
break
|
| 323 |
if provider == None:
|
321 |
if provider == None:
|
| 324 |
sys.exit("Can't continue execution: No such provider")
|
322 |
sys.exit("Can't continue execution: No such provider")
|
| 325 |
return provider
|
323 |
return provider
|
| 326 |
|
324 |
|
| 327 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
- |
|
| 328 |
try:
|
- |
|
| 329 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
- |
|
| 330 |
userClient = UserClient().get_client()
|
- |
|
| 331 |
crmServiceClient = CRMClient().get_client()
|
- |
|
| 332 |
for order in tickets_tobe_created:
|
- |
|
| 333 |
ticket_created = False
|
- |
|
| 334 |
searchFilter = SearchFilter()
|
- |
|
| 335 |
user = userClient.getUserByEmail(order.customer_email)
|
- |
|
| 336 |
if user is None or user.userId == -1:
|
- |
|
| 337 |
searchFilter.customerEmailId = order.customer_email
|
- |
|
| 338 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 339 |
else:
|
- |
|
| 340 |
searchFilter.customerId = user.userId
|
- |
|
| 341 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
- |
|
| 342 |
tickets = crmServiceClient.getTickets(searchFilter)
|
- |
|
| 343 |
print tickets
|
- |
|
| 344 |
for old_ticket in tickets:
|
- |
|
| 345 |
if old_ticket.orderId == order.id:
|
- |
|
| 346 |
ticket_created = True
|
- |
|
| 347 |
break
|
- |
|
| 348 |
if not ticket_created:
|
- |
|
| 349 |
print "creating ticket for orderId:"+str(order.id)
|
- |
|
| 350 |
ticket = Ticket()
|
- |
|
| 351 |
activity = Activity()
|
- |
|
| 352 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
- |
|
| 353 |
ticket.creatorId = 1
|
- |
|
| 354 |
ticket.assigneeId = defaultUndeliveredAsssigneeId
|
- |
|
| 355 |
ticket.category = TicketCategory.UNDELIVERED
|
- |
|
| 356 |
ticket.priority = TicketPriority.HIGH
|
- |
|
| 357 |
ticket.status = TicketStatus.OPEN
|
- |
|
| 358 |
ticket.description = description
|
- |
|
| 359 |
ticket.orderId = order.id
|
- |
|
| 360 |
ticket.airwayBillNo = order.airwaybill_no
|
- |
|
| 361 |
|
- |
|
| 362 |
activity.creatorId = 1
|
- |
|
| 363 |
activity.ticketAssigneeId = ticket.assigneeId
|
- |
|
| 364 |
activity.type = ActivityType.OTHER
|
- |
|
| 365 |
activity.description = description
|
- |
|
| 366 |
activity.ticketCategory = ticket.category
|
- |
|
| 367 |
activity.ticketDescription = ticket.description
|
- |
|
| 368 |
activity.ticketPriority = ticket.priority
|
- |
|
| 369 |
activity.ticketStatus = ticket.status
|
- |
|
| 370 |
|
- |
|
| 371 |
if user is None or user.userId == -1:
|
- |
|
| 372 |
ticket.customerEmailId = order.customer_email
|
- |
|
| 373 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 374 |
ticket.customerName = order.customer_name
|
- |
|
| 375 |
activity.customerEmailId = order.customer_email
|
- |
|
| 376 |
activity.customerMobileNumber = order.customer_mobilenumber
|
- |
|
| 377 |
activity.customerName = order.customer_name
|
- |
|
| 378 |
else:
|
- |
|
| 379 |
ticket.customerId = user.userId
|
- |
|
| 380 |
activity.customerId = user.userId
|
- |
|
| 381 |
|
- |
|
| 382 |
crmServiceClient.insertTicket(ticket, activity)
|
- |
|
| 383 |
'''
|
- |
|
| 384 |
Inform user about first delivery attempt
|
- |
|
| 385 |
'''
|
- |
|
| 386 |
enqueueMailForFDA(order)
|
- |
|
| 387 |
except:
|
- |
|
| 388 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
- |
|
| 389 |
traceback.print_exc()
|
- |
|
| 390 |
|
- |
|
| 391 |
def auto_close_crm_tickets_created():
|
325 |
def auto_close_crm_tickets_created():
|
| 392 |
try:
|
326 |
try:
|
| 393 |
ticket_created_orders = []
|
327 |
ticket_created_orders = []
|
| 394 |
tickets_map = {}
|
328 |
tickets_map = {}
|
| 395 |
crmServiceClient = CRMClient().get_client()
|
329 |
crmServiceClient = CRMClient().get_client()
|
| Line 405... |
Line 339... |
| 405 |
tickets_map[old_ticket.orderId] = old_ticket
|
339 |
tickets_map[old_ticket.orderId] = old_ticket
|
| 406 |
print ticket_created_orders
|
340 |
print ticket_created_orders
|
| 407 |
txnClient = TransactionClient().get_client()
|
341 |
txnClient = TransactionClient().get_client()
|
| 408 |
orders = txnClient.getOrderList(ticket_created_orders)
|
342 |
orders = txnClient.getOrderList(ticket_created_orders)
|
| 409 |
for order in orders:
|
343 |
for order in orders:
|
| 410 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
344 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT]:
|
| 411 |
old_ticket = tickets_map.get(order.id)
|
345 |
old_ticket = tickets_map.get(order.id)
|
| 412 |
old_ticket.status = TicketStatus.CLOSED
|
346 |
old_ticket.status = TicketStatus.CLOSED
|
| 413 |
activity = Activity()
|
347 |
activity = Activity()
|
| 414 |
activity.creatorId = 1
|
348 |
activity.creatorId = 1
|
| 415 |
activity.ticketAssigneeId = old_ticket.assigneeId
|
349 |
activity.ticketAssigneeId = old_ticket.assigneeId
|