| Line 4... |
Line 4... |
| 4 |
@author: Chandranshu
|
4 |
@author: Chandranshu
|
| 5 |
'''
|
5 |
'''
|
| 6 |
|
6 |
|
| 7 |
from datetime import date, timedelta
|
7 |
from datetime import date, timedelta
|
| 8 |
from elixir import *
|
8 |
from elixir import *
|
| 9 |
from random import randrange
|
- |
|
| 10 |
from reportlab.lib.units import inch
|
9 |
from reportlab.lib.units import inch
|
| 11 |
from reportlab.pdfgen.canvas import Canvas
|
10 |
from reportlab.pdfgen.canvas import Canvas
|
| 12 |
from reportlab.rl_config import defaultPageSize
|
11 |
from reportlab.rl_config import defaultPageSize
|
| 13 |
from shop2020.clients.AlertClient import AlertClient
|
- |
|
| 14 |
from shop2020.clients.CatalogClient import CatalogClient
|
12 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 15 |
from shop2020.clients.HelperClient import HelperClient
|
13 |
from shop2020.clients.HelperClient import HelperClient
|
| 16 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
14 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 17 |
from shop2020.clients.PaymentClient import PaymentClient
|
15 |
from shop2020.clients.PaymentClient import PaymentClient
|
| 18 |
from shop2020.clients.UserClient import UserClient
|
16 |
from shop2020.clients.UserClient import UserClient
|
| Line 20... |
Line 18... |
| 20 |
from shop2020.model.v1 import order
|
18 |
from shop2020.model.v1 import order
|
| 21 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
19 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
| 22 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
20 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
| 23 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
| 24 |
CodVerificationAgent, Attribute, RechargeVoucherTracker
|
22 |
CodVerificationAgent, Attribute, RechargeVoucherTracker
|
| - |
|
23 |
|
| 25 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 26 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
- |
|
| 27 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
| - |
|
26 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
| 28 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
27 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
| 29 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
28 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 30 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
29 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
| 31 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
30 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 32 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
31 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 33 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
|
32 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
|
| 34 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
- |
|
| 35 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
33 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 36 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
34 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
| 37 |
WarehouseServiceException
|
35 |
WarehouseServiceException
|
| 38 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
36 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part,\
|
| - |
|
37 |
mail_html
|
| 39 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
38 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 40 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
39 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| 41 |
from sqlalchemy.sql import func
|
40 |
from sqlalchemy.sql import func
|
| 42 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, select
|
41 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, select
|
| 43 |
from string import Template
|
42 |
from string import Template
|
| Line 46... |
Line 45... |
| 46 |
import logging
|
45 |
import logging
|
| 47 |
import os
|
46 |
import os
|
| 48 |
import sys
|
47 |
import sys
|
| 49 |
import time
|
48 |
import time
|
| 50 |
import traceback
|
49 |
import traceback
|
| 51 |
|
- |
|
| - |
|
50 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
| - |
|
51 |
from random import randrange
|
| - |
|
52 |
from shop2020.clients.AlertClient import AlertClient
|
| 52 |
logging.basicConfig(level=logging.DEBUG)
|
53 |
logging.basicConfig(level=logging.DEBUG)
|
| 53 |
|
54 |
|
| 54 |
|
55 |
|
| 55 |
PREPAID_SHIPPING_CUTOFF_TIME = 15
|
56 |
PREPAID_SHIPPING_CUTOFF_TIME = 15
|
| 56 |
COD_SHIPPING_CUTOFF_TIME = 12
|
57 |
COD_SHIPPING_CUTOFF_TIME = 12
|
| Line 206... |
Line 207... |
| 206 |
## Assign runner in case of delhi pincodes
|
207 |
## Assign runner in case of delhi pincodes
|
| 207 |
if transaction.orders[0].pickupStoreId:
|
208 |
if transaction.orders[0].pickupStoreId:
|
| 208 |
logistics_client = LogisticsClient().get_client()
|
209 |
logistics_client = LogisticsClient().get_client()
|
| 209 |
store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
|
210 |
store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
|
| 210 |
if delhi_pincodes.__contains__(store.pin):
|
211 |
if delhi_pincodes.__contains__(store.pin):
|
| 211 |
pickUp = PickUpType.RUNNER
|
212 |
pickUp = PickUpType.RUNNER
|
| 212 |
|
213 |
|
| 213 |
if new_status == TransactionStatus.FAILED:
|
214 |
if new_status == TransactionStatus.FAILED:
|
| 214 |
for order in transaction.orders:
|
215 |
for order in transaction.orders:
|
| 215 |
order.status = OrderStatus.PAYMENT_FAILED
|
216 |
order.status = OrderStatus.PAYMENT_FAILED
|
| 216 |
order.statusDescription = "Payment Failed"
|
217 |
order.statusDescription = "Payment Failed"
|
| Line 353... |
Line 354... |
| 353 |
|
354 |
|
| 354 |
return delivery_days
|
355 |
return delivery_days
|
| 355 |
|
356 |
|
| 356 |
def enqueue_transaction_info_email(transaction_id):
|
357 |
def enqueue_transaction_info_email(transaction_id):
|
| 357 |
transaction = get_transaction(transaction_id)
|
358 |
transaction = get_transaction(transaction_id)
|
| 358 |
|
359 |
customer_name = ""
|
| 359 |
html_header = """
|
360 |
html_header = """
|
| 360 |
<html>
|
361 |
<html>
|
| 361 |
<body>
|
362 |
<body>
|
| 362 |
<div>
|
363 |
<div>
|
| 363 |
<p>
|
364 |
<p>
|
| 364 |
Hello,<br /><br />
|
365 |
Hello $customer_name,<br /><br />
|
| 365 |
Thanks for placing order with us. Following are the details of your order:
|
366 |
Thanks for placing order with us. Following are the details of your order:
|
| 366 |
</p>
|
367 |
</p>
|
| 367 |
<div>
|
368 |
<div>
|
| 368 |
Order Date: $order_date
|
369 |
Order Date: $order_date
|
| 369 |
</div>
|
370 |
</div>
|
| Line 387... |
Line 388... |
| 387 |
|
388 |
|
| 388 |
orders = transaction.orders
|
389 |
orders = transaction.orders
|
| 389 |
html_pickup_text = ""
|
390 |
html_pickup_text = ""
|
| 390 |
random_text = ""
|
391 |
random_text = ""
|
| 391 |
if orders[0].pickupStoreId:
|
392 |
if orders[0].pickupStoreId:
|
| 392 |
random_text = str(randrange(100000, 999999))
|
393 |
random_text = str(randrange(100000, 999999))
|
| 393 |
html_pickup_text = "Secret code for your order is " + random_text + ". Please tell store manager this secret code to get the order. "
|
- |
|
| 394 |
|
394 |
|
| 395 |
for order in orders:
|
395 |
for order in orders:
|
| - |
|
396 |
customer_name = order.customer_name
|
| 396 |
order_date = order.created_timestamp
|
397 |
order_date = order.created_timestamp
|
| 397 |
user_email = order.customer_email
|
398 |
user_email = order.customer_email
|
| 398 |
html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
|
399 |
html_tr = "<tr><td align='center'>" + str(order.id) + "</td>"
|
| 399 |
|
400 |
|
| 400 |
if order.pickupStoreId:
|
401 |
if order.pickupStoreId:
|
| Line 422... |
Line 423... |
| 422 |
<td> Rs. $total_amount</td>
|
423 |
<td> Rs. $total_amount</td>
|
| 423 |
</tr>
|
424 |
</tr>
|
| 424 |
</table>
|
425 |
</table>
|
| 425 |
</div>
|
426 |
</div>
|
| 426 |
"""
|
427 |
"""
|
| - |
|
428 |
|
| - |
|
429 |
store_address = ""
|
| - |
|
430 |
if orders[0].pickupStoreId:
|
| - |
|
431 |
store = LogisticsClient().get_client().getPickupStore(orders[0].pickupStoreId)
|
| - |
|
432 |
store_address = __get_store_address_html(store)
|
| - |
|
433 |
|
| - |
|
434 |
html_pickup_text = html_pickup_text + """
|
| - |
|
435 |
<h3>Steps to Pickup In Store</h3>
|
| - |
|
436 |
1) Estimated arrival date of your product(s) is $store_delivery_date at your selected Store.<br>
|
| - |
|
437 |
2) You will receive a confirmation email from us when your product(s) reaches the store. Once you receive the same, please visit the following store selected by you.<br>
|
| - |
|
438 |
<br><i>$store_address</i><br>
|
| - |
|
439 |
"""
|
| - |
|
440 |
|
| - |
|
441 |
if orders[0].cod:
|
| - |
|
442 |
html_pickup_text = html_pickup_text + """
|
| - |
|
443 |
3) Pay Rs. $total_amount, present a valid Photo Identity Proof* and use your Secret Code <b><i>$secret_code</i></b> to claim your Product(s).<br><br>
|
| - |
|
444 |
*Valid Photo Identity Proof are Driving License, Passport, PAN Card, Voter ID, Company Issued ID Card, College issued Student ID Card Or any other Government approved Photo Id.<br>
|
| - |
|
445 |
<br>
|
| - |
|
446 |
In case you have any questions please visit <a href="www.saholic.com/static/buy-online-and-pickup-in-store">Details on Pickup in Store</a>. If you still have more questions feel free to contact us 24/7 via <a href="http://www.saholic.com/contact-us">http://www.saholic.com/contact-us</a>
|
| - |
|
447 |
</br><hr />
|
| - |
|
448 |
"""
|
| - |
|
449 |
else:
|
| - |
|
450 |
html_pickup_text = html_pickup_text + """
|
| - |
|
451 |
3) Present a valid Photo Identity Proof* and use your Secret Code <b><i>$secret_code</i></b> to claim your Product(s).<br><br>
|
| - |
|
452 |
*Valid Photo Identity Proof are Driving License, Passport, PAN Card, Voter ID, Company Issued ID Card, College issued Student ID Card Or any other Government approved Photo Id.<br>
|
| - |
|
453 |
<br>
|
| - |
|
454 |
In case you have any questions please visit <a href="www.saholic.com/static/buy-online-pickup-in-store">Details on Pickup in Store</a>. If you still have more questions feel free to contact us 24/7 via <a href="http://www.saholic.com/contact-us">http://www.saholic.com/contact-us</a>
|
| - |
|
455 |
</br><hr />
|
| - |
|
456 |
"""
|
| - |
|
457 |
|
| 427 |
html_footer = html_footer + html_pickup_text + """
|
458 |
html_footer = html_footer + html_pickup_text + """
|
| 428 |
<p>
|
459 |
<p>
|
| 429 |
Best Wishes,<br />
|
460 |
Best Wishes,<br />
|
| 430 |
Saholic Team
|
461 |
Saholic Team
|
| 431 |
</p>
|
462 |
</p>
|
| Line 434... |
Line 465... |
| 434 |
</html>
|
465 |
</html>
|
| 435 |
"""
|
466 |
"""
|
| 436 |
|
467 |
|
| 437 |
dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
|
468 |
dt = datetime.datetime.strptime(str(order_date), "%Y-%m-%d %H:%M:%S")
|
| 438 |
formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
469 |
formated_order_date = dt.strftime("%A, %d. %B %Y %I:%M%p")
|
| - |
|
470 |
|
| - |
|
471 |
sdt = datetime.datetime.strptime(str(orders[0].expected_delivery_time), "%Y-%m-%d %H:%M:%S")
|
| - |
|
472 |
store_delivery_date = sdt.strftime("%A, %d %B %Y")
|
| 439 |
|
473 |
|
| 440 |
email_header = Template(html_header).substitute(dict(order_date = formated_order_date))
|
474 |
email_header = Template(html_header).substitute(dict(order_date = formated_order_date, customer_name = customer_name))
|
| 441 |
email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount))
|
475 |
email_footer = Template(html_footer).substitute(dict(total_amount = "%.2f" % total_amount, secret_code = random_text, store_address = store_address, store_delivery_date = store_delivery_date))
|
| 442 |
|
476 |
|
| 443 |
try:
|
477 |
try:
|
| 444 |
helper_client = HelperClient().get_client()
|
478 |
helper_client = HelperClient().get_client()
|
| 445 |
helper_client.saveUserEmailForSending(user_email, "", "Saholic - Order Details", email_header + html_table + email_footer, str(transaction_id), "TransactionInfo")
|
479 |
helper_client.saveUserEmailForSending(user_email, "", "Saholic - Order Details", email_header + html_table + email_footer, str(transaction_id), "TransactionInfo")
|
| 446 |
return True
|
480 |
return True
|
| Line 857... |
Line 891... |
| 857 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
891 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 858 |
monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = " + str(order.id);
|
892 |
monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = " + str(order.id);
|
| 859 |
alert_client = AlertClient().get_client()
|
893 |
alert_client = AlertClient().get_client()
|
| 860 |
alert_client.scheduleAlert(monitoredEntity)
|
894 |
alert_client.scheduleAlert(monitoredEntity)
|
| 861 |
except Exception as e:
|
895 |
except Exception as e:
|
| 862 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
- |
|
| 863 |
print e
|
896 |
print e
|
| 864 |
session.commit()
|
897 |
session.commit()
|
| 865 |
|
898 |
|
| 866 |
try:
|
899 |
try:
|
| 867 |
enqueue_shipping_confirmation_email(orders)
|
900 |
enqueue_shipping_confirmation_email(orders)
|
| Line 929... |
Line 962... |
| 929 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
962 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 930 |
monitoredEntity.description="providerId = " + str(provider_id) + " " + pickup_details
|
963 |
monitoredEntity.description="providerId = " + str(provider_id) + " " + pickup_details
|
| 931 |
alert_client = AlertClient().get_client()
|
964 |
alert_client = AlertClient().get_client()
|
| 932 |
alert_client.updateMonitoredObject(monitoredEntity)
|
965 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 933 |
except Exception as e:
|
966 |
except Exception as e:
|
| 934 |
print "Exception in updating alert in MarkOrdersAsPickedUp method"
|
- |
|
| 935 |
print e
|
967 |
print e
|
| 936 |
session.commit()
|
968 |
session.commit()
|
| 937 |
|
969 |
|
| 938 |
def get_orders_not_picked_up(provider_id):
|
970 |
def get_orders_not_picked_up(provider_id):
|
| 939 |
current_time = datetime.datetime.now()
|
971 |
current_time = datetime.datetime.now()
|
| Line 962... |
Line 994... |
| 962 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
994 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 963 |
monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = " + str(order.id);
|
995 |
monitoredEntity.description="deliveryTimeAtStore = " + str(order.delivery_timestamp) + " orderId = " + str(order.id);
|
| 964 |
alert_client = AlertClient().get_client()
|
996 |
alert_client = AlertClient().get_client()
|
| 965 |
alert_client.updateMonitoredObject(monitoredEntity)
|
997 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 966 |
except Exception as e:
|
998 |
except Exception as e:
|
| 967 |
print "Exception in updating alert in MarkOrdersAsDelivered method"
|
- |
|
| 968 |
print e
|
999 |
print e
|
| 969 |
else:
|
1000 |
else:
|
| 970 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
1001 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
| 971 |
order.statusDescription = "Order delivered"
|
1002 |
order.statusDescription = "Order delivered"
|
| 972 |
update_trust_level(order)
|
1003 |
update_trust_level(order)
|
| 973 |
try:
|
1004 |
try:
|
| 974 |
alert_client = AlertClient().get_client()
|
1005 |
alert_client = AlertClient().get_client()
|
| 975 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
1006 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 976 |
except Exception as e:
|
1007 |
except Exception as e:
|
| 977 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
- |
|
| 978 |
print e
|
1008 |
print e
|
| 979 |
timestamp, receiver = detail.split('|')
|
1009 |
timestamp, receiver = detail.split('|')
|
| 980 |
if order.first_dlvyatmp_timestamp is None:
|
1010 |
if order.first_dlvyatmp_timestamp is None:
|
| 981 |
order.first_dlvyatmp_timestamp = timestamp
|
1011 |
order.first_dlvyatmp_timestamp = timestamp
|
| 982 |
order.delivery_timestamp = timestamp
|
1012 |
order.delivery_timestamp = timestamp
|
| Line 1011... |
Line 1041... |
| 1011 |
|
1041 |
|
| 1012 |
try:
|
1042 |
try:
|
| 1013 |
alert_client = AlertClient().get_client()
|
1043 |
alert_client = AlertClient().get_client()
|
| 1014 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
1044 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 1015 |
except Exception as e:
|
1045 |
except Exception as e:
|
| 1016 |
print "Exception in ending alert in MarkOrderAsDelivered method"
|
- |
|
| 1017 |
print e
|
1046 |
print e
|
| 1018 |
|
1047 |
|
| 1019 |
|
1048 |
|
| 1020 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
1049 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
| 1021 |
order = Order.get_by(id=orderId)
|
1050 |
order = Order.get_by(id=orderId)
|
| Line 1094... |
Line 1123... |
| 1094 |
order.statusDescription = "Order Returned to Origin:" + reason
|
1123 |
order.statusDescription = "Order Returned to Origin:" + reason
|
| 1095 |
update_trust_level(order)
|
1124 |
update_trust_level(order)
|
| 1096 |
session.commit()
|
1125 |
session.commit()
|
| 1097 |
try:
|
1126 |
try:
|
| 1098 |
alert_client = AlertClient().get_client()
|
1127 |
alert_client = AlertClient().get_client()
|
| 1099 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
1128 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
|
| 1100 |
except Exception as e:
|
1129 |
except Exception as e:
|
| 1101 |
print "Exception in ending alert in MarkOrderAsRTO method"
|
- |
|
| 1102 |
print e
|
1130 |
print e
|
| 1103 |
|
1131 |
|
| 1104 |
def get_rto_orders(provider_id):
|
1132 |
def get_rto_orders(provider_id):
|
| 1105 |
current_time = datetime.datetime.now()
|
1133 |
current_time = datetime.datetime.now()
|
| 1106 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1134 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| Line 1157... |
Line 1185... |
| 1157 |
monitoredEntity = MonitoredEntity();
|
1185 |
monitoredEntity = MonitoredEntity();
|
| 1158 |
monitoredEntity.entityType=EntityType.COURIER;
|
1186 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 1159 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
1187 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
| 1160 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
1188 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 1161 |
#Warn alert time is taken as 23 hrs less than promised delivery time
|
1189 |
#Warn alert time is taken as 23 hrs less than promised delivery time
|
| 1162 |
warn_time = (order.expected_delivery_time-timedelta(hours = 23))
|
1190 |
warn_time = (order.expected_delivery_time-23*3600*1000)
|
| 1163 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
1191 |
#Critical alert time is taken as 13 hrs less than promised delivery time
|
| 1164 |
critical_time = (order.expected_delivery_time-timedelta(hours = 13))
|
1192 |
critical_time = (order.expected_delivery_time-13*3600*1000)
|
| 1165 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
1193 |
monitoredEntity.warnExpiryTime = warn_time
|
| 1166 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
1194 |
monitoredEntity.criticalExpiryTime = critical_time
|
| 1167 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
1195 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| 1168 |
alert_client = AlertClient().get_client()
|
1196 |
alert_client = AlertClient().get_client()
|
| 1169 |
alert_client.updateMonitoredObject(monitoredEntity)
|
1197 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 1170 |
except Exception as e:
|
1198 |
except Exception as e:
|
| 1171 |
print "Exception in updating alert in MarkOrderAsLocalConnected method"
|
- |
|
| 1172 |
print e
|
1199 |
print e
|
| 1173 |
session.commit()
|
1200 |
session.commit()
|
| 1174 |
|
1201 |
|
| 1175 |
def get_orders_not_local_connected(provider_id):
|
1202 |
def get_orders_not_local_connected(provider_id):
|
| 1176 |
current_time = datetime.datetime.now()
|
1203 |
current_time = datetime.datetime.now()
|
| Line 1191... |
Line 1218... |
| 1191 |
monitoredEntity = MonitoredEntity();
|
1218 |
monitoredEntity = MonitoredEntity();
|
| 1192 |
monitoredEntity.entityType=EntityType.COURIER;
|
1219 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 1193 |
monitoredEntity.eventType=OrderStatus.REACHED_DESTINATION_CITY
|
1220 |
monitoredEntity.eventType=OrderStatus.REACHED_DESTINATION_CITY
|
| 1194 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
1221 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 1195 |
warn_time = (order.expected_delivery_time)
|
1222 |
warn_time = (order.expected_delivery_time)
|
| 1196 |
critical_time = (order.expected_delivery_time + timedelta(hours=12))
|
1223 |
critical_time = (order.expected_delivery_time+12*3600*1000)
|
| 1197 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
1224 |
monitoredEntity.warnExpiryTime = warn_time
|
| 1198 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
1225 |
monitoredEntity.criticalExpiryTime = critical_time
|
| 1199 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
1226 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| 1200 |
alert_client = AlertClient().get_client()
|
1227 |
alert_client = AlertClient().get_client()
|
| 1201 |
alert_client.updateMonitoredObject(monitoredEntity)
|
1228 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 1202 |
except Exception as e:
|
1229 |
except Exception as e:
|
| 1203 |
print "Exception in updating alert in MarkOrderAsDestCityReached method"
|
- |
|
| 1204 |
print e
|
1230 |
print e
|
| 1205 |
session.commit()
|
1231 |
session.commit()
|
| 1206 |
|
1232 |
|
| 1207 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
1233 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
| 1208 |
for awb, detail in first_atdl_orders.iteritems():
|
1234 |
for awb, detail in first_atdl_orders.iteritems():
|
| Line 1229... |
Line 1255... |
| 1229 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
1255 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 1230 |
monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
|
1256 |
monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
|
| 1231 |
alert_client = AlertClient().get_client()
|
1257 |
alert_client = AlertClient().get_client()
|
| 1232 |
alert_client.updateMonitoredObject(monitoredEntity)
|
1258 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| 1233 |
except Exception as e:
|
1259 |
except Exception as e:
|
| 1234 |
print "Exception in updating alert in MarkOrdersAsFirstDeliveryAttempted method"
|
- |
|
| 1235 |
print e
|
1260 |
print e
|
| 1236 |
session.commit()
|
1261 |
session.commit()
|
| 1237 |
|
1262 |
|
| 1238 |
def get_orders_not_met_expected_delivery_date():
|
1263 |
def get_orders_not_met_expected_delivery_date():
|
| 1239 |
current_time = datetime.datetime.now()
|
1264 |
current_time = datetime.datetime.now()
|
| Line 2045... |
Line 2070... |
| 2045 |
if store.line2:
|
2070 |
if store.line2:
|
| 2046 |
address = address + store.line2 + "\n"
|
2071 |
address = address + store.line2 + "\n"
|
| 2047 |
address = address + store.city + "\n"
|
2072 |
address = address + store.city + "\n"
|
| 2048 |
address = address + store.state + "\n"
|
2073 |
address = address + store.state + "\n"
|
| 2049 |
address = address + "PIN " + store.pin + "\n"
|
2074 |
address = address + "PIN " + store.pin + "\n"
|
| - |
|
2075 |
if store.phone:
|
| 2050 |
address = address + "Phone: " + store.phone
|
2076 |
address = address + "Phone: " + store.phone
|
| - |
|
2077 |
return address
|
| - |
|
2078 |
|
| - |
|
2079 |
def __get_store_address_html(store):
|
| - |
|
2080 |
address = store.name + "<br>" + store.line1 + "<br>"
|
| - |
|
2081 |
if store.line2:
|
| - |
|
2082 |
address = address + store.line2 + "<br>"
|
| - |
|
2083 |
address = address + store.city + "<br>"
|
| - |
|
2084 |
address = address + store.state + "<br>"
|
| - |
|
2085 |
address = address + "PIN " + store.pin + "<br>"
|
| - |
|
2086 |
if store.phone:
|
| - |
|
2087 |
address = address + "Phone: " + store.phone
|
| 2051 |
return address
|
2088 |
return address
|
| 2052 |
|
2089 |
|
| 2053 |
def __generate_return_advice(order, warehouse, provider, filename):
|
2090 |
def __generate_return_advice(order, warehouse, provider, filename):
|
| 2054 |
if warehouse.id == 7:
|
2091 |
if warehouse.id == 7:
|
| 2055 |
executive = 'Amit Kumar'
|
2092 |
executive = 'Amit Kumar'
|
| Line 2361... |
Line 2398... |
| 2361 |
type = DeliveryType.PREPAID
|
2398 |
type = DeliveryType.PREPAID
|
| 2362 |
if order.cod:
|
2399 |
if order.cod:
|
| 2363 |
type = DeliveryType.COD
|
2400 |
type = DeliveryType.COD
|
| 2364 |
|
2401 |
|
| 2365 |
logistics_client = LogisticsClient().get_client()
|
2402 |
logistics_client = LogisticsClient().get_client()
|
| 2366 |
logistics_info = logistics_client.getLogisticsEstimation(order.lineitems[0].item_id, address.pin, type)
|
2403 |
logistics_info = logistics_client.getLogisticsEstimation(order.lineitems[0].item_id, address.pin, type, PickUpType.COURIER)
|
| 2367 |
|
2404 |
|
| 2368 |
# Check for new estimate. Raise exception if new address is not serviceable
|
2405 |
# Check for new estimate. Raise exception if new address is not serviceable
|
| 2369 |
if logistics_info.deliveryTime == -1:
|
2406 |
if logistics_info.deliveryTime == -1:
|
| 2370 |
raise TransactionServiceException(1, 'Location not serviceable')
|
2407 |
raise TransactionServiceException(1, 'Location not serviceable')
|
| 2371 |
|
2408 |
|
| Line 2373... |
Line 2410... |
| 2373 |
if order.cod:
|
2410 |
if order.cod:
|
| 2374 |
if not logistics_info.codAllowed:
|
2411 |
if not logistics_info.codAllowed:
|
| 2375 |
raise TransactionServiceException(2, 'COD service not available')
|
2412 |
raise TransactionServiceException(2, 'COD service not available')
|
| 2376 |
|
2413 |
|
| 2377 |
if logistics_info.providerId != order.logistics_provider_id:
|
2414 |
if logistics_info.providerId != order.logistics_provider_id:
|
| 2378 |
logistics_info = logistics_client.getLogisticsInfo(address.pin, order.lineitems[0].item_id, type, PickUpType.COURIER)
|
2415 |
logistics_info = logistics_client.getLogisticsInfo(address.pin, order.lineitems[0].item_id, type)
|
| 2379 |
order.tracking_id = logistics_info.airway_billno
|
2416 |
order.tracking_id = logistics_info.airway_billno
|
| 2380 |
order.airwaybill_no = logistics_info.airway_billno
|
2417 |
order.airwaybill_no = logistics_info.airway_billno
|
| 2381 |
order.logistics_provider_id = logistics_info.providerId
|
2418 |
order.logistics_provider_id = logistics_info.providerId
|
| 2382 |
|
2419 |
|
| 2383 |
current_time = datetime.datetime.now()
|
2420 |
current_time = datetime.datetime.now()
|