| Line 1085... |
Line 1085... |
| 1085 |
return True
|
1085 |
return True
|
| 1086 |
except Exception as e:
|
1086 |
except Exception as e:
|
| 1087 |
print e
|
1087 |
print e
|
| 1088 |
return False
|
1088 |
return False
|
| 1089 |
|
1089 |
|
| 1090 |
def enqueue_delivery_success_mail(order):
|
1090 |
def enqueue_delivery_success_mail(logisticsTxnId, orderList):
|
| - |
|
1091 |
|
| - |
|
1092 |
order = orderList[0]
|
| 1091 |
html_header = """
|
1093 |
html_header = """
|
| 1092 |
<html>
|
1094 |
<html>
|
| 1093 |
<body>
|
1095 |
<body>
|
| 1094 |
<div>
|
1096 |
<div>
|
| 1095 |
<p>
|
1097 |
<p>
|
| 1096 |
Dear $customer_name,<br /><br />
|
1098 |
Dear $customer_name,<br /><br />
|
| - |
|
1099 |
</p>"""
|
| - |
|
1100 |
|
| - |
|
1101 |
html= """
|
| - |
|
1102 |
<div>
|
| - |
|
1103 |
Order Date: $order_date <br>
|
| - |
|
1104 |
$pickup_text
|
| - |
|
1105 |
</div>
|
| - |
|
1106 |
<div>
|
| - |
|
1107 |
<table>
|
| - |
|
1108 |
<tr><td colspan="8"><hr /></td></tr>
|
| - |
|
1109 |
<tr><td colspan="8" align="left"><b>Order Details</b></td></tr>
|
| - |
|
1110 |
<tr><td colspan="8"><hr /></td></tr>
|
| - |
|
1111 |
<tr>
|
| - |
|
1112 |
<th width="100">Sub Order Id</th>
|
| - |
|
1113 |
<th>Product Name</th>
|
| - |
|
1114 |
<th width="100">Quantity</th>
|
| - |
|
1115 |
<th width="100">Unit Price</th>
|
| - |
|
1116 |
<th width="100">Amount</th>
|
| - |
|
1117 |
<th width="100">Insurance Amount</th>
|
| - |
|
1118 |
<th width="100">OTG Covered</th>
|
| - |
|
1119 |
<th width="100">Freebie Item</th>
|
| - |
|
1120 |
</tr>"""
|
| - |
|
1121 |
|
| - |
|
1122 |
total_amount = 0.0
|
| - |
|
1123 |
advanceAmount = 0.0
|
| - |
|
1124 |
hasOtg = False
|
| - |
|
1125 |
otgCount = 0
|
| - |
|
1126 |
hasFreebie = False
|
| - |
|
1127 |
hasSplitOrder = False
|
| - |
|
1128 |
hasInsurer = False
|
| - |
|
1129 |
hasPickupStoreOrder = False
|
| - |
|
1130 |
splitOrdersMap = {}
|
| - |
|
1131 |
totalUnitPrice = 0.0
|
| - |
|
1132 |
for orderObj in orderList:
|
| - |
|
1133 |
lineitem = orderObj.lineitems[0]
|
| - |
|
1134 |
lineitem_total_price = round(lineitem.total_price, 2)
|
| - |
|
1135 |
total_amount += lineitem_total_price
|
| - |
|
1136 |
advanceAmount += orderObj.advanceAmount
|
| - |
|
1137 |
html += """
|
| - |
|
1138 |
<tr>
|
| - |
|
1139 |
<td align="center">"""+str(orderObj.id)+"""</td>
|
| - |
|
1140 |
<td>"""+str(lineitem)+"""</td>
|
| - |
|
1141 |
<td align="center">"""+("%.0f" % lineitem.quantity)+"""</td>
|
| - |
|
1142 |
<td align="center">"""+("%.2f" % lineitem.unit_price)+"""</td>
|
| - |
|
1143 |
<td align="center">"""+("%.2f" % lineitem_total_price)+"""</td>"""
|
| - |
|
1144 |
if orderObj.insurer > 0:
|
| - |
|
1145 |
hasInsurer = True
|
| - |
|
1146 |
total_amount += orderObj.insuranceAmount
|
| - |
|
1147 |
html += """<td align="center">"""+("%.2f" % orderObj.insuranceAmount) +"""</td>"""
|
| - |
|
1148 |
else:
|
| - |
|
1149 |
html += """<td align="center">0.00</td>"""
|
| - |
|
1150 |
if orderObj.freebieItemId:
|
| - |
|
1151 |
hasFreebie = True
|
| - |
|
1152 |
catalog_client = CatalogClient().get_client()
|
| - |
|
1153 |
item = catalog_client.getItem(order.freebieItemId)
|
| - |
|
1154 |
html += """<td align="center">"""+item.brand+" "+item.model_name+ " " + item.model_number +"""</td>"""
|
| - |
|
1155 |
else:
|
| - |
|
1156 |
html += """<td align="center"></td>"""
|
| - |
|
1157 |
freebieOrderId = get_order_attribute_value(orderObj.id, "freebieOrderId")
|
| - |
|
1158 |
if freebieOrderId != "":
|
| - |
|
1159 |
freebieOrder = get_order(freebieOrderId)
|
| - |
|
1160 |
hasSplitOrder = True
|
| - |
|
1161 |
splitOrdersMap[orderObj.id] = freebieOrder
|
| - |
|
1162 |
if orderObj.pickupStoreId:
|
| - |
|
1163 |
hasPickupStoreOrder = True
|
| - |
|
1164 |
if orderObj.otg:
|
| - |
|
1165 |
hasOtg = True
|
| - |
|
1166 |
otgCount += 1
|
| - |
|
1167 |
totalUnitPrice += lineitem.unit_price
|
| - |
|
1168 |
html += """<td align="center">Yes</td>"""
|
| - |
|
1169 |
else:
|
| - |
|
1170 |
html += """<td align="center">No</td>"""
|
| - |
|
1171 |
|
| - |
|
1172 |
html += """
|
| - |
|
1173 |
</tr>
|
| - |
|
1174 |
"""
|
| - |
|
1175 |
html += """
|
| - |
|
1176 |
<tr><td colspan=8> </td></tr>
|
| - |
|
1177 |
<tr><td colspan=8><hr /></td></tr>"""
|
| - |
|
1178 |
amount_string = "Total Amount"
|
| - |
|
1179 |
if advanceAmount > 0:
|
| - |
|
1180 |
html += """<tr>
|
| - |
|
1181 |
<td colspan="7">Advance Amount</td>
|
| - |
|
1182 |
<td>Rs."""+("%.2f" % advanceAmount)+"""
|
| - |
|
1183 |
</tr>
|
| - |
|
1184 |
"""
|
| - |
|
1185 |
total_amount -= advanceAmount
|
| - |
|
1186 |
amount_string = "Balance Amount"
|
| - |
|
1187 |
html += """<tr>
|
| - |
|
1188 |
<td colspan="7">"""+amount_string+"""</td>
|
| - |
|
1189 |
<td>Rs."""+("%.2f" % total_amount)+"""
|
| - |
|
1190 |
</tr>
|
| - |
|
1191 |
"""
|
| - |
|
1192 |
|
| - |
|
1193 |
html += """
|
| - |
|
1194 |
$freebie_text
|
| - |
|
1195 |
$insurance_text
|
| - |
|
1196 |
</div>
|
| - |
|
1197 |
<p>
|
| - |
|
1198 |
Best Wishes,<br />
|
| - |
|
1199 |
$source_name Team
|
| - |
|
1200 |
</p>
|
| - |
|
1201 |
</div>
|
| - |
|
1202 |
</body>
|
| - |
|
1203 |
</html>
|
| 1097 |
"""
|
1204 |
"""
|
| 1098 |
|
1205 |
|
| 1099 |
if order.pickupStoreId:
|
1206 |
if hasPickupStoreOrder:
|
| 1100 |
pickup_text = "Pickup Date: " + order.delivery_timestamp.strftime("%A, %d. %B %Y %I:%M%p")
|
1207 |
pickup_text = "Pickup Date: " + order.delivery_timestamp.strftime("%A, %d. %B %Y %I:%M%p")
|
| 1101 |
thank_you_html = """
|
1208 |
thank_you_html = """
|
| 1102 |
Thank you for shopping with us and picking up your order in Store. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers.<br><br>
|
1209 |
Thank you for shopping with us and picking up your order in Store.
|
| 1103 |
|
1210 |
|
| 1104 |
Following are the details of your order for which the pickup has happened. If you have not picked up this product please <a href="$source_url/contact-us" target="_blank">contact us</a> immediately.<br>
|
1211 |
Following are the details of your order for which the pickup has happened. <br> If you have not picked up this product please <a href="$source_url/contact-us" target="_blank">contact us</a> immediately.<br>
|
| - |
|
1212 |
If you are happy with our services please join us on <a href="https://twitter.com/saholic">Twitter</a>, <a href="http://www.facebook.com/mysaholic">Facebook Page</a> and help us spread the word
|
| 1105 |
"""
|
1213 |
"""
|
| 1106 |
else:
|
1214 |
else:
|
| 1107 |
pickup_text = ""
|
- |
|
| 1108 |
if order.otg:
|
1215 |
if hasOtg:
|
| 1109 |
|
- |
|
| 1110 |
delayed = False
|
1216 |
delayed = False
|
| 1111 |
fda = False
|
1217 |
fda = False
|
| 1112 |
|
1218 |
|
| 1113 |
if order.first_dlvyatmp_timestamp.date() < order.delivery_timestamp.date():
|
1219 |
if order.first_dlvyatmp_timestamp.date() < order.delivery_timestamp.date():
|
| 1114 |
fda = True
|
1220 |
fda = True
|
| 1115 |
|
1221 |
|
| 1116 |
fda_datetime = order.first_dlvyatmp_timestamp
|
1222 |
fda_datetime = order.first_dlvyatmp_timestamp
|
| 1117 |
fda_date = fda_datetime.date()
|
1223 |
fda_date = fda_datetime.date()
|
| 1118 |
|
1224 |
|
| 1119 |
if order.promised_delivery_time.date() < fda_date:
|
1225 |
if order.promised_delivery_time.date() < fda_date:
|
| 1120 |
delayed = True
|
1226 |
delayed = True
|
| 1121 |
|
1227 |
|
| 1122 |
if not delayed and not fda:
|
1228 |
if not delayed and not fda:
|
| 1123 |
thank_you_html = """As Promised """ + str(order.lineitems[0]) +""" ordered by you has been <b>Delivered On Time.</b>"""
|
1229 |
thank_you_html = """We are pleased to inform that the following items in your order $master_order_id have been delivered.<br/>As Promised order placed by you has been <b>Delivered On Time.</b><br/>
|
| - |
|
1230 |
If you are happy with our services please join us on <a href="https://twitter.com/saholic">Twitter</a>, <a href="http://www.facebook.com/mysaholic">Facebook Page</a> and help us spread the word
|
| - |
|
1231 |
Delivered Item Details are:
|
| - |
|
1232 |
"""
|
| 1124 |
elif delayed:
|
1233 |
elif delayed:
|
| 1125 |
max_discount = 500
|
1234 |
max_discount = 500*otgCount
|
| 1126 |
delayedDays = max(1,get_business_days_count(order.promised_delivery_time, fda_datetime))
|
1235 |
delayedDays = max(1,get_business_days_count(order.promised_delivery_time, fda_datetime))
|
| 1127 |
max_discount = min(max_discount, order.lineitems[0].unit_price/10)
|
1236 |
max_discount = min(max_discount, totalUnitPrice/10)
|
| 1128 |
discount = min(round(max_discount),delayedDays*50)
|
1237 |
discount = min(round(max_discount),delayedDays*50)
|
| 1129 |
promotion_client = PromotionClient().get_client()
|
1238 |
promotion_client = PromotionClient().get_client()
|
| 1130 |
endOn = order.delivery_timestamp + datetime.timedelta(days = 30)
|
1239 |
endOn = order.delivery_timestamp + datetime.timedelta(days = 30)
|
| 1131 |
expiry = endOn.strftime("%A, %d. %B %Y")
|
1240 |
expiry = endOn.strftime("%A, %d. %B %Y")
|
| 1132 |
endOn = to_java_date(endOn)
|
1241 |
endOn = to_java_date(endOn)
|
| 1133 |
arguments = "{\"endOn\":" + str(endOn) + ", \"emails\":[\"" + order.customer_email + "\"], \"couponType\":\"both\", \"usage_limit_for_user\":1, \"isCod\":False, \"discount\":" + str(discount) + "}"
|
1242 |
arguments = "{\"endOn\":" + str(endOn) + ", \"emails\":[\"" + order.customer_email + "\"], \"couponType\":\"both\", \"usage_limit_for_user\":1, \"isCod\":False, \"discount\":" + str(discount) + "}"
|
| 1134 |
otgCoupon = promotion_client.createCoupon(28,CouponCategory.CUSTOMER_SATISFACTION , '', arguments, False, "otg")
|
1243 |
otgCoupon = promotion_client.createCoupon(28,CouponCategory.CUSTOMER_SATISFACTION , '', arguments, False, "otg")
|
| 1135 |
thank_you_html = '$prodName ordered by you has been delivered. We apologise for a delay of $delayedDays business days.<br><br> As per our <b>On Time Guarantee</b> Please accept a Gift Voucher worth <b>Rs.$discount</b> as a token of our apology. <br><br>Your unique Gift Voucher Code is <b>$otgCoupon</b>. <br><br>You can use the same to buy any Mobile, Camera, Laptop, Tablet, Accessory or Mobile/DTH Recharge from our website.<br> Note:GV is valid till $expiry and GV amount cannot be split, please use the entire amount of GV in one transaction.<br>'
|
1244 |
thank_you_html = """Following items in your order """+logisticsTxnId+""" have been delivered. We apologise for a delay of """+delayedDays+""" days<br/>
|
| 1136 |
thank_you_html = Template(thank_you_html).substitute(dict(prodName=order.lineitems[0], delayedDays = delayedDays, discount = discount, otgCoupon = otgCoupon, expiry = expiry))
|
1245 |
As per our On Time Guarantee Please accept a Gift Voucher worth Rs."""+str(discount)+"""as a token of our apology.
|
| - |
|
1246 |
Your unique Gift Voucher Code is """+otgCoupon+""" Gift Voucher Expiry Date: """+expiry+"""<br/>
|
| - |
|
1247 |
You can use the same to buy any Mobile, Camera, Laptop, Tablet, Accessory or Mobile/DTH Recharge from our website.</br/>
|
| - |
|
1248 |
If you are happy with our services please join us on <a href="https://twitter.com/saholic">Twitter</a>, <a href="http://www.facebook.com/mysaholic">Facebook Page</a> and help us spread the word
|
| - |
|
1249 |
"""
|
| 1137 |
elif fda:
|
1250 |
elif fda:
|
| 1138 |
fdaFormattedString = order.first_dlvyatmp_timestamp.strftime("%A, %d. %B %Y")
|
1251 |
fdaFormattedString = order.first_dlvyatmp_timestamp.strftime("%A, %d. %B %Y")
|
| 1139 |
thank_you_html = str(order.lineitems[0]) + """ ordered by you has been delivered. The First Delivery attempt was made on """+ fdaFormattedString +""" , within our commited estimated time for delivery."""
|
1252 |
thank_you_html = """We are pleased to inform that the following items in your order $master_order_id have been delivered.<br/> The First Delivery attempt was made on """+ fdaFormattedString +""" , within our commited estimated time for delivery.<br/>
|
| 1140 |
|
- |
|
| 1141 |
thank_you_html = thank_you_html + """If you are happy with our services please join us on <a href="http://www.facebook.com/mysaholic">Facebook</a>/<a href="https://twitter.com/saholic">Twitter</a> and help us spread the word."""
|
1253 |
If you are happy with our services please join us on <a href="https://twitter.com/saholic">Twitter</a>, <a href="http://www.facebook.com/mysaholic">Facebook Page</a> and help us spread the word
|
| - |
|
1254 |
Following Items are Delivered:
|
| 1142 |
|
1255 |
"""
|
| 1143 |
else :
|
1256 |
else :
|
| 1144 |
thank_you_html = str(order.lineitems[0]) + """ ordered by you has been delivered.
|
1257 |
thank_you_html = """We are pleased to inform that the following items in your order $master_order_id have been delivered.<br/>
|
| 1145 |
Thank you for shopping with us. Please do join us at our <a href="http://www.facebook.com/mysaholic">Facebook Page</a>, and share your experience with other shoppers. Following are the details of your order.<br>
|
1258 |
If you are happy with our services please join us on <a href="https://twitter.com/saholic">Twitter</a>, <a href="http://www.facebook.com/mysaholic">Facebook Page</a> and help us spread the word
|
| - |
|
1259 |
Following Items are Delivered:
|
| 1146 |
"""
|
1260 |
"""
|
| 1147 |
|
1261 |
|
| 1148 |
freebie_text = "<br/>"
|
1262 |
freebie_text = "<br/>"
|
| - |
|
1263 |
if hasFreebie and not hasSplitOrder:
|
| - |
|
1264 |
freebie_text = freebie_text + "We have also delivered your freebies with eligible products as promised<br/>"
|
| 1149 |
if order.freebieItemId:
|
1265 |
elif not hasFreebie and hasSplitOrder:
|
| - |
|
1266 |
freebie_text = freebie_text + "We wish to inform you that your freebie item(s): <br/>"
|
| 1150 |
catalog_client = CatalogClient().get_client()
|
1267 |
for splitOrder in splitOrdersMap.values():
|
| 1151 |
item = catalog_client.getItem(order.freebieItemId)
|
1268 |
freebieLineItem = get_line_items_for_order(splitOrder.id)[0]
|
| 1152 |
freebie_text = freebie_text = "We have also delivered " + item.brand + " " + item.modelName + "" + item.modelNumber +" as promised"
|
1269 |
freebie_text = freebie_text + freebieLineItem.brand + " " + freebieLineItem.model_name + " " + freebieLineItem.model_number + " will be sent as a separate order with OrderId : " + str(splitOrder.id) + " and is expected to be delivered on " + splitOrder.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>"+ "<br/>You can track the status of this order from My Orders section in saholic.com"
|
| 1153 |
else:
|
1270 |
elif hasFreebie and hasSplitOrder:
|
| 1154 |
freebie_orderId = get_order_attribute_value(order.id, "freebieOrderId")
|
1271 |
freebie_text = freebie_text + "We have also delivered some of your freebies with eligible products as promised and rest freebie item(s) details are given below: <br/>"
|
| 1155 |
if freebie_orderId != "":
|
1272 |
for splitOrder in splitOrdersMap.values():
|
| 1156 |
line_items = get_line_items_for_order(int(freebie_orderId))
|
1273 |
freebieLineItem = get_line_items_for_order(splitOrder.id)[0]
|
| 1157 |
freebie_order = get_order(int(freebie_orderId))
|
1274 |
freebie_text = freebie_text + freebieLineItem.brand + " " + freebieLineItem.model_name + " " + freebieLineItem.model_number + " will be sent as a separate order with OrderId : " + str(splitOrder.id) + " and is expected to be delivered on " + splitOrder.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>" + "<br/>You can track the status of this order from My Orders section in saholic.com"
|
| - |
|
1275 |
else:
|
| - |
|
1276 |
freebie_text = ""
|
| - |
|
1277 |
|
| - |
|
1278 |
insuranceText = ""
|
| - |
|
1279 |
if hasInsurer:
|
| 1158 |
freebie_text = freebie_text + " We wish to inform you that your freebie item " +line_items[0].brand + " " + line_items[0].model_name + " " + line_items[0].model_number + " will be sent as a separate order with OrderId : " + freebie_orderId + " and is expected to be delivered on " + freebie_order.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>You can track the status of this order from My Orders section in saholic.com"
|
1280 |
insuranceText = "Some item(s) are Insured Against Theft for 1 Year. <a href='http://www.saholic.com/static/insurance-terms'>Know More</a><br/>Please download and read attached policy document."
|
| 1159 |
|
1281 |
|
| 1160 |
html_header = html_header + thank_you_html + """
|
- |
|
| 1161 |
</p>
|
- |
|
| 1162 |
<div>
|
- |
|
| 1163 |
Order Date: $order_date <br>
|
- |
|
| 1164 |
$pickup_text
|
- |
|
| 1165 |
</div>
|
- |
|
| 1166 |
<div>
|
- |
|
| 1167 |
<table>
|
- |
|
| 1168 |
<tr><td colspan="5"><hr /></td></tr>
|
- |
|
| 1169 |
<tr><td colspan="5" align="left"><b>Order Details</b></td></tr>
|
- |
|
| 1170 |
<tr><td colspan="5"><hr /></td></tr>
|
- |
|
| 1171 |
<tr>
|
- |
|
| 1172 |
<th width="100">Order No.</th>
|
- |
|
| 1173 |
<th>Product</th>
|
- |
|
| 1174 |
<th width="100">Quantity</th>
|
- |
|
| 1175 |
<th width="100">Unit Price</th>
|
- |
|
| 1176 |
<th width="100">Amount</th>
|
- |
|
| 1177 |
</tr>
|
- |
|
| 1178 |
"""
|
- |
|
| 1179 |
total_amount = 0.0
|
- |
|
| 1180 |
html_table = ""
|
- |
|
| 1181 |
|
- |
|
| 1182 |
customer_name = order.customer_name
|
1282 |
customer_name = order.customer_name
|
| 1183 |
order_date = order.created_timestamp
|
1283 |
order_date = order.created_timestamp
|
| 1184 |
user_email = order.customer_email
|
1284 |
user_email = order.customer_email
|
| 1185 |
html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
|
- |
|
| 1186 |
|
- |
|
| 1187 |
for lineitem in order.lineitems:
|
- |
|
| 1188 |
lineitem_total_price = round(lineitem.total_price, 2)
|
- |
|
| 1189 |
|
1285 |
|
| 1190 |
html_tr += "<td>" + str(lineitem) + "</td>"
|
- |
|
| 1191 |
html_tr += "<td align='center'>" + ("%.0f" % lineitem.quantity) + "</td>"
|
- |
|
| 1192 |
html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem.unit_price) + "</td>"
|
- |
|
| 1193 |
html_tr += "<td align='center'> Rs. " + ("%.2f" % lineitem_total_price) + "</td></tr>"
|
- |
|
| 1194 |
total_amount += lineitem_total_price
|
- |
|
| 1195 |
html_table += html_tr
|
- |
|
| 1196 |
if order.insurer:
|
- |
|
| 1197 |
html_table += "<tr><td align='center'></td><td style='font-style:italic;'>Insured Against Theft for 1 Year. <a href='http://www.saholic.com/static/insurance-terms'>Know More</a></td><td align='center'></td><td align='center'></td>"
|
- |
|
| 1198 |
html_table += "<td align='center'>" + str(order.insuranceAmount) + "</td></tr>"
|
- |
|
| 1199 |
html_table += "<tr><td align='center'></td><td style='font-style:italic;'>Please download and read attached policy document.</td><td align='center'></td><td align='center'></td></tr>"
|
- |
|
| 1200 |
total_amount += order.insuranceAmount
|
- |
|
| 1201 |
|
- |
|
| 1202 |
html_footer = """
|
- |
|
| 1203 |
<tr><td colspan=5> </td></tr>
|
- |
|
| 1204 |
<tr><td colspan=5><hr /></td></tr>
|
- |
|
| 1205 |
<tr>
|
- |
|
| 1206 |
<td colspan=4>Total Amount</td>
|
- |
|
| 1207 |
<td> Rs. $total_amount</td>
|
- |
|
| 1208 |
</tr>
|
- |
|
| 1209 |
</table>
|
- |
|
| 1210 |
$freebie_text
|
- |
|
| 1211 |
</div>
|
- |
|
| 1212 |
<p>
|
- |
|
| 1213 |
Best Wishes,<br />
|
- |
|
| 1214 |
$source_name Team
|
- |
|
| 1215 |
</p>
|
- |
|
| 1216 |
</div>
|
- |
|
| 1217 |
</body>
|
- |
|
| 1218 |
</html>
|
- |
|
| 1219 |
"""
|
- |
|
| 1220 |
|
- |
|
| 1221 |
subject = "Your order for " + str(order.lineitems[0]) + " is now complete"
|
1286 |
subject = "Your order "+logisticsTxnId+" is now complete"
|
| 1222 |
dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
|
1287 |
dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
|
| 1223 |
formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
1288 |
formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
| 1224 |
|
- |
|
| 1225 |
|
1289 |
|
| 1226 |
email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name, pickup_text = pickup_text, source_url = source_url))
|
1290 |
complete_html = html_header + thank_you_html + html
|
| - |
|
1291 |
|
| 1227 |
email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, source_name = source_name, freebie_text = freebie_text))
|
1292 |
email_html = Template(complete_html).substitute(dict(order_date = formated_order_date, customer_name = customer_name, pickup_text = pickup_text, source_url = source_url, source_name = source_name, freebie_text = freebie_text, insurance_text = insuranceText))
|
| 1228 |
|
1293 |
|
| 1229 |
try:
|
1294 |
try:
|
| 1230 |
helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
1295 |
helper_client = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
| 1231 |
helper_client.saveUserEmailForSending([user_email], "", subject, email_header + html_table + email_footer, str(order.id), "DeliverySuccess", [], [], order.source)
|
1296 |
helper_client.saveUserEmailForSending([user_email], "", subject, email_html, logisticsTxnId, "DeliverySuccess", [], [], order.source)
|
| 1232 |
|
1297 |
|
| 1233 |
if order.source == OrderSource.WEBSITE:
|
1298 |
if order.source == OrderSource.WEBSITE:
|
| 1234 |
send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, Your order: " + str(order.id) + " has been delivered now. For any queries please call 0120-2479977." , SmsType.TRANSACTIONAL)
|
1299 |
send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, Your order: " + logisticsTxnId + " has been delivered now. For any queries please call 0120-2479977." , SmsType.TRANSACTIONAL)
|
| 1235 |
|
1300 |
|
| 1236 |
return True
|
1301 |
return True
|
| 1237 |
except Exception as e:
|
1302 |
except Exception as e:
|
| 1238 |
print e
|
1303 |
print e
|
| 1239 |
return False
|
1304 |
return False
|
| Line 1970... |
Line 2035... |
| 1970 |
alert_client.scheduleAlert(monitoredEntity)
|
2035 |
alert_client.scheduleAlert(monitoredEntity)
|
| 1971 |
except Exception as e:
|
2036 |
except Exception as e:
|
| 1972 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
2037 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 1973 |
print e
|
2038 |
print e
|
| 1974 |
session.commit()
|
2039 |
session.commit()
|
| - |
|
2040 |
logisticsTxnIdOrdersMap = {}
|
| - |
|
2041 |
try:
|
| - |
|
2042 |
for order in orders:
|
| - |
|
2043 |
if logisticsTxnIdOrdersMap.has_key(order.logisticsTransactionId):
|
| - |
|
2044 |
ordersList = logisticsTxnIdOrdersMap.get(order.logisticsTransactionId)
|
| - |
|
2045 |
ordersList.append(order)
|
| - |
|
2046 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
| - |
|
2047 |
else:
|
| - |
|
2048 |
ordersList = []
|
| - |
|
2049 |
ordersList.append(order)
|
| - |
|
2050 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
| - |
|
2051 |
except Exception as e:
|
| - |
|
2052 |
print e
|
| 1975 |
|
2053 |
|
| - |
|
2054 |
for logisticsTxnId, orderList in logisticsTxnIdOrdersMap.iteritems():
|
| - |
|
2055 |
enqueue_shipping_confirmation_email(logisticsTxnId, orderList)
|
| 1976 |
|
2056 |
|
| 1977 |
try:
|
2057 |
try:
|
| 1978 |
for order in orders:
|
2058 |
for order in orders:
|
| 1979 |
if order.pickupStoreId:
|
2059 |
if order.pickupStoreId:
|
| 1980 |
send_mails_to_bdms(order)
|
2060 |
send_mails_to_bdms(order)
|
| - |
|
2061 |
'''
|
| 1981 |
else:
|
2062 |
else:
|
| 1982 |
enqueue_shipping_confirmation_email(order)
|
2063 |
enqueue_shipping_confirmation_email(order)
|
| - |
|
2064 |
'''
|
| 1983 |
except Exception as e:
|
2065 |
except Exception as e:
|
| 1984 |
print e
|
2066 |
print e
|
| 1985 |
|
2067 |
|
| 1986 |
return True
|
2068 |
return True
|
| 1987 |
except:
|
2069 |
except:
|
| Line 2094... |
Line 2176... |
| 2094 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
2176 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 2095 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.SHIPPED_FROM_WH).filter(Order.shipping_timestamp <= to_datetime).all()
|
2177 |
orders_not_picked_up = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.SHIPPED_FROM_WH).filter(Order.shipping_timestamp <= to_datetime).all()
|
| 2096 |
return orders_not_picked_up
|
2178 |
return orders_not_picked_up
|
| 2097 |
|
2179 |
|
| 2098 |
def mark_orders_as_delivered(provider_id, delivered_orders):
|
2180 |
def mark_orders_as_delivered(provider_id, delivered_orders):
|
| - |
|
2181 |
logisticsTxnIdOrdersMap = {}
|
| 2099 |
for awb, detail in delivered_orders.iteritems():
|
2182 |
for awb, detail in delivered_orders.iteritems():
|
| 2100 |
orders = []
|
2183 |
orders = []
|
| 2101 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
2184 |
orders = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).all()
|
| 2102 |
if orders == None or len(orders) ==0:
|
2185 |
if orders == None or len(orders) ==0:
|
| 2103 |
continue
|
2186 |
continue
|
| 2104 |
for order in orders:
|
2187 |
for order in orders:
|
| 2105 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
2188 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
| 2106 |
continue
|
2189 |
continue
|
| - |
|
2190 |
if order.logisticsTransactionId:
|
| - |
|
2191 |
if logisticsTxnIdOrdersMap.has_key(order.logisticsTransactionId):
|
| - |
|
2192 |
orderList = logisticsTxnIdOrdersMap.get(order.logisticsTransactionId)
|
| - |
|
2193 |
orderList.append(order)
|
| - |
|
2194 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = orderList
|
| - |
|
2195 |
else:
|
| - |
|
2196 |
orderList =[]
|
| - |
|
2197 |
orderList.append(order)
|
| - |
|
2198 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = orderList
|
| - |
|
2199 |
else:
|
| - |
|
2200 |
orderList =[]
|
| - |
|
2201 |
orderList.append(order)
|
| - |
|
2202 |
logisticsTxnIdOrdersMap[str(order.id)] = orderList
|
| 2107 |
timestamp, receiver = detail.split('|')
|
2203 |
timestamp, receiver = detail.split('|')
|
| 2108 |
order.delivery_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
2204 |
order.delivery_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
| 2109 |
if order.first_dlvyatmp_timestamp is None:
|
2205 |
if order.first_dlvyatmp_timestamp is None:
|
| 2110 |
order.first_dlvyatmp_timestamp = order.delivery_timestamp
|
2206 |
order.first_dlvyatmp_timestamp = order.delivery_timestamp
|
| 2111 |
order.receiver = receiver
|
2207 |
order.receiver = receiver
|
| Line 2141... |
Line 2237... |
| 2141 |
|
2237 |
|
| 2142 |
if order.dataInsuranceDetails:
|
2238 |
if order.dataInsuranceDetails:
|
| 2143 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
2239 |
order.dataInsuranceDetails[0].startDate = order.delivery_timestamp
|
| 2144 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
2240 |
order.dataInsuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 90)
|
| 2145 |
|
2241 |
|
| 2146 |
if enqueue_delivery_success_mail(order) :
|
- |
|
| 2147 |
session.commit()
|
- |
|
| 2148 |
else :
|
- |
|
| 2149 |
session.rollback()
|
- |
|
| 2150 |
try:
|
2242 |
try:
|
| 2151 |
alert_client = AlertClient().get_client()
|
2243 |
alert_client = AlertClient().get_client()
|
| 2152 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
2244 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 2153 |
except Exception as e:
|
2245 |
except Exception as e:
|
| 2154 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
2246 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 2155 |
print e
|
2247 |
print e
|
| - |
|
2248 |
|
| - |
|
2249 |
for logisticsTxnId, ordersList in logisticsTxnIdOrdersMap.iteritems():
|
| - |
|
2250 |
if enqueue_delivery_success_mail(logisticsTxnId, ordersList) :
|
| - |
|
2251 |
session.commit()
|
| - |
|
2252 |
else :
|
| - |
|
2253 |
session.rollback()
|
| - |
|
2254 |
|
| 2156 |
|
2255 |
|
| 2157 |
def update_insurance_details(order):
|
2256 |
def update_insurance_details(order):
|
| 2158 |
order.insuranceDetails[0].startDate = order.delivery_timestamp
|
2257 |
order.insuranceDetails[0].startDate = order.delivery_timestamp
|
| 2159 |
order.insuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 365)
|
2258 |
order.insuranceDetails[0].expiryDate = order.delivery_timestamp + timedelta(days = 365)
|
| 2160 |
filename = "/tmp/" + str(order.id) + "-insurance-policy.pdf"
|
2259 |
filename = "/tmp/" + str(order.id) + "-insurance-policy.pdf"
|
| Line 2166... |
Line 2265... |
| 2166 |
doc.docSource = order.id
|
2265 |
doc.docSource = order.id
|
| 2167 |
doc.document = pdfFile
|
2266 |
doc.document = pdfFile
|
| 2168 |
|
2267 |
|
| 2169 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
2268 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
| 2170 |
singleOrder = Order.get_by(id=orderId)
|
2269 |
singleOrder = Order.get_by(id=orderId)
|
| - |
|
2270 |
logisticsTxnIdOrdersMap = {}
|
| 2171 |
|
2271 |
|
| 2172 |
grouppedOrdersList = []
|
2272 |
grouppedOrdersList = []
|
| 2173 |
if singleOrder.logisticsTransactionId:
|
2273 |
if singleOrder.logisticsTransactionId:
|
| 2174 |
grouppedOrdersList = get_group_orders_by_logistics_txn_id(singleOrder.logisticsTransactionId)
|
2274 |
grouppedOrdersList = get_group_orders_by_logistics_txn_id(singleOrder.logisticsTransactionId)
|
| - |
|
2275 |
for order in grouppedOrdersList:
|
| - |
|
2276 |
if logisticsTxnIdOrdersMap.has_key(order.logisticsTransactionId):
|
| - |
|
2277 |
orderList = logisticsTxnIdOrdersMap.get(order.logisticsTransactionId)
|
| - |
|
2278 |
orderList.append(order)
|
| - |
|
2279 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId]= orderList
|
| - |
|
2280 |
else:
|
| - |
|
2281 |
orderList=[]
|
| - |
|
2282 |
orderList.append(order)
|
| - |
|
2283 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId]= orderList
|
| 2175 |
else:
|
2284 |
else:
|
| 2176 |
grouppedOrdersList.append(singleOrder)
|
2285 |
grouppedOrdersList.append(singleOrder)
|
| - |
|
2286 |
logisticsTxnIdOrdersMap[str(singleOrder.id)]= grouppedOrdersList
|
| 2177 |
|
2287 |
|
| 2178 |
for order in grouppedOrdersList:
|
2288 |
for order in grouppedOrdersList:
|
| 2179 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_RECEIVED, OrderStatus.RET_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_AUTHORIZED, OrderStatus.RET_PICKUP_REQUEST_RAISED, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
|
2289 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.DOA_PICKUP_REQUEST_RAISED, OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_RECEIVED, OrderStatus.RET_PICKUP_CONFIRMED, OrderStatus.RET_REQUEST_AUTHORIZED, OrderStatus.RET_PICKUP_REQUEST_RAISED, OrderStatus.RTO_IN_TRANSIT, OrderStatus.BILLED, OrderStatus.RECEIVED_AT_STORE]:
|
| 2180 |
raise TransactionServiceException(101, "Either wrong order id or invalid state " + str(orderId))
|
2290 |
raise TransactionServiceException(101, "Either wrong order id or invalid state " + str(orderId))
|
| 2181 |
|
2291 |
|
| Line 2207... |
Line 2317... |
| 2207 |
sod.payStatus = StorePaymentStatus.FULL_PAY_RECEIVED
|
2317 |
sod.payStatus = StorePaymentStatus.FULL_PAY_RECEIVED
|
| 2208 |
session.commit()
|
2318 |
session.commit()
|
| 2209 |
|
2319 |
|
| 2210 |
if order.pickupStoreId and order.cod:
|
2320 |
if order.pickupStoreId and order.cod:
|
| 2211 |
__push_collection_to_hotspot(order, "SALE")
|
2321 |
__push_collection_to_hotspot(order, "SALE")
|
| - |
|
2322 |
|
| - |
|
2323 |
for logisticsTxnId, ordersList in logisticsTxnIdOrdersMap.iteritems():
|
| - |
|
2324 |
enqueue_delivery_success_mail(logisticsTxnId, ordersList)
|
| - |
|
2325 |
|
| 2212 |
|
2326 |
|
| 2213 |
enqueue_delivery_success_mail(order)
|
- |
|
| 2214 |
# if order.pickupStoreId:
|
2327 |
# if order.pickupStoreId:
|
| 2215 |
# payment_client = PaymentClient().get_client()
|
2328 |
# payment_client = PaymentClient().get_client()
|
| 2216 |
# payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
|
2329 |
# payment_client.createRefund(order.id, order.transaction.id, order.total_amount)
|
| 2217 |
# payment_client = PaymentClient().get_client()
|
2330 |
# payment_client = PaymentClient().get_client()
|
| 2218 |
# payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
|
2331 |
# payment_client.partiallyCapturePayment(order.transaction.id, order.total_amount, xferBy, xferTxnId, now())
|
| Line 4505... |
Line 4618... |
| 4505 |
|
4618 |
|
| 4506 |
def get_reshipped_order_ids(order_ids):
|
4619 |
def get_reshipped_order_ids(order_ids):
|
| 4507 |
reshipped_order_ids = []
|
4620 |
reshipped_order_ids = []
|
| 4508 |
return [order.new_order_id for order in Order.query.filter(Order.new_order_id.in_(order_ids)).all()]
|
4621 |
return [order.new_order_id for order in Order.query.filter(Order.new_order_id.in_(order_ids)).all()]
|
| 4509 |
|
4622 |
|
| 4510 |
def get_shipping_confirmation_email_body(order):
|
4623 |
def get_shipping_confirmation_email_body(logisticsTxnId, orderList):
|
| 4511 |
|
4624 |
order = orderList[0]
|
| 4512 |
html = """
|
4625 |
html = """
|
| 4513 |
<html>
|
4626 |
<html>
|
| 4514 |
<body>
|
4627 |
<body>
|
| 4515 |
<div>
|
4628 |
<div>
|
| 4516 |
<p>Dear Customer,</p>
|
4629 |
<p>Dear Customer,</p>
|
| 4517 |
<p>
|
4630 |
<p>
|
| 4518 |
We are pleased to inform that we have shipped the order: $order_id for your product $product_name on $shipping_datetime.
|
4631 |
We are pleased to inform that the following items in your order: -$master_order_id have been Shipped.
|
| - |
|
4632 |
Details of your shipment:
|
| - |
|
4633 |
<br>
|
| - |
|
4634 |
<br>
|
| - |
|
4635 |
<div>
|
| - |
|
4636 |
<table>
|
| - |
|
4637 |
<tr><td colspan="8"><hr /></td></tr>
|
| - |
|
4638 |
<tr><td colspan="8" align="left"><b>Order Details</b></td></tr>
|
| - |
|
4639 |
<tr><td colspan="8"><hr /></td></tr>
|
| - |
|
4640 |
<tr>
|
| - |
|
4641 |
<th width="100">Sub Order Id</th>
|
| - |
|
4642 |
<th>Product Name</th>
|
| - |
|
4643 |
<th width="100">Quantity</th>
|
| - |
|
4644 |
<th width="100">Unit Price</th>
|
| - |
|
4645 |
<th width="100">Amount</th>
|
| - |
|
4646 |
<th width="100">Insurance Amount</th>
|
| - |
|
4647 |
<th width="100">OTG Covered</th>
|
| - |
|
4648 |
<th width="100">Freebie Item</th>
|
| - |
|
4649 |
</tr>"""
|
| - |
|
4650 |
|
| - |
|
4651 |
total_amount = 0.0
|
| - |
|
4652 |
advanceAmount = 0.0
|
| - |
|
4653 |
hasOtg = False
|
| - |
|
4654 |
hasFreebie = False
|
| - |
|
4655 |
hasSplitOrder = False
|
| - |
|
4656 |
hasInsurer = False
|
| - |
|
4657 |
splitOrdersMap = {}
|
| - |
|
4658 |
for orderObj in orderList:
|
| - |
|
4659 |
lineitem = orderObj.lineitems[0]
|
| - |
|
4660 |
lineitem_total_price = round(lineitem.total_price, 2)
|
| - |
|
4661 |
total_amount += lineitem_total_price
|
| - |
|
4662 |
advanceAmount += orderObj.advanceAmount
|
| - |
|
4663 |
html += """
|
| - |
|
4664 |
<tr>
|
| - |
|
4665 |
<td align="center">"""+str(orderObj.id)+"""</td>
|
| - |
|
4666 |
<td>"""+str(lineitem)+"""</td>
|
| - |
|
4667 |
<td align="center">"""+("%.0f" % lineitem.quantity)+"""</td>
|
| - |
|
4668 |
<td align="center">"""+("%.2f" % lineitem.unit_price)+"""</td>
|
| - |
|
4669 |
<td align="center">"""+("%.2f" % lineitem_total_price)+"""</td>"""
|
| - |
|
4670 |
if orderObj.insurer > 0:
|
| - |
|
4671 |
hasInsurer = True
|
| - |
|
4672 |
total_amount += orderObj.insuranceAmount
|
| - |
|
4673 |
html += """<td align="center">"""+("%.2f" % orderObj.insuranceAmount) +"""</td>"""
|
| - |
|
4674 |
else:
|
| - |
|
4675 |
html += """<td align="center">0.00</td>"""
|
| - |
|
4676 |
if orderObj.freebieItemId:
|
| - |
|
4677 |
hasFreebie = True
|
| - |
|
4678 |
catalog_client = CatalogClient().get_client()
|
| - |
|
4679 |
item = catalog_client.getItem(order.freebieItemId)
|
| - |
|
4680 |
html += """<td align="center">"""+item.brand+" "+item.model_name+ " " + item.model_number +"""</td>"""
|
| - |
|
4681 |
else:
|
| - |
|
4682 |
html += """<td align="center"></td>"""
|
| - |
|
4683 |
freebieOrderId = get_order_attribute_value(orderObj.id, "freebieOrderId")
|
| - |
|
4684 |
if freebieOrderId != "":
|
| - |
|
4685 |
freebieOrder = get_order(freebieOrderId)
|
| - |
|
4686 |
hasSplitOrder = True
|
| - |
|
4687 |
splitOrdersMap[orderObj.id] = freebieOrder
|
| - |
|
4688 |
if orderObj.otg:
|
| - |
|
4689 |
hasOtg = True
|
| - |
|
4690 |
html += """<td align="center">Yes</td>"""
|
| - |
|
4691 |
else:
|
| - |
|
4692 |
html += """<td align="center">No</td>"""
|
| - |
|
4693 |
|
| - |
|
4694 |
html += """
|
| - |
|
4695 |
</tr>
|
| - |
|
4696 |
"""
|
| - |
|
4697 |
|
| - |
|
4698 |
html += """
|
| - |
|
4699 |
<tr><td colspan=8> </td></tr>
|
| - |
|
4700 |
<tr><td colspan=8><hr /></td></tr>"""
|
| - |
|
4701 |
|
| - |
|
4702 |
amount_string = "Total Amount"
|
| - |
|
4703 |
if advanceAmount > 0:
|
| - |
|
4704 |
html += """<tr>
|
| - |
|
4705 |
<td colspan="7">Advance Amount</td>
|
| - |
|
4706 |
<td>Rs."""+("%.2f" % advanceAmount)+"""
|
| - |
|
4707 |
</tr>
|
| - |
|
4708 |
"""
|
| - |
|
4709 |
total_amount -= advanceAmount
|
| - |
|
4710 |
amount_string = "Balance Amount"
|
| - |
|
4711 |
html += """<tr>
|
| - |
|
4712 |
<td colspan="7">"""+amount_string+"""</td>
|
| - |
|
4713 |
<td>Rs."""+("%.2f" % total_amount)+"""
|
| - |
|
4714 |
</tr>
|
| - |
|
4715 |
"""
|
| - |
|
4716 |
|
| - |
|
4717 |
|
| - |
|
4718 |
html += """
|
| - |
|
4719 |
</table>
|
| - |
|
4720 |
</div>
|
| 4519 |
The shipment will be delivered to you via $courier_name Courier Service vide AWB# $awb.
|
4721 |
The shipment will be delivered to you via $courier_name Courier Service vide AWB# $awb.
|
| 4520 |
|
4722 |
|
| 4521 |
</p>
|
4723 |
</p>
|
| 4522 |
<p>
|
4724 |
<p>
|
| 4523 |
Expected delivery date for your order is $expected_delivery_date.
|
4725 |
Expected delivery date for your order is $expected_delivery_date.
|
| Line 4546... |
Line 4748... |
| 4546 |
|
4748 |
|
| 4547 |
lclient = LogisticsClient().get_client()
|
4749 |
lclient = LogisticsClient().get_client()
|
| 4548 |
logistics_info = lclient.getLogisticsEstimation(order.lineitems[0].item_id, order.customer_pincode, DeliveryType.PREPAID)
|
4750 |
logistics_info = lclient.getLogisticsEstimation(order.lineitems[0].item_id, order.customer_pincode, DeliveryType.PREPAID)
|
| 4549 |
dt = datetime.datetime.strptime(str(order.shipping_timestamp), "%Y-%m-%d %H:%M:%S")
|
4751 |
dt = datetime.datetime.strptime(str(order.shipping_timestamp), "%Y-%m-%d %H:%M:%S")
|
| 4550 |
shipping_date = dt.strftime("%A, %d %B %Y %I:%M%p")
|
4752 |
shipping_date = dt.strftime("%A, %d %B %Y %I:%M%p")
|
| 4551 |
product = str(order.lineitems[0])
|
- |
|
| 4552 |
new_expected_delivery_timestamp = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), (logistics_info.deliveryTime - logistics_info.shippingTime)))
|
4753 |
new_expected_delivery_timestamp = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), (logistics_info.deliveryTime - logistics_info.shippingTime)))
|
| 4553 |
if order.source ==6:
|
4754 |
if order.source ==6:
|
| 4554 |
new_expected_delivery_timestamp = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), 3))
|
4755 |
new_expected_delivery_timestamp = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), 3))
|
| 4555 |
new_courier_delivery_time = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), (logistics_info.deliveryTime - logistics_info.shippingTime - logistics_info.deliveryDelay)))
|
4756 |
new_courier_delivery_time = datetime.datetime.now() + timedelta(adjust_delivery_time(datetime.datetime.now(), (logistics_info.deliveryTime - logistics_info.shippingTime - logistics_info.deliveryDelay)))
|
| 4556 |
#update new expected timestamp
|
4757 |
#update new expected timestamp
|
| - |
|
4758 |
|
| - |
|
4759 |
for orderObj in orderList:
|
| 4557 |
if order.cod:
|
4760 |
if orderObj.cod:
|
| 4558 |
new_expected_delivery_timestamp = new_expected_delivery_timestamp.replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
4761 |
new_expected_delivery_timestamp = new_expected_delivery_timestamp.replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
| 4559 |
order.courier_delivery_time = new_courier_delivery_time.replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
4762 |
orderObj.courier_delivery_time = new_courier_delivery_time.replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
| 4560 |
else:
|
4763 |
else:
|
| 4561 |
new_expected_delivery_timestamp = new_expected_delivery_timestamp.replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
4764 |
new_expected_delivery_timestamp = new_expected_delivery_timestamp.replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
| 4562 |
order.courier_delivery_time = new_courier_delivery_time.replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
4765 |
orderObj.courier_delivery_time = new_courier_delivery_time.replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0, microsecond=0)
|
| 4563 |
order.expected_delivery_time = new_expected_delivery_timestamp
|
4766 |
orderObj.expected_delivery_time = new_expected_delivery_timestamp
|
| 4564 |
session.commit()
|
4767 |
session.commit()
|
| 4565 |
|
4768 |
|
| 4566 |
new_expected_delivery_date = new_expected_delivery_timestamp.strftime("%A, %d %B %Y")
|
4769 |
new_expected_delivery_date = new_expected_delivery_timestamp.strftime("%A, %d %B %Y")
|
| 4567 |
otg_text = ""
|
4770 |
otg_text = ""
|
| 4568 |
if order.otg:
|
4771 |
if hasOtg:
|
| 4569 |
promised_delivery_date = order.promised_delivery_time.strftime("%A, %d %B %Y")
|
4772 |
promised_delivery_date = order.promised_delivery_time.strftime("%A, %d %B %Y")
|
| 4570 |
if new_expected_delivery_timestamp > order.promised_delivery_time:
|
4773 |
if new_expected_delivery_timestamp > order.promised_delivery_time:
|
| 4571 |
otg_text = 'Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> We apologize in advance for the expected delay from our initial promised delivery date of ' + promised_delivery_date + '. Your will receive a Gift Voucher Code at time of delivery based on the actual delay. You can use the same to buy any Mobile, Camera, Laptop, Tablet, Accessory or Mobile/DTH Recharge from our website.'
|
4774 |
otg_text = 'Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> We apologize in advance for the expected delay from our initial promised delivery date of ' + promised_delivery_date + '. Your will receive a Gift Voucher Code at time of delivery based on the actual delay. You can use the same to buy any Mobile, Camera, Laptop, Tablet, Accessory or Mobile/DTH Recharge from our website.'
|
| 4572 |
elif new_expected_delivery_timestamp < order.promised_delivery_time:
|
4775 |
elif new_expected_delivery_timestamp < order.promised_delivery_time:
|
| 4573 |
otg_text = 'We are happy to inform you that we expect to deliver your order before time. Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> Please note, compensation for delay (If Any) will be computed from the initial promised delivery date of ' + promised_delivery_date + '.'
|
4776 |
otg_text = 'We are happy to inform you that we expect to deliver your order before time. Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> Please note, compensation for delay (If Any) will be computed from the initial promised delivery date of ' + promised_delivery_date + '.'
|
| 4574 |
else:
|
4777 |
else:
|
| 4575 |
otg_text = 'Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> We are committed to deliver your order by our initial promised delivery date of ' + promised_delivery_date + '.'
|
4778 |
otg_text = 'Your order is covered under our <a href="http://www.saholic.com/static/on-time-guarantee">On Time Guarantee; We Pay if we Delay.</a> We are committed to deliver your order by our initial promised delivery date of ' + promised_delivery_date + '.'
|
| 4576 |
|
4779 |
|
| 4577 |
freebie_text = "<br/>"
|
4780 |
freebie_text = "<br/>"
|
| 4578 |
if order.freebieItemId:
|
4781 |
if hasFreebie and not hasSplitOrder:
|
| 4579 |
catalog_client = CatalogClient().get_client()
|
4782 |
freebie_text = freebie_text + "We have also shipped your freebies with eligible products as promised<br/>"
|
| 4580 |
item = catalog_client.getItem(order.freebieItemId)
|
4783 |
elif not hasFreebie and hasSplitOrder:
|
| 4581 |
freebie_text = freebie_text = "We have also shipped you " + item.brand + " " + item.modelName + "" + item.modelNumber +" as promised<br/>"
|
4784 |
freebie_text = freebie_text + "We wish to inform you that your freebie item(s): <br/>"
|
| 4582 |
else:
|
4785 |
for splitOrder in splitOrdersMap.values():
|
| 4583 |
freebie_orderId = get_order_attribute_value(order.id, "freebieOrderId")
|
4786 |
freebieLineItem = get_line_items_for_order(splitOrder.id)[0]
|
| 4584 |
if freebie_orderId != "":
|
4787 |
freebie_text = freebie_text + freebieLineItem.brand + " " + freebieLineItem.model_name + " " + freebieLineItem.model_number + " will be sent as a separate order with OrderId : " + str(splitOrder.id) + " and is expected to be delivered on " + splitOrder.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>"
|
| - |
|
4788 |
elif hasFreebie and hasSplitOrder:
|
| - |
|
4789 |
freebie_text = freebie_text + "We have also shipped some of your freebies with eligible products as promised and rest freebie item(s) details are given below: <br/>"
|
| 4585 |
line_items = get_line_items_for_order(int(freebie_orderId))
|
4790 |
for splitOrder in splitOrdersMap.values():
|
| 4586 |
freebie_order = get_order(int(freebie_orderId))
|
4791 |
freebieLineItem = get_line_items_for_order(splitOrder.id)[0]
|
| 4587 |
freebie_text = freebie_text + "We wish to inform you that your freebie item " +line_items[0].brand + " " + line_items[0].model_name + " " + line_items[0].model_number + " will be sent as a separate order with OrderId : " + freebie_orderId + " and is expected to be delivered on " + freebie_order.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>"
|
4792 |
freebie_text = freebie_text + freebieLineItem.brand + " " + freebieLineItem.model_name + " " + freebieLineItem.model_number + " will be sent as a separate order with OrderId : " + str(splitOrder.id) + " and is expected to be delivered on " + splitOrder.expected_delivery_time.strftime("%A, %d %B %Y")+ "<br/>"
|
| 4588 |
else:
|
4793 |
else:
|
| 4589 |
freebie_text = ""
|
4794 |
freebie_text = ""
|
| 4590 |
|
4795 |
|
| 4591 |
info = dict(order_id = order.id, product_name = product, shipping_datetime = shipping_date, awb = order.airwaybill_no, expected_delivery_date = new_expected_delivery_date, courier_name = provider_name, courier_phone = provider_phone, source_name = source_name, otg_text = otg_text, freebie_text = freebie_text)
|
4796 |
info = dict(master_order_id = logisticsTxnId, shipping_datetime = shipping_date, awb = order.airwaybill_no, expected_delivery_date = new_expected_delivery_date, courier_name = provider_name, courier_phone = provider_phone, source_name = source_name, otg_text = otg_text, freebie_text = freebie_text)
|
| 4592 |
return Template(html).substitute(info)
|
4797 |
return Template(html).substitute(info)
|
| 4593 |
|
4798 |
|
| 4594 |
def enqueue_shipping_confirmation_email(order):
|
4799 |
def enqueue_shipping_confirmation_email(logisticsTxnId, orderList):
|
| 4595 |
# Calling helper service on production
|
4800 |
# Calling helper service on production
|
| - |
|
4801 |
order = orderList[0]
|
| 4596 |
helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
4802 |
helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
| 4597 |
try:
|
4803 |
try:
|
| 4598 |
emailSubject = 'Shipping Details for Order ID: ' + str(order.id)
|
4804 |
emailSubject = 'Shipping Details for Master Order ID: ' + logisticsTxnId
|
| 4599 |
emailBody = get_shipping_confirmation_email_body(order)
|
4805 |
emailBody = get_shipping_confirmation_email_body(logisticsTxnId, orderList)
|
| 4600 |
helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, str(order.id), 'ShippingConfirmation', [], [], order.source)
|
4806 |
helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, logisticsTxnId, 'ShippingConfirmation', [], [], order.source)
|
| 4601 |
|
4807 |
|
| 4602 |
logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 6: {'name': 'RedExpress', 'phone': '8373915813'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}, 7: {'name': 'FedEx', 'phone' : '0120-4354176'}}
|
4808 |
logistics_providers = {1: {'name': 'BlueDart', 'phone': '011-66111234'}, 6: {'name': 'RedExpress', 'phone': '8373915813'}, 3: {'name': 'Delhivery', 'phone' : '0124- 4212200'}, 7: {'name': 'FedEx', 'phone' : '0120-4354176'}}
|
| 4603 |
provider_name = logistics_providers[order.logistics_provider_id]['name']
|
4809 |
provider_name = logistics_providers[order.logistics_provider_id]['name']
|
| 4604 |
if order.source == OrderSource.WEBSITE :
|
4810 |
if order.source == OrderSource.WEBSITE :
|
| 4605 |
send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, We have shipped your order: " + str(order.id) + " through "+provider_name + " AWB No. " + order.airwaybill_no, SmsType.TRANSACTIONAL)
|
4811 |
send_transaction_sms(order.customer_id, order.customer_mobilenumber, "Dear Customer, We have shipped your order: " + logisticsTxnId + " through "+provider_name + " AWB No. " + order.airwaybill_no, SmsType.TRANSACTIONAL)
|
| 4606 |
except Exception as e:
|
4812 |
except Exception as e:
|
| 4607 |
print e
|
4813 |
print e
|
| 4608 |
|
4814 |
|
| 4609 |
def get_order_distribution_by_status(start_date, end_date):
|
4815 |
def get_order_distribution_by_status(start_date, end_date):
|
| 4610 |
query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
|
4816 |
query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
|