| Line 1094... |
Line 1094... |
| 1094 |
return True
|
1094 |
return True
|
| 1095 |
|
1095 |
|
| 1096 |
def mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds):
|
1096 |
def mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds):
|
| 1097 |
try:
|
1097 |
try:
|
| 1098 |
current_timestamp = datetime.datetime.now()
|
1098 |
current_timestamp = datetime.datetime.now()
|
| 1099 |
orders = Order.query.filter_by(warehouse_id = warehouseId, logistics_provider_id = providerId, status = OrderStatus.BILLED, cod = cod).all()
|
1099 |
orders = Order.query.filter(Order.id.in_(orderIds)).filter_by(warehouse_id = warehouseId, logistics_provider_id = providerId, status = OrderStatus.BILLED).all()
|
| 1100 |
for order in orders:
|
1100 |
for order in orders:
|
| 1101 |
if order.id in orderIds:
|
- |
|
| 1102 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
1101 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
| 1103 |
order.statusDescription = "Order shipped from warehouse"
|
1102 |
order.statusDescription = "Order shipped from warehouse"
|
| 1104 |
order.shipping_timestamp = current_timestamp
|
1103 |
order.shipping_timestamp = current_timestamp
|
| 1105 |
try:
|
1104 |
try:
|
| 1106 |
print "Trying to schedule alert"
|
1105 |
print "Trying to schedule alert"
|
| 1107 |
monitoredEntity = MonitoredEntity();
|
1106 |
monitoredEntity = MonitoredEntity();
|
| 1108 |
monitoredEntity.entityType=EntityType.COURIER;
|
1107 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 1109 |
monitoredEntity.eventType=OrderStatus.SHIPPED_FROM_WH;
|
1108 |
monitoredEntity.eventType=OrderStatus.SHIPPED_FROM_WH;
|
| 1110 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
1109 |
monitoredEntity.entityIdentifier="orderId = " + str(order.id);
|
| 1111 |
adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 1);
|
1110 |
adjustedDeliveryDays = adjust_delivery_time(datetime.datetime.now(), 1);
|
| 1112 |
sec = datetime.datetime.now()
|
1111 |
sec = datetime.datetime.now()
|
| 1113 |
#Warn alert time is taken as 16 hrs
|
1112 |
#Warn alert time is taken as 16 hrs
|
| 1114 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=10))
|
1113 |
warn_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=16))
|
| 1115 |
#Critical alert time is taken as 26 hrs
|
1114 |
#Critical alert time is taken as 26 hrs
|
| 1116 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=15))
|
1115 |
critical_time = (sec + timedelta(days=(adjustedDeliveryDays-1)) + timedelta(hours=26))
|
| 1117 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
1116 |
monitoredEntity.warnExpiryTime = int(warn_time.strftime("%s"))*1000
|
| 1118 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
1117 |
monitoredEntity.criticalExpiryTime = int(critical_time.strftime("%s"))*1000
|
| 1119 |
monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = " + str(order.id);
|
1118 |
monitoredEntity.description="warehouseId = " + str(warehouseId) + " providerId = " + str(providerId) + " orderId = " + str(order.id);
|
| 1120 |
alert_client = AlertClient().get_client()
|
1119 |
alert_client = AlertClient().get_client()
|
| 1121 |
alert_client.scheduleAlert(monitoredEntity)
|
1120 |
alert_client.scheduleAlert(monitoredEntity)
|
| 1122 |
except Exception as e:
|
1121 |
except Exception as e:
|
| 1123 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
1122 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 1124 |
print e
|
1123 |
print e
|
| 1125 |
session.commit()
|
1124 |
session.commit()
|
| 1126 |
|
1125 |
|
| 1127 |
try:
|
1126 |
try:
|
| 1128 |
enqueue_shipping_confirmation_email(orders)
|
1127 |
enqueue_shipping_confirmation_email(orders)
|
| 1129 |
except Exception as e:
|
1128 |
except Exception as e:
|
| Line 1150... |
Line 1149... |
| 1150 |
raw_message = '''
|
1149 |
raw_message = '''
|
| 1151 |
Dear Sir,
|
1150 |
Dear Sir,
|
| 1152 |
|
1151 |
|
| 1153 |
Order mentioned below is being shipped to your store. Customer will pick it from your store.
|
1152 |
Order mentioned below is being shipped to your store. Customer will pick it from your store.
|
| 1154 |
|
1153 |
|
| 1155 |
Store Id: %(store_id)
|
1154 |
Store Id: %(store_id)s
|
| 1156 |
Order Id: %(order_id)
|
1155 |
Order Id: %(order_id)s
|
| 1157 |
Product: %(product)
|
1156 |
Product: %(product)s
|
| 1158 |
Delivery By: %(provider)
|
1157 |
Delivery By: %(provider)s
|
| 1159 |
|
1158 |
|
| 1160 |
Thanks and Regards
|
1159 |
Thanks and Regards
|
| 1161 |
Sandeep Sachdeva
|
1160 |
Sandeep Sachdeva
|
| 1162 |
'''
|
1161 |
'''
|
| - |
|
1162 |
|
| 1163 |
message = dedent(raw_message) % { 'order_id' : str(order.id),
|
1163 |
message = dedent(raw_message) % { 'order_id' : str(order.id),
|
| 1164 |
'store_id' : str(store.hotspotId),
|
1164 |
'store_id' : str(store.hotspotId),
|
| 1165 |
'provider' : provider.name,
|
1165 |
'provider' : provider.name,
|
| 1166 |
'product' : str(order.lineitems[0])
|
1166 |
'product' : str(order.lineitems[0])
|
| 1167 |
}
|
1167 |
}
|
| Line 3202... |
Line 3202... |
| 3202 |
|
3202 |
|
| 3203 |
for order in orders:
|
3203 |
for order in orders:
|
| 3204 |
try:
|
3204 |
try:
|
| 3205 |
emailSubject = 'Shipping Details for Order ID: ' + str(order.id)
|
3205 |
emailSubject = 'Shipping Details for Order ID: ' + str(order.id)
|
| 3206 |
emailBody = get_shipping_confirmation_email_body(order)
|
3206 |
emailBody = get_shipping_confirmation_email_body(order)
|
| 3207 |
helperClient.saveUserEmailForSending(order.customer_email, None, emailSubject, emailBody, '', 'ShippingConfirmation')
|
3207 |
helperClient.saveUserEmailForSending(order.customer_email, None, emailSubject, emailBody, str(order.id), 'ShippingConfirmation')
|
| 3208 |
except Exception as e:
|
3208 |
except Exception as e:
|
| 3209 |
print e
|
3209 |
print e
|
| 3210 |
|
3210 |
|
| 3211 |
def get_order_distribution_by_status(start_date, end_date):
|
3211 |
def get_order_distribution_by_status(start_date, end_date):
|
| 3212 |
query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
|
3212 |
query = session.query(Order.status, func.count(Order.id)).group_by(Order.status)
|