| Line 2016... |
Line 2016... |
| 2016 |
orders = Order.query.filter(Order.id.in_(orderIds)).filter_by(warehouse_id = warehouseId, logistics_provider_id = providerId, status = OrderStatus.BILLED).all()
|
2016 |
orders = Order.query.filter(Order.id.in_(orderIds)).filter_by(warehouse_id = warehouseId, logistics_provider_id = providerId, status = OrderStatus.BILLED).all()
|
| 2017 |
for order in orders:
|
2017 |
for order in orders:
|
| 2018 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
2018 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
| 2019 |
order.statusDescription = "Order shipped from warehouse"
|
2019 |
order.statusDescription = "Order shipped from warehouse"
|
| 2020 |
order.shipping_timestamp = current_timestamp
|
2020 |
order.shipping_timestamp = current_timestamp
|
| - |
|
2021 |
'''
|
| 2021 |
try:
|
2022 |
try:
|
| 2022 |
print "Trying to schedule alert"
|
2023 |
print "Trying to schedule alert"
|
| 2023 |
monitoredEntity = MonitoredEntity();
|
2024 |
monitoredEntity = MonitoredEntity();
|
| 2024 |
monitoredEntity.entityType=EntityType.COURIER;
|
2025 |
monitoredEntity.entityType=EntityType.COURIER;
|
| 2025 |
monitoredEntity.eventType=OrderStatus.SHIPPED_FROM_WH;
|
2026 |
monitoredEntity.eventType=OrderStatus.SHIPPED_FROM_WH;
|
| Line 2036... |
Line 2037... |
| 2036 |
alert_client = AlertClient().get_client()
|
2037 |
alert_client = AlertClient().get_client()
|
| 2037 |
alert_client.scheduleAlert(monitoredEntity)
|
2038 |
alert_client.scheduleAlert(monitoredEntity)
|
| 2038 |
except Exception as e:
|
2039 |
except Exception as e:
|
| 2039 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
2040 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 2040 |
print e
|
2041 |
print e
|
| - |
|
2042 |
'''
|
| 2041 |
session.commit()
|
2043 |
session.commit()
|
| 2042 |
logisticsTxnIdOrdersMap = {}
|
2044 |
logisticsTxnIdOrdersMap = {}
|
| 2043 |
try:
|
- |
|
| 2044 |
for order in orders:
|
2045 |
for order in orders:
|
| 2045 |
if order.logisticsTransactionId:
|
2046 |
if order.logisticsTransactionId:
|
| 2046 |
if logisticsTxnIdOrdersMap.has_key(order.logisticsTransactionId):
|
2047 |
if logisticsTxnIdOrdersMap.has_key(order.logisticsTransactionId):
|
| 2047 |
ordersList = logisticsTxnIdOrdersMap.get(order.logisticsTransactionId)
|
2048 |
ordersList = logisticsTxnIdOrdersMap.get(order.logisticsTransactionId)
|
| 2048 |
ordersList.append(order)
|
- |
|
| 2049 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
- |
|
| 2050 |
else:
|
- |
|
| 2051 |
ordersList = []
|
- |
|
| 2052 |
ordersList.append(order)
|
2049 |
ordersList.append(order)
|
| 2053 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
2050 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
| 2054 |
else:
|
2051 |
else:
|
| 2055 |
ordersList = []
|
2052 |
ordersList = []
|
| 2056 |
ordersList.append(order)
|
2053 |
ordersList.append(order)
|
| 2057 |
logisticsTxnIdOrdersMap[str(order.id)] = ordersList
|
2054 |
logisticsTxnIdOrdersMap[order.logisticsTransactionId] = ordersList
|
| 2058 |
except Exception as e:
|
2055 |
else:
|
| 2059 |
print e
|
2056 |
ordersList = []
|
| - |
|
2057 |
ordersList.append(order)
|
| - |
|
2058 |
logisticsTxnIdOrdersMap[str(order.id)] = ordersList
|
| 2060 |
|
2059 |
|
| 2061 |
for logisticsTxnId, orderList in logisticsTxnIdOrdersMap.iteritems():
|
2060 |
for logisticsTxnId, orderList in logisticsTxnIdOrdersMap.iteritems():
|
| 2062 |
enqueue_shipping_confirmation_email(logisticsTxnId, orderList)
|
2061 |
enqueue_shipping_confirmation_email(logisticsTxnId, orderList)
|
| 2063 |
|
2062 |
|
| 2064 |
try:
|
2063 |
try:
|
| Line 4801... |
Line 4800... |
| 4801 |
|
4800 |
|
| 4802 |
def enqueue_shipping_confirmation_email(logisticsTxnId, orderList):
|
4801 |
def enqueue_shipping_confirmation_email(logisticsTxnId, orderList):
|
| 4803 |
# Calling helper service on production
|
4802 |
# Calling helper service on production
|
| 4804 |
order = orderList[0]
|
4803 |
order = orderList[0]
|
| 4805 |
helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
4804 |
helperClient = HelperClient(host_key = "helper_service_server_host_prod").get_client()
|
| 4806 |
try:
|
- |
|
| 4807 |
emailSubject = 'Shipping Details for Master Order ID: ' + logisticsTxnId
|
4805 |
emailSubject = 'Shipping Details for Master Order ID: ' + logisticsTxnId
|
| 4808 |
emailBody = get_shipping_confirmation_email_body(logisticsTxnId, orderList)
|
4806 |
emailBody = get_shipping_confirmation_email_body(logisticsTxnId, orderList)
|
| 4809 |
helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, logisticsTxnId, 'ShippingConfirmation', [], [], order.source)
|
4807 |
helperClient.saveUserEmailForSending([order.customer_email], None, emailSubject, emailBody, logisticsTxnId, 'ShippingConfirmation', [], [], order.source)
|
| 4810 |
|
4808 |
|
| 4811 |
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'}}
|
4809 |
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'}}
|
| 4812 |
provider_name = logistics_providers[order.logistics_provider_id]['name']
|
4810 |
provider_name = logistics_providers[order.logistics_provider_id]['name']
|
| 4813 |
if order.source == OrderSource.WEBSITE :
|
4811 |
if order.source == OrderSource.WEBSITE :
|
| 4814 |
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)
|
4812 |
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)
|
| 4815 |
except Exception as e:
|
- |
|
| 4816 |
print e
|
4813 |
|
| 4817 |
|
4814 |
|
| 4818 |
def get_order_distribution_by_status(start_date, end_date):
|
4815 |
def get_order_distribution_by_status(start_date, end_date):
|
| 4819 |
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)
|
| 4820 |
query = query.filter(Order.created_timestamp >= start_date)
|
4817 |
query = query.filter(Order.created_timestamp >= start_date)
|
| 4821 |
query = query.filter(Order.created_timestamp <= end_date)
|
4818 |
query = query.filter(Order.created_timestamp <= end_date)
|
| Line 7777... |
Line 7774... |
| 7777 |
totalWeight = totalWeight + order.total_weight
|
7774 |
totalWeight = totalWeight + order.total_weight
|
| 7778 |
#if order.cod:
|
7775 |
#if order.cod:
|
| 7779 |
totalOrdersAmount = totalOrdersAmount + order.total_amount
|
7776 |
totalOrdersAmount = totalOrdersAmount + order.total_amount
|
| 7780 |
|
7777 |
|
| 7781 |
if order.cod:
|
7778 |
if order.cod:
|
| 7782 |
if isPrivateDealUser:
|
7779 |
if isPrivateDealUser and privateDealUser.bulkShipmentAmountLimit:
|
| 7783 |
if totalOrdersAmount > privateDealUser.bulkShipmentAmountLimit:
|
7780 |
if totalOrdersAmount > privateDealUser.bulkShipmentAmountLimit:
|
| - |
|
7781 |
raise TransactionServiceException(208, "Private Deal Counter Group Shipment Weight Limit Violated i.e. "+ str(privateDealUser.bulkShipmentAmountLimit))
|
| - |
|
7782 |
else:
|
| - |
|
7783 |
if totalOrdersAmount > 50000:
|
| 7784 |
raise TransactionServiceException(208, "Private Deal Counter Group Shipment Weight Limit Violated")
|
7784 |
raise TransactionServiceException(208, "Private Deal Counter Group Shipment Weight Limit Violated i.e. "+ str(50000))
|
| 7785 |
|
7785 |
|
| 7786 |
if totalWeight > provider.bundleWeightLimit:
|
7786 |
if totalWeight > provider.bundleWeightLimit:
|
| 7787 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Group Shipment Weight Limit Violated")
|
7787 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Group Shipment Weight Limit Violated i.e. "+str(provider.bundleWeightLimit))
|
| 7788 |
|
7788 |
|
| 7789 |
if order.cod:
|
7789 |
if order.cod:
|
| 7790 |
if totalOrdersAmount > provider.maxCodLimit:
|
7790 |
if totalOrdersAmount > provider.maxCodLimit:
|
| 7791 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Max Cod Amount Collection Limit Violated")
|
7791 |
raise TransactionServiceException(210, "Logistics Partner "+provider.name+ " Max Cod Amount Collection Limit Violated i.e. "+ str(provider.maxCodLimit))
|
| 7792 |
|
7792 |
|
| 7793 |
websiteCodLimit = float(providerLimits.get("websiteCodLimit"))
|
7793 |
websiteCodLimit = float(providerLimits.get("websiteCodLimit"))
|
| 7794 |
providerPrepaidLimit = float(providerLimits.get("providerPrepaidLimit"))
|
7794 |
providerPrepaidLimit = float(providerLimits.get("providerPrepaidLimit"))
|
| 7795 |
|
7795 |
|
| 7796 |
if order.cod and not isPrivateDealUser:
|
7796 |
if order.cod and not isPrivateDealUser:
|
| 7797 |
if totalOrdersAmount > websiteCodLimit:
|
7797 |
if totalOrdersAmount > websiteCodLimit:
|
| 7798 |
raise TransactionServiceException(212, "Website Maximum COD Limit Violated")
|
7798 |
raise TransactionServiceException(212, "Website Maximum COD Limit Violated i.e. "+str(websiteCodLimit))
|
| 7799 |
|
7799 |
|
| 7800 |
if not order.cod:
|
7800 |
if not order.cod:
|
| 7801 |
if totalOrdersAmount > providerPrepaidLimit:
|
7801 |
if totalOrdersAmount > providerPrepaidLimit:
|
| 7802 |
raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
|
7802 |
raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
|
| 7803 |
|
7803 |
|