| Line 2656... |
Line 2656... |
| 2656 |
alert_client = AlertClient().get_client()
|
2656 |
alert_client = AlertClient().get_client()
|
| 2657 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
2657 |
alert_client.endMonitoringEntity(EntityType.COURIER, "orderId = " + str(order.id))
|
| 2658 |
except Exception as e:
|
2658 |
except Exception as e:
|
| 2659 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
2659 |
print "Exception in scheduling alert in ShippedFromWarehouse method"
|
| 2660 |
print e
|
2660 |
print e
|
| - |
|
2661 |
|
| - |
|
2662 |
itemIds = []
|
| - |
|
2663 |
ordersMap = {}
|
| - |
|
2664 |
orderItemsMap = {}
|
| - |
|
2665 |
for order in orders:
|
| - |
|
2666 |
if order.lineitems[0].item_id not in itemIds:
|
| - |
|
2667 |
itemIds.append(order.lineitems[0].item_id)
|
| - |
|
2668 |
ordersMap[order.id] = order
|
| - |
|
2669 |
orderItemsMap[order.id] = order.lineitems[0].item_id
|
| - |
|
2670 |
|
| - |
|
2671 |
catalogClient = CatalogClient().get_client()
|
| - |
|
2672 |
items = catalogClient.getItems(itemIds)
|
| - |
|
2673 |
catalogIds = []
|
| - |
|
2674 |
catalogItemsMap = {}
|
| - |
|
2675 |
for item in items:
|
| - |
|
2676 |
catalogIds.append(item.catalog_item_id)
|
| - |
|
2677 |
catalogItemsMap[item.id] = item.catalog_item_id
|
| - |
|
2678 |
|
| - |
|
2679 |
itemWarrantyInfoMap = catalogClient.getWarrantyInfoForItemList(catalogIds, ItemCondition.DAMAGED)
|
| - |
|
2680 |
itemDOAWarrantyInfoMap = catalogClient.getWarrantyInfoForItemList(catalogIds, ItemCondition.DEFECTIVE)
|
| - |
|
2681 |
|
| - |
|
2682 |
for orderId, order in ordersMap.items():
|
| - |
|
2683 |
orderItemId = orderItemsMap.get(orderId)
|
| - |
|
2684 |
orderCatalogItemId = catalogItemsMap.get(orderItemId)
|
| - |
|
2685 |
itemWarrantyInfo = itemWarrantyInfoMap.get(orderCatalogItemId)
|
| - |
|
2686 |
itemDOAWarrantyInfo = itemDOAWarrantyInfoMap.get(orderCatalogItemId)
|
| - |
|
2687 |
|
| - |
|
2688 |
itemWarrntyVal = 0
|
| - |
|
2689 |
doaItemWarrantyVal = 0
|
| - |
|
2690 |
|
| - |
|
2691 |
if itemWarrantyInfo.key()[0]=='M':
|
| - |
|
2692 |
itemWarrntyVal = 30*itemWarrantyInfo.values()[0]
|
| - |
|
2693 |
else:
|
| - |
|
2694 |
itemWarrntyVal = itemWarrantyInfo.values()[0]
|
| - |
|
2695 |
|
| - |
|
2696 |
if itemDOAWarrantyInfo.key()[0]=='M':
|
| - |
|
2697 |
doaItemWarrantyVal = 30*itemDOAWarrantyInfo.values()[0]
|
| - |
|
2698 |
else:
|
| - |
|
2699 |
doaItemWarrantyVal = itemDOAWarrantyInfo.values()[0]
|
| - |
|
2700 |
|
| - |
|
2701 |
order.lineitems[0].warrantry_expiry_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") + timedelta(days=itemWarrntyVal)
|
| - |
|
2702 |
order.lineitems[0].damaged_expiry_timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") + timedelta(days=doaItemWarrantyVal)
|
| 2661 |
|
2703 |
|
| 2662 |
for logisticsTxnId, ordersList in logisticsTxnIdOrdersMap.iteritems():
|
2704 |
for logisticsTxnId, ordersList in logisticsTxnIdOrdersMap.iteritems():
|
| 2663 |
if enqueue_delivery_success_mail(logisticsTxnId, ordersList) :
|
2705 |
if enqueue_delivery_success_mail(logisticsTxnId, ordersList) :
|
| 2664 |
order = ordersList[0]
|
2706 |
order = ordersList[0]
|
| 2665 |
update_trust_level(order)
|
2707 |
update_trust_level(order)
|
| Line 4948... |
Line 4990... |
| 4948 |
def move_orders_to_correct_warehouse():
|
4990 |
def move_orders_to_correct_warehouse():
|
| 4949 |
completedOrders = []
|
4991 |
completedOrders = []
|
| 4950 |
pendingOrders = ""
|
4992 |
pendingOrders = ""
|
| 4951 |
orders = Order.query.filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.ACCEPTED]))).order_by(Order.promised_shipping_time).all()
|
4993 |
orders = Order.query.filter(Order.status.in_(tuple([OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.ACCEPTED]))).order_by(Order.promised_shipping_time).all()
|
| 4952 |
logistics_client = LogisticsClient().get_client()
|
4994 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
4995 |
inventoryClient = InventoryClient().get_client()
|
| 4953 |
for order in orders:
|
4996 |
for order in orders:
|
| 4954 |
lineitem = order.lineitems[0]
|
4997 |
lineitem = order.lineitems[0]
|
| 4955 |
try:
|
4998 |
try:
|
| 4956 |
if not logistics_client.isAlive():
|
4999 |
if not logistics_client or not logistics_client.isAlive():
|
| 4957 |
logistics_client = LogisticsClient().get_client()
|
5000 |
logistics_client = LogisticsClient().get_client()
|
| 4958 |
logistics_info = logistics_client.getLogisticsEstimation(lineitem.item_id, order.customer_pincode, order.cod)
|
5001 |
logistics_info = logistics_client.getLogisticsEstimation(lineitem.item_id, order.customer_pincode, order.cod)
|
| 4959 |
if order.fulfilmentWarehouseId != logistics_info.fulfilmentWarehouseId:
|
5002 |
if order.fulfilmentWarehouseId != logistics_info.fulfilmentWarehouseId:
|
| - |
|
5003 |
if not inventoryClient or not inventoryClient.isAlive():
|
| - |
|
5004 |
inventoryClient = InventoryClient().get_client()
|
| - |
|
5005 |
itemInventory = inventoryClient.getItemInventoryByItemId(order.lineitems[0].item_id)
|
| - |
|
5006 |
netavailability = itemInventory.availability[order.fulfilmentWarehouseId] - (itemInventory.reserved[order.fulfilmentWarehouseId]+itemInventory.held[order.fulfilmentWarehouseId])
|
| - |
|
5007 |
if order.lineitems[0].quantity<=netavailability:
|
| 4960 |
try:
|
5008 |
try:
|
| 4961 |
print "++++" + str(order.id) + "=" + str(order.fulfilmentWarehouseId) + "->"+ str(logistics_info.fulfilmentWarehouseId)
|
5009 |
print "++++" + str(order.id) + "=" + str(order.fulfilmentWarehouseId) + "->"+ str(logistics_info.fulfilmentWarehouseId)
|
| 4962 |
change_warehouse(order.id, logistics_info.fulfilmentWarehouseId)
|
5010 |
change_warehouse(order.id, logistics_info.fulfilmentWarehouseId)
|
| 4963 |
completedOrders.append(order.id)
|
5011 |
completedOrders.append(order.id)
|
| 4964 |
except:
|
5012 |
except:
|
| 4965 |
print "++++" + str(order.id)
|
5013 |
print "++++" + str(order.id)
|
| 4966 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
5014 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
| 4967 |
except:
|
5015 |
except:
|
| 4968 |
print "++++" + str(order.id)
|
5016 |
print "++++" + str(order.id)
|
| 4969 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
5017 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
| 4970 |
|
5018 |
|
| 4971 |
if len(completedOrders)==0 and len(pendingOrders)==0:
|
5019 |
if len(completedOrders)==0 and len(pendingOrders)==0:
|
| Line 8632... |
Line 8680... |
| 8632 |
conn.close()
|
8680 |
conn.close()
|
| 8633 |
|
8681 |
|
| 8634 |
conn.close()
|
8682 |
conn.close()
|
| 8635 |
|
8683 |
|
| 8636 |
print 'Process completed'
|
8684 |
print 'Process completed'
|
| 8637 |
'''
|
8685 |
awbNumber = None
|
| - |
|
8686 |
if updatedOrders[0].logistics_provider_id<7:
|
| 8638 |
deltype = DeliveryType.PREPAID
|
8687 |
deltype = DeliveryType.PREPAID
|
| 8639 |
if ordersList[0].cod:
|
8688 |
if updatedOrders[0].cod:
|
| 8640 |
deltype = DeliveryType.COD
|
8689 |
deltype = DeliveryType.COD
|
| 8641 |
if not logistics_client.isAlive():
|
8690 |
if not logistics_client.isAlive():
|
| 8642 |
logistics_client = LogisticsClient().get_client()
|
8691 |
logistics_client = LogisticsClient().get_client()
|
| 8643 |
awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
|
8692 |
awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
|
| 8644 |
'''
|
- |
|
| 8645 |
|
8693 |
|
| 8646 |
txnSeqRequired = 0
|
8694 |
txnSeqRequired = 0
|
| 8647 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==updatedOrders[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
|
8695 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==updatedOrders[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
|
| 8648 |
if txnShipSeq is None:
|
8696 |
if txnShipSeq is None:
|
| 8649 |
txnShipSeq = TransactionShipmentSequence()
|
8697 |
txnShipSeq = TransactionShipmentSequence()
|
| Line 8657... |
Line 8705... |
| 8657 |
txnShipSeqNew.createdTimestamp = datetime.datetime.now()
|
8705 |
txnShipSeqNew.createdTimestamp = datetime.datetime.now()
|
| 8658 |
txnShipSeqNew.sequence = txnShipSeq.sequence + 1
|
8706 |
txnShipSeqNew.sequence = txnShipSeq.sequence + 1
|
| 8659 |
txnSeqRequired = txnShipSeq.sequence + 1
|
8707 |
txnSeqRequired = txnShipSeq.sequence + 1
|
| 8660 |
|
8708 |
|
| 8661 |
for order in updatedOrders:
|
8709 |
for order in updatedOrders:
|
| 8662 |
#update_order_AWB(order.id, awbNumber)
|
- |
|
| 8663 |
order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
|
8710 |
order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
|
| 8664 |
|
8711 |
|
| 8665 |
session.commit()
|
8712 |
session.commit()
|
| 8666 |
|
8713 |
|
| - |
|
8714 |
if awbNumber is not None:
|
| - |
|
8715 |
update_master_order_awb(str(updatedOrders[0].transaction_id)+"-"+str(txnSeqRequired), awbNumber)
|
| - |
|
8716 |
|
| 8667 |
singleOrder = updatedOrders[0]
|
8717 |
singleOrder = updatedOrders[0]
|
| 8668 |
if singleOrder.orderType == OrderType.B2B:
|
8718 |
if singleOrder.orderType == OrderType.B2B:
|
| 8669 |
user_client = UserClient().get_client()
|
8719 |
user_client = UserClient().get_client()
|
| 8670 |
if user_client.isPrivateDealUser(singleOrder.customer_id):
|
8720 |
if user_client.isPrivateDealUser(singleOrder.customer_id):
|
| 8671 |
billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
|
8721 |
billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
|
| Line 10694... |
Line 10744... |
| 10694 |
returnOrder.refundDescription = str(returnOrder.replacementOrderId) + " has been delivered now"
|
10744 |
returnOrder.refundDescription = str(returnOrder.replacementOrderId) + " has been delivered now"
|
| 10695 |
returnOrder.returnTxnResolutionStatus = ReturnTxnResolutionStatus._VALUES_TO_NAMES[ReturnTxnResolutionStatus.REPLACEMENT_DONE]
|
10745 |
returnOrder.returnTxnResolutionStatus = ReturnTxnResolutionStatus._VALUES_TO_NAMES[ReturnTxnResolutionStatus.REPLACEMENT_DONE]
|
| 10696 |
session.commit()
|
10746 |
session.commit()
|
| 10697 |
|
10747 |
|
| 10698 |
def get_eligible_orders_for_return(customerId, itemCondition, overrideWarranty):
|
10748 |
def get_eligible_orders_for_return(customerId, itemCondition, overrideWarranty):
|
| 10699 |
query = session.query(Order).join((LineItem,Order.id==LineItem.order_id)).filter(Order.delivery_timestamp != None).filter(LineItem.quantity-LineItem.returnQty>0)
|
10749 |
query = session.query(Order).join((LineItem,Order.id==LineItem.order_id)).filter(Order.delivery_timestamp != None).filter(Order.status.in_(tuple([OrderStatus.DELIVERY_SUCCESS,OrderStatus.PARTIAL_RETURN,OrderStatus.PARTIAL_RETURN_IN_PROCESS]))).filter(LineItem.quantity-LineItem.returnQty>0)
|
| 10700 |
if not overrideWarranty and itemCondition is not None:
|
10750 |
if not overrideWarranty and itemCondition is not None:
|
| 10701 |
if itemCondition == 'DAMAGED':
|
10751 |
if itemCondition == 'DAMAGED':
|
| 10702 |
query = query.filter(LineItem.warranty_expiry_timestamp<=datetime.datetime.now())
|
10752 |
query = query.filter(LineItem.warranty_expiry_timestamp<=datetime.datetime.now())
|
| 10703 |
elif itemCondition == 'DEFECTIVE':
|
10753 |
elif itemCondition == 'DEFECTIVE':
|
| 10704 |
query = query.filter(LineItem.damaged_expiry_timestamp<=datetime.datetime.now())
|
10754 |
query = query.filter(LineItem.damaged_expiry_timestamp<=datetime.datetime.now())
|