| 6561 |
amit.gupta |
1 |
#!/usr/bin/python
|
|
|
2 |
'''
|
|
|
3 |
It processes the following reports received from Couriers
|
|
|
4 |
through email:
|
|
|
5 |
1. Pickup Report : contains details of orders that were
|
|
|
6 |
picked up from our warehouse, Return orders and DOA orders that were
|
|
|
7 |
picked up from our customers.
|
|
|
8 |
2. Delivery & RTO Report: contains details of orders that
|
|
|
9 |
were either successfully delivered to our customers or
|
|
|
10 |
which are being returned to us.
|
|
|
11 |
3. Non-delivery Report: contains details of orders whose
|
|
|
12 |
delivery date has passed but which have not been
|
|
|
13 |
delivered yet.
|
|
|
14 |
|
|
|
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
|
|
|
17 |
|
|
|
18 |
@author: Chandranshu
|
|
|
19 |
'''
|
|
|
20 |
from shop2020.clients import HelperClient
|
|
|
21 |
from shop2020.model.v1.order.impl.DataService import Order, LineItem
|
|
|
22 |
from shop2020.thriftpy.model.v1.user.ttypes import User
|
|
|
23 |
from string import Template
|
|
|
24 |
import csv
|
|
|
25 |
import datetime
|
|
|
26 |
import optparse
|
|
|
27 |
import sys
|
|
|
28 |
import time
|
|
|
29 |
import traceback
|
|
|
30 |
import xlrd
|
|
|
31 |
from shop2020.utils.Utils import to_py_date
|
|
|
32 |
|
|
|
33 |
if __name__ == '__main__' and __package__ is None:
|
|
|
34 |
import os
|
|
|
35 |
sys.path.insert(0, os.getcwd())
|
|
|
36 |
|
| 8570 |
manish.sha |
37 |
logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 2: {'name': 'Aramex', 'phone': '0124- 39419900'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}, 7: {'name': 'FedEx', 'phone' : '0120-4354176'}, 6: {'name' : 'RedExpress', 'phone' : '8373915813'}}
|
| 6561 |
amit.gupta |
38 |
FDASubjectTemplate = Template('First attempt made to deliver your $productName')
|
|
|
39 |
FDABodyTemplate = Template('<div>'+
|
|
|
40 |
'<p> Dear $customerName,<br>'+
|
|
|
41 |
'<br>An attempt was made to deliver the product you ordered. The Courier '+
|
|
|
42 |
'used was: $courierName and Airway Bill Number: $awbNumber. '+
|
|
|
43 |
'However, the product could not be delivered due to $delayReason. '+
|
|
|
44 |
'Please<a target="_blank" href="http://saholic.com/contactus"> Contact us </a>to coordinate the next delivery date.</p>'+
|
|
|
45 |
'<div> <span>Order</span> Date: $orderDate</div>'+
|
|
|
46 |
'<div>'+
|
|
|
47 |
'<table>'+
|
|
|
48 |
' <tbody>'+
|
|
|
49 |
' <tr>'+
|
|
|
50 |
' <td colspan="6">'+
|
|
|
51 |
' <hr></td>'+
|
|
|
52 |
' </tr>'+
|
|
|
53 |
' <tr>'+
|
|
|
54 |
' <td align="left" colspan="6"><b><span>Order</span> <span>Details</span></b></td>'+
|
|
|
55 |
' </tr>'+
|
|
|
56 |
' <tr>'+
|
|
|
57 |
' <td colspan="6">'+
|
|
|
58 |
' <hr></td>'+
|
|
|
59 |
' </tr>'+
|
|
|
60 |
' <tr>'+
|
|
|
61 |
' <th width="100"><span>Order</span> No.</th>'+
|
|
|
62 |
' <th>Product</th>'+
|
|
|
63 |
' <th width="100">Quantity</th>'+
|
|
|
64 |
' <td style="vertical-align:top"><span style="font-weight:bold">First Delivery Attempt</span><br>'+
|
|
|
65 |
' </td>'+
|
|
|
66 |
'<th width="100">Unit Price</th>'+
|
|
|
67 |
' <th width="100">Amount</th>'+
|
|
|
68 |
' </tr>'+
|
|
|
69 |
' <tr>'+
|
|
|
70 |
' <td align="center">$orderId</td>'+
|
|
|
71 |
' <td>$productName</td>'+
|
|
|
72 |
' <td align="center">$quantity</td>'+
|
|
|
73 |
' <td style="vertical-align:top">$fdaDate</td>'+
|
|
|
74 |
'<td align="center"> Rs. $unitPrice</td>'+
|
|
|
75 |
' <td align="center"> Rs. $total</td>'+
|
|
|
76 |
' </tr>'+
|
|
|
77 |
' '+
|
|
|
78 |
' <tr>'+
|
|
|
79 |
' <td colspan="6">'+
|
|
|
80 |
' <hr></td>'+
|
|
|
81 |
' </tr>'+
|
|
|
82 |
' <tr>'+
|
|
|
83 |
' <td colspan="5">Total Amount</td>'+
|
|
|
84 |
' <td> Rs. $totalAmount</td>'+
|
|
|
85 |
' </tr>'+
|
|
|
86 |
' <tr>'+
|
|
|
87 |
' <td style="vertical-align:top" rowspan="1" colspan="6"><br>'+
|
|
|
88 |
'</td>'+
|
|
|
89 |
' </tr>'+
|
|
|
90 |
'<tr>'+
|
|
|
91 |
' <td colspan="6">'+
|
|
|
92 |
' <hr></td>'+
|
|
|
93 |
' </tr>'+
|
|
|
94 |
' </tbody>'+
|
|
|
95 |
'</table>'+
|
|
|
96 |
'</div>'+
|
|
|
97 |
'<br>'+
|
|
|
98 |
'<p>Best Wishes,<br>'+
|
|
|
99 |
'Saholic Team </p>'+
|
|
|
100 |
'</div>')
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
def enqueueMailForFDA(order):
|
|
|
104 |
dt = to_py_date(order.created_timestamp)
|
|
|
105 |
formatted_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
|
|
106 |
|
|
|
107 |
sdt = to_py_date(order.first_attempt_timestamp)
|
|
|
108 |
fda_date = sdt.strftime("%d %B %Y")
|
|
|
109 |
'''order.lineitems[0]
|
|
|
110 |
'''
|
|
|
111 |
lineitem = order.lineitems[0]
|
|
|
112 |
productName = "{0} {1} {2} {3}".format(lineitem.brand or "", lineitem.model_name or "", lineitem.model_number or "", lineitem.color or "")
|
|
|
113 |
subject = FDASubjectTemplate.substitute(productName=productName)
|
|
|
114 |
body = FDABodyTemplate.substitute(productName=productName, customerName=order.customer_name, quantity="%.0f" % lineitem.quantity,
|
|
|
115 |
orderDate=formatted_order_date, orderId=order.id, unitPrice="%.2f" % lineitem.unit_price,
|
|
|
116 |
total = "%.2f" % lineitem.total_price, totalAmount = "%.2f" % order.total_amount, fdaDate= fda_date,
|
|
|
117 |
delayReason=order.statusDescription , awbNumber=order.airwaybill_no, courierName = logistics_providers[order.logistics_provider_id]['name'])
|
|
|
118 |
print body
|
|
|
119 |
try:
|
|
|
120 |
helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
| 10298 |
manish.sha |
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)
|
| 6561 |
amit.gupta |
122 |
except Exception as e:
|
|
|
123 |
print "Some problem occurred while enquing mail for user" + str(order.id) +" to inform FIRST_DELIVERY_ATTEMPT_MADE status"
|
|
|
124 |
print e
|