| Line 21... |
Line 21... |
| 21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
| 22 |
CodVerificationAgent, Attribute, RechargeVoucherTracker
|
22 |
CodVerificationAgent, Attribute, RechargeVoucherTracker
|
| 23 |
|
23 |
|
| 24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
| - |
|
26 |
from shop2020.thriftpy.alert.ttypes import MonitoredEntity, EntityType
|
| 26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
27 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
| 27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
28 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 28 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
29 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
| 29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
30 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
31 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| Line 44... |
Line 45... |
| 44 |
import os
|
45 |
import os
|
| 45 |
import sys
|
46 |
import sys
|
| 46 |
import time
|
47 |
import time
|
| 47 |
import traceback
|
48 |
import traceback
|
| 48 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
49 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
| - |
|
50 |
from shop2020.clients.AlertClient import AlertClient
|
| 49 |
logging.basicConfig(level=logging.DEBUG)
|
51 |
logging.basicConfig(level=logging.DEBUG)
|
| 50 |
|
52 |
|
| 51 |
|
53 |
|
| 52 |
PREPAID_SHIPPING_CUTOFF_TIME = 15
|
54 |
PREPAID_SHIPPING_CUTOFF_TIME = 15
|
| 53 |
COD_SHIPPING_CUTOFF_TIME = 12
|
55 |
COD_SHIPPING_CUTOFF_TIME = 12
|
| Line 721... |
Line 723... |
| 721 |
try:
|
723 |
try:
|
| 722 |
warehouse_client = WarehouseClient().get_client()
|
724 |
warehouse_client = WarehouseClient().get_client()
|
| 723 |
# Fetching GOOD w/h corresponding to the virtual one here
|
725 |
# Fetching GOOD w/h corresponding to the virtual one here
|
| 724 |
if warehouse.billingWarehouseId is None:
|
726 |
if warehouse.billingWarehouseId is None:
|
| 725 |
warehouse = catalog_client.getWarehouses(None, InventoryType.GOOD, warehouse.vendor.id, order.warehouse_id, 0)[0]
|
727 |
warehouse = catalog_client.getWarehouses(None, InventoryType.GOOD, warehouse.vendor.id, order.warehouse_id, 0)[0]
|
| - |
|
728 |
order.fulfilmentWarehouseId = warehouse.id
|
| 726 |
|
729 |
|
| 727 |
if ItemType.SERIALIZED == item.type:
|
730 |
if ItemType.SERIALIZED == item.type:
|
| 728 |
inventoryItem = warehouse_client.getInventoryItem(serialNumber)
|
731 |
inventoryItem = warehouse_client.getInventoryItem(serialNumber)
|
| 729 |
else:
|
732 |
else:
|
| 730 |
inventoryItem = warehouse_client.getNonSeralizedInventoryItem(itemNumbers[index], item_id, warehouse.id)
|
733 |
inventoryItem = warehouse_client.getNonSeralizedInventoryItem(itemNumbers[index], item_id, order.fulfilmentWarehouseId)
|
| 731 |
|
734 |
|
| 732 |
if (inventoryItem.itemId != item_id):
|
735 |
if (inventoryItem.itemId != item_id):
|
| 733 |
catalog_client = CatalogClient().get_client()
|
736 |
catalog_client = CatalogClient().get_client()
|
| 734 |
item = catalog_client.getItem(inventoryItem.itemId)
|
737 |
item = catalog_client.getItem(inventoryItem.itemId)
|
| 735 |
scanItemString = " ".join([str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
738 |
scanItemString = " ".join([str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
| 736 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
739 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
| 737 |
raise TransactionServiceException(110, 'Trying to scan ' + scanItemString + ' instead of ' + lineItemString)
|
740 |
raise TransactionServiceException(110, 'Trying to scan ' + scanItemString + ' instead of ' + lineItemString)
|
| 738 |
|
741 |
|
| 739 |
if ItemType.SERIALIZED == item.type:
|
742 |
if ItemType.SERIALIZED == item.type:
|
| 740 |
inventoryItem = warehouse_client.scanSerializedItemForOrder(serialNumber, ScanType.SALE, orderId, warehouse.id, 1, order.warehouse_id)
|
743 |
inventoryItem = warehouse_client.scanSerializedItemForOrder(serialNumber, ScanType.SALE, orderId, order.fulfilmentWarehouseId, 1, order.warehouse_id)
|
| 741 |
else:
|
744 |
else:
|
| 742 |
inventoryItem = warehouse_client.scanForOrder(inventoryItem, ScanType.SALE, 1, order.id, warehouse.id, order.warehouse_id)
|
745 |
inventoryItem = warehouse_client.scanForOrder(inventoryItem, ScanType.SALE, 1, order.id, order.fulfilmentWarehouseId, order.warehouse_id)
|
| 743 |
|
746 |
|
| 744 |
lineitem.transfer_price = inventoryItem.unitPrice
|
747 |
lineitem.transfer_price = inventoryItem.unitPrice
|
| 745 |
order.vendorId = inventoryItem.supplierId
|
748 |
order.vendorId = inventoryItem.supplierId
|
| - |
|
749 |
catalog_client = CatalogClient().get_client()
|
| 746 |
except WarehouseServiceException as e:
|
750 |
except WarehouseServiceException as e:
|
| 747 |
print sys.exc_info()[0]
|
751 |
print sys.exc_info()[0]
|
| 748 |
print 'Could not scan out orders due to: ' + e.message
|
752 |
print 'Could not scan out orders due to: ' + e.message
|
| 749 |
raise TransactionServiceException(110, e.message)
|
753 |
raise TransactionServiceException(110, e.message)
|
| 750 |
else:
|
754 |
else:
|
| 751 |
if not warehouse.isAvailabilityMonitored:
|
755 |
if not warehouse.isAvailabilityMonitored:
|
| 752 |
catalog_client = CatalogClient().get_client()
|
756 |
catalog_client = CatalogClient().get_client()
|
| 753 |
catalog_client.addInventory(item.id, warehouse.id, -1 * lineitem.quantity)
|
757 |
catalog_client.addInventory(item.id, warehouse.id, -1 * lineitem.quantity)
|
| 754 |
|
758 |
|
| 755 |
__update_inventory_reservation(order)
|
759 |
__update_inventory_reservation(order)
|
| 756 |
order.fulfilmentWarehouseId = warehouse.id
|
- |
|
| 757 |
session.commit()
|
760 |
session.commit()
|
| 758 |
return True
|
761 |
return True
|
| 759 |
else:
|
762 |
else:
|
| 760 |
return False
|
763 |
return False
|
| 761 |
|
764 |
|
| Line 808... |
Line 811... |
| 808 |
for order in orders:
|
811 |
for order in orders:
|
| 809 |
if order.id in orderIds:
|
812 |
if order.id in orderIds:
|
| 810 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
813 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
| 811 |
order.statusDescription = "Order shipped from warehouse"
|
814 |
order.statusDescription = "Order shipped from warehouse"
|
| 812 |
order.shipping_timestamp = current_timestamp
|
815 |
order.shipping_timestamp = current_timestamp
|
| - |
|
816 |
try:
|
| - |
|
817 |
print "Trying to schedule alert"
|
| - |
|
818 |
monitoredEntity = MonitoredEntity();
|
| - |
|
819 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
820 |
monitoredEntity.eventType=OrderStatus.SHIPPED_FROM_WH;
|
| - |
|
821 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
822 |
seconds_epoch = time.time()
|
| - |
|
823 |
#Warn alert time is taken as 15 hrs
|
| - |
|
824 |
warn_time = (seconds_epoch+15*3600)*1000
|
| - |
|
825 |
#Critical alert time is taken as 25 hrs
|
| - |
|
826 |
critical_time = (seconds_epoch+25*3600)*1000
|
| - |
|
827 |
monitoredEntity.warnExpiryTime = warn_time
|
| - |
|
828 |
monitoredEntity.criticalExpiryTime = critical_time
|
| - |
|
829 |
monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = " + str(order.id);
|
| - |
|
830 |
print monitoredEntity
|
| - |
|
831 |
print monitoredEntity.description
|
| - |
|
832 |
print monitoredEntity.warnExpiryTime
|
| - |
|
833 |
print monitoredEntity.entityIdentifier
|
| - |
|
834 |
alert_client = AlertClient().get_client()
|
| - |
|
835 |
alert_client.scheduleAlert(monitoredEntity)
|
| - |
|
836 |
except Exception as e:
|
| - |
|
837 |
print e
|
| 813 |
session.commit()
|
838 |
session.commit()
|
| 814 |
|
839 |
|
| 815 |
try:
|
840 |
try:
|
| 816 |
enqueue_shipping_confirmation_email(orders)
|
841 |
enqueue_shipping_confirmation_email(orders)
|
| 817 |
except Exception as e:
|
842 |
except Exception as e:
|
| Line 828... |
Line 853... |
| 828 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
853 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
| 829 |
continue
|
854 |
continue
|
| 830 |
order.status = OrderStatus.SHIPPED_TO_LOGST
|
855 |
order.status = OrderStatus.SHIPPED_TO_LOGST
|
| 831 |
order.statusDescription = "Order picked up by Courier Company"
|
856 |
order.statusDescription = "Order picked up by Courier Company"
|
| 832 |
order.pickup_timestamp = pickup_timestamp
|
857 |
order.pickup_timestamp = pickup_timestamp
|
| - |
|
858 |
|
| - |
|
859 |
try:
|
| - |
|
860 |
monitoredEntity = MonitoredEntity();
|
| - |
|
861 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
862 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_LOGST
|
| - |
|
863 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
864 |
seconds_epoch = time.time()
|
| - |
|
865 |
#Warn alert time is taken as 15 hrs
|
| - |
|
866 |
warn_time = (seconds_epoch+15*3600)*1000
|
| - |
|
867 |
#Critical alert time is taken as 25 hrs
|
| - |
|
868 |
critical_time = (seconds_epoch+25*3600)*1000
|
| - |
|
869 |
monitoredEntity.warnExpiryTime = warn_time
|
| - |
|
870 |
monitoredEntity.criticalExpiryTime = critical_time
|
| - |
|
871 |
monitoredEntity.description="providerId = " + str(provider_id) + " " + pickup_details
|
| - |
|
872 |
alert_client = AlertClient().get_client()
|
| - |
|
873 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| - |
|
874 |
except Exception as e:
|
| - |
|
875 |
print e
|
| 833 |
session.commit()
|
876 |
session.commit()
|
| 834 |
|
877 |
|
| 835 |
def get_orders_not_picked_up(provider_id):
|
878 |
def get_orders_not_picked_up(provider_id):
|
| 836 |
current_time = datetime.datetime.now()
|
879 |
current_time = datetime.datetime.now()
|
| 837 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
880 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| Line 854... |
Line 897... |
| 854 |
if order.first_dlvyatmp_timestamp is None:
|
897 |
if order.first_dlvyatmp_timestamp is None:
|
| 855 |
order.first_dlvyatmp_timestamp = timestamp
|
898 |
order.first_dlvyatmp_timestamp = timestamp
|
| 856 |
order.delivery_timestamp = timestamp
|
899 |
order.delivery_timestamp = timestamp
|
| 857 |
order.receiver = receiver
|
900 |
order.receiver = receiver
|
| 858 |
update_trust_level(order)
|
901 |
update_trust_level(order)
|
| - |
|
902 |
try:
|
| - |
|
903 |
alert_client = AlertClient().get_client()
|
| - |
|
904 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
|
| - |
|
905 |
except Exception as e:
|
| - |
|
906 |
print e
|
| - |
|
907 |
|
| 859 |
session.commit()
|
908 |
session.commit()
|
| 860 |
|
909 |
|
| 861 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
910 |
def mark_order_as_delivered(orderId, deliveryTimestamp, receiver):
|
| 862 |
order = Order.get_by(id=orderId)
|
911 |
order = Order.get_by(id=orderId)
|
| 863 |
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]:
|
912 |
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]:
|
| Line 872... |
Line 921... |
| 872 |
order.receiver = receiver
|
921 |
order.receiver = receiver
|
| 873 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
922 |
order.status = OrderStatus.DELIVERY_SUCCESS
|
| 874 |
order.statusDescription = "Order delivered"
|
923 |
order.statusDescription = "Order delivered"
|
| 875 |
update_trust_level(order)
|
924 |
update_trust_level(order)
|
| 876 |
session.commit()
|
925 |
session.commit()
|
| - |
|
926 |
try:
|
| - |
|
927 |
alert_client = AlertClient().get_client()
|
| - |
|
928 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
|
| - |
|
929 |
except Exception as e:
|
| - |
|
930 |
print e
|
| - |
|
931 |
|
| 877 |
|
932 |
|
| 878 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
933 |
def mark_order_as_received_at_store(orderId, deliveryTimestamp):
|
| 879 |
order = Order.get_by(id=orderId)
|
934 |
order = Order.get_by(id=orderId)
|
| 880 |
if order != None or order.status in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.DELIVERED_AT_STORE]:
|
935 |
if order != None or order.status in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.DELIVERED_AT_STORE]:
|
| 881 |
order.status = OrderStatus.RECEIVED_AT_STORE
|
936 |
order.status = OrderStatus.RECEIVED_AT_STORE
|
| Line 892... |
Line 947... |
| 892 |
order.status = OrderStatus.RTO_IN_TRANSIT
|
947 |
order.status = OrderStatus.RTO_IN_TRANSIT
|
| 893 |
order.delivery_timestamp, reason = detail.split('|')
|
948 |
order.delivery_timestamp, reason = detail.split('|')
|
| 894 |
order.statusDescription = "Order Returned to Origin:" + reason
|
949 |
order.statusDescription = "Order Returned to Origin:" + reason
|
| 895 |
update_trust_level(order)
|
950 |
update_trust_level(order)
|
| 896 |
session.commit()
|
951 |
session.commit()
|
| - |
|
952 |
try:
|
| - |
|
953 |
alert_client = AlertClient().get_client()
|
| - |
|
954 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + order.id)
|
| - |
|
955 |
except Exception as e:
|
| - |
|
956 |
print e
|
| 897 |
|
957 |
|
| 898 |
def get_rto_orders(provider_id):
|
958 |
def get_rto_orders(provider_id):
|
| 899 |
current_time = datetime.datetime.now()
|
959 |
current_time = datetime.datetime.now()
|
| 900 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
960 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 901 |
rto_orders = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.RTO_IN_TRANSIT).filter(Order.delivery_timestamp <= to_datetime).all()
|
961 |
rto_orders = Order.query.filter_by(logistics_provider_id = provider_id).filter_by(status=OrderStatus.RTO_IN_TRANSIT).filter(Order.delivery_timestamp <= to_datetime).all()
|
| Line 929... |
Line 989... |
| 929 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
|
989 |
if order == None or order.status not in [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST]:
|
| 930 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
990 |
#raise TransactionServiceException(102, "No order found for the awb: " + awb)
|
| 931 |
continue
|
991 |
continue
|
| 932 |
order.status = OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
992 |
order.status = OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
| 933 |
order.statusDescription = "Left Out of Origin City"
|
993 |
order.statusDescription = "Left Out of Origin City"
|
| 934 |
order.local_connected_timestamp = timestamp
|
994 |
current_time = datetime.datetime.now()
|
| - |
|
995 |
order.local_connected_timestamp = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| - |
|
996 |
try:
|
| - |
|
997 |
monitoredEntity = MonitoredEntity();
|
| - |
|
998 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
999 |
monitoredEntity.eventType=OrderStatus.SHIPPED_TO_DESTINATION_CITY
|
| - |
|
1000 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
1001 |
#Warn alert time is taken as 15 hrs
|
| - |
|
1002 |
warn_time = (order.promised_delivery_time-23*3600*1000)
|
| - |
|
1003 |
#Critical alert time is taken as 25 hrs
|
| - |
|
1004 |
critical_time = (order.promised_delivery_time-13*3600*1000)
|
| - |
|
1005 |
monitoredEntity.warnExpiryTime = warn_time
|
| - |
|
1006 |
monitoredEntity.criticalExpiryTime = critical_time
|
| - |
|
1007 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| - |
|
1008 |
alert_client = AlertClient().get_client()
|
| - |
|
1009 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| - |
|
1010 |
except Exception as e:
|
| - |
|
1011 |
print e
|
| 935 |
session.commit()
|
1012 |
session.commit()
|
| 936 |
|
1013 |
|
| 937 |
def get_orders_not_local_connected(provider_id):
|
1014 |
def get_orders_not_local_connected(provider_id):
|
| 938 |
current_time = datetime.datetime.now()
|
1015 |
current_time = datetime.datetime.now()
|
| 939 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1016 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 940 |
orders_pending_local_connection = Order.query.filter_by(logistics_provider_id = provider_id).filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST))).filter(or_(Order.shipping_timestamp <= to_datetime, Order.pickup_timestamp <= to_datetime)).all()
|
1017 |
orders_pending_local_connection = Order.query.filter_by(logistics_provider_id = provider_id).filter(Order.status.in_((OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST))).filter(or_(Order.shipping_timestamp <= to_datetime, Order.pickup_timestamp <= to_datetime)).all()
|
| Line 947... |
Line 1024... |
| 947 |
continue
|
1024 |
continue
|
| 948 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
1025 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
| 949 |
order.status = OrderStatus.REACHED_DESTINATION_CITY
|
1026 |
order.status = OrderStatus.REACHED_DESTINATION_CITY
|
| 950 |
order.statusDescription = "Reached Destination City"
|
1027 |
order.statusDescription = "Reached Destination City"
|
| 951 |
order.reached_destination_timestamp = timestamp
|
1028 |
order.reached_destination_timestamp = timestamp
|
| - |
|
1029 |
try:
|
| - |
|
1030 |
monitoredEntity = MonitoredEntity();
|
| - |
|
1031 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
1032 |
monitoredEntity.eventType=OrderStatus.REACHED_DESTINATION_CITY
|
| - |
|
1033 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
1034 |
warn_time = (order.promised_delivery_time)
|
| - |
|
1035 |
critical_time = (order.promised_delivery_time+12*3600*1000)
|
| - |
|
1036 |
monitoredEntity.warnExpiryTime = warn_time
|
| - |
|
1037 |
monitoredEntity.criticalExpiryTime = critical_time
|
| - |
|
1038 |
monitoredEntity.description="providerId = " + str(provider_id) + " destination city " + order.customer_city
|
| - |
|
1039 |
alert_client = AlertClient().get_client()
|
| - |
|
1040 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| - |
|
1041 |
except Exception as e:
|
| - |
|
1042 |
print e
|
| 952 |
session.commit()
|
1043 |
session.commit()
|
| 953 |
|
1044 |
|
| 954 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
1045 |
def mark_orders_as_firstDeliveryAttempted(provider_id, first_atdl_orders):
|
| 955 |
for awb, detail in first_atdl_orders.iteritems():
|
1046 |
for awb, detail in first_atdl_orders.iteritems():
|
| 956 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
1047 |
order = Order.query.filter_by(airwaybill_no=awb, logistics_provider_id = provider_id).first()
|
| Line 958... |
Line 1049... |
| 958 |
continue
|
1049 |
continue
|
| 959 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
1050 |
#raise TransactionServiceException(103, "No order found for the awb:" + awb)
|
| 960 |
order.status = OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
1051 |
order.status = OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
| 961 |
order.first_dlvyatmp_timestamp, reason = detail.split('|')
|
1052 |
order.first_dlvyatmp_timestamp, reason = detail.split('|')
|
| 962 |
order.statusDescription = reason
|
1053 |
order.statusDescription = reason
|
| - |
|
1054 |
try:
|
| - |
|
1055 |
monitoredEntity = MonitoredEntity();
|
| - |
|
1056 |
monitoredEntity.entityType=EntityType.COURIER;
|
| - |
|
1057 |
monitoredEntity.eventType=OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE
|
| - |
|
1058 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| - |
|
1059 |
seconds_epoch = time.time()
|
| - |
|
1060 |
#Warn alert time is taken as 15 hrs
|
| - |
|
1061 |
warn_time = (seconds_epoch+24*3600)*1000
|
| - |
|
1062 |
#Critical alert time is taken as 25 hrs
|
| - |
|
1063 |
critical_time = (seconds_epoch+36*3600)*1000
|
| - |
|
1064 |
monitoredEntity.warnExpiryTime = warn_time
|
| - |
|
1065 |
monitoredEntity.criticalExpiryTime = critical_time
|
| - |
|
1066 |
monitoredEntity.description="providerId = " + str(provider_id) + " first attempt timestamp" + order.first_dlvyatmp_timestamp
|
| - |
|
1067 |
alert_client = AlertClient().get_client()
|
| - |
|
1068 |
alert_client.updateMonitoredObject(monitoredEntity)
|
| - |
|
1069 |
except Exception as e:
|
| - |
|
1070 |
print e
|
| 963 |
session.commit()
|
1071 |
session.commit()
|
| 964 |
|
1072 |
|
| 965 |
def get_orders_not_met_expected_delivery_date():
|
1073 |
def get_orders_not_met_expected_delivery_date():
|
| 966 |
current_time = datetime.datetime.now()
|
1074 |
current_time = datetime.datetime.now()
|
| 967 |
today_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
1075 |
today_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|