| Line 15... |
Line 15... |
| 15 |
It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,
|
15 |
It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,
|
| 16 |
Undelivered orders report and Returned Orders report to cnc.center@shop2020.in
|
16 |
Undelivered orders report and Returned Orders report to cnc.center@shop2020.in
|
| 17 |
|
17 |
|
| 18 |
@author: Chandranshu
|
18 |
@author: Chandranshu
|
| 19 |
'''
|
19 |
'''
|
| - |
|
20 |
from shop2020.clients import HelperClient, TransactionClient
|
| - |
|
21 |
from shop2020.clients.CRMClient import CRMClient
|
| 20 |
from shop2020.clients import HelperClient
|
22 |
from shop2020.clients.UserClient import UserClient
|
| - |
|
23 |
from shop2020.thriftpy.crm.ttypes import SearchFilter, TicketCategory, Ticket, \
|
| - |
|
24 |
Activity, TicketPriority, TicketStatus, ActivityType
|
| 21 |
from shop2020.model.v1.order.impl.DataService import Order, LineItem
|
25 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus, \
|
| - |
|
26 |
TransactionServiceException
|
| 22 |
from shop2020.thriftpy.model.v1.user.ttypes import User
|
27 |
from shop2020.thriftpy.model.v1.user.ttypes import PrivateDealUser
|
| - |
|
28 |
from shop2020.utils.Utils import to_py_date
|
| 23 |
from string import Template
|
29 |
from string import Template
|
| 24 |
import csv
|
- |
|
| 25 |
import datetime
|
- |
|
| 26 |
import optparse
|
- |
|
| 27 |
import sys
|
30 |
import sys
|
| 28 |
import time
|
- |
|
| 29 |
import traceback
|
31 |
import traceback
|
| 30 |
import xlrd
|
- |
|
| 31 |
from shop2020.utils.Utils import to_py_date
|
- |
|
| 32 |
|
32 |
|
| 33 |
if __name__ == '__main__' and __package__ is None:
|
33 |
if __name__ == '__main__' and __package__ is None:
|
| 34 |
import os
|
34 |
import os
|
| 35 |
sys.path.insert(0, os.getcwd())
|
35 |
sys.path.insert(0, os.getcwd())
|
| 36 |
|
36 |
|
| Line 98... |
Line 98... |
| 98 |
'<p>Best Wishes,<br>'+
|
98 |
'<p>Best Wishes,<br>'+
|
| 99 |
'Saholic Team </p>'+
|
99 |
'Saholic Team </p>'+
|
| 100 |
'</div>')
|
100 |
'</div>')
|
| 101 |
|
101 |
|
| 102 |
|
102 |
|
| - |
|
103 |
dtrUndeliveredAsssigneeId = 33
|
| - |
|
104 |
defaultUndeliveredAsssigneeId = 47
|
| - |
|
105 |
|
| - |
|
106 |
|
| 103 |
def enqueueMailForFDA(order):
|
107 |
def enqueueMailForFDA(order):
|
| 104 |
dt = to_py_date(order.created_timestamp)
|
108 |
dt = to_py_date(order.created_timestamp)
|
| 105 |
formatted_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
109 |
formatted_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
| 106 |
|
110 |
|
| 107 |
sdt = to_py_date(order.first_attempt_timestamp)
|
111 |
sdt = to_py_date(order.first_attempt_timestamp)
|
| Line 120... |
Line 124... |
| 120 |
helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
124 |
helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
| 121 |
helper_client.saveUserEmailForSending([order.customer_email], "", subject, body, str(order.id), "FirstDeliveryAttempted", [], ['kshitij.sood@shop2020.in', 'rajneesh.arora@shop2020.in', 'pramit.singh@shop2020.in', 'amit.sirohi@shop2020.in', 'rajveer.singh@shop2020.in'], 1)
|
125 |
helper_client.saveUserEmailForSending([order.customer_email], "", subject, body, str(order.id), "FirstDeliveryAttempted", [], ['kshitij.sood@shop2020.in', 'rajneesh.arora@shop2020.in', 'pramit.singh@shop2020.in', 'amit.sirohi@shop2020.in', 'rajveer.singh@shop2020.in'], 1)
|
| 122 |
except Exception as e:
|
126 |
except Exception as e:
|
| 123 |
print "Some problem occurred while enquing mail for user" + str(order.id) +" to inform FIRST_DELIVERY_ATTEMPT_MADE status"
|
127 |
print "Some problem occurred while enquing mail for user" + str(order.id) +" to inform FIRST_DELIVERY_ATTEMPT_MADE status"
|
| 124 |
print e
|
128 |
print e
|
| - |
|
129 |
|
| - |
|
130 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
| - |
|
131 |
try:
|
| - |
|
132 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT])
|
| - |
|
133 |
userClient = UserClient().get_client()
|
| - |
|
134 |
crmServiceClient = CRMClient().get_client()
|
| - |
|
135 |
for order in tickets_tobe_created:
|
| - |
|
136 |
ticket_created = False
|
| - |
|
137 |
searchFilter = SearchFilter()
|
| - |
|
138 |
user = userClient.getUserByEmail(order.customer_email)
|
| - |
|
139 |
privateDealUser = PrivateDealUser()
|
| - |
|
140 |
if user is None or user.userId == -1:
|
| - |
|
141 |
searchFilter.customerEmailId = order.customer_email
|
| - |
|
142 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
143 |
else:
|
| - |
|
144 |
searchFilter.customerId = user.userId
|
| - |
|
145 |
privateDealUser= userClient.getPrivateDealUser(user.id)
|
| - |
|
146 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
| - |
|
147 |
tickets = crmServiceClient.getTickets(searchFilter)
|
| - |
|
148 |
print tickets
|
| - |
|
149 |
for old_ticket in tickets:
|
| - |
|
150 |
if old_ticket.orderId == order.id:
|
| - |
|
151 |
ticket_created = True
|
| - |
|
152 |
break
|
| - |
|
153 |
if not ticket_created:
|
| - |
|
154 |
if order.status == OrderStatus.RTO_IN_TRANSIT and not privateDealUser.isActive:
|
| - |
|
155 |
continue
|
| - |
|
156 |
|
| - |
|
157 |
print "creating ticket for orderId:"+str(order.id)
|
| - |
|
158 |
ticket = Ticket()
|
| - |
|
159 |
activity = Activity()
|
| - |
|
160 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
| - |
|
161 |
ticket.creatorId = 1
|
| - |
|
162 |
#Tickets of Undelivered tickets to private deal user should be assigned to Ritesh
|
| - |
|
163 |
if privateDealUser.isActive:
|
| - |
|
164 |
ticket.assigneeId = dtrUndeliveredAsssigneeId
|
| - |
|
165 |
else:
|
| - |
|
166 |
ticket.assigneeId = defaultUndeliveredAsssigneeId
|
| - |
|
167 |
ticket.category = TicketCategory.UNDELIVERED
|
| - |
|
168 |
ticket.priority = TicketPriority.HIGH
|
| - |
|
169 |
ticket.status = TicketStatus.OPEN
|
| - |
|
170 |
ticket.description = description
|
| - |
|
171 |
ticket.orderId = order.id
|
| - |
|
172 |
ticket.airwayBillNo = order.airwaybill_no
|
| - |
|
173 |
|
| - |
|
174 |
activity.creatorId = 1
|
| - |
|
175 |
activity.ticketAssigneeId = ticket.assigneeId
|
| - |
|
176 |
activity.type = ActivityType.OTHER
|
| - |
|
177 |
activity.description = description
|
| - |
|
178 |
activity.ticketCategory = ticket.category
|
| - |
|
179 |
activity.ticketDescription = ticket.description
|
| - |
|
180 |
activity.ticketPriority = ticket.priority
|
| - |
|
181 |
activity.ticketStatus = ticket.status
|
| - |
|
182 |
|
| - |
|
183 |
if user is None or user.userId == -1:
|
| - |
|
184 |
ticket.customerEmailId = order.customer_email
|
| - |
|
185 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
186 |
ticket.customerName = order.customer_name
|
| - |
|
187 |
activity.customerEmailId = order.customer_email
|
| - |
|
188 |
activity.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
189 |
activity.customerName = order.customer_name
|
| - |
|
190 |
else:
|
| - |
|
191 |
ticket.customerId = user.userId
|
| - |
|
192 |
activity.customerId = user.userId
|
| - |
|
193 |
|
| - |
|
194 |
crmServiceClient.insertTicket(ticket, activity)
|
| - |
|
195 |
'''
|
| - |
|
196 |
Inform user about first delivery attempt
|
| - |
|
197 |
'''
|
| - |
|
198 |
if not OrderStatus.RTO_IN_TRANSIT:
|
| - |
|
199 |
enqueueMailForFDA(order)
|
| - |
|
200 |
except:
|
| - |
|
201 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
| - |
|
202 |
traceback.print_exc()
|
| - |
|
203 |
|
| - |
|
204 |
def fetch_data(provider_id, order_status_list):
|
| - |
|
205 |
txnClient = TransactionClient().get_client()
|
| - |
|
206 |
try:
|
| - |
|
207 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status_list)
|
| - |
|
208 |
return doas_tobe_picked_up
|
| - |
|
209 |
except TransactionServiceException as tex:
|
| - |
|
210 |
print tex.message
|