| Line 116... |
Line 116... |
| 116 |
import re
|
116 |
import re
|
| 117 |
import sys
|
117 |
import sys
|
| 118 |
import time
|
118 |
import time
|
| 119 |
import traceback
|
119 |
import traceback
|
| 120 |
import urllib
|
120 |
import urllib
|
| - |
|
121 |
from shop2020.utils.caching.SimpleCaching import memoized
|
| 121 |
|
122 |
|
| 122 |
|
123 |
|
| 123 |
|
124 |
|
| 124 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
125 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| 125 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
126 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| Line 570... |
Line 571... |
| 570 |
logistics_client = LogisticsClient().get_client()
|
571 |
logistics_client = LogisticsClient().get_client()
|
| 571 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
572 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
| 572 |
item_id = order.lineitems[0].item_id
|
573 |
item_id = order.lineitems[0].item_id
|
| 573 |
if pickUp == PickUpType.RUNNER or pickUp == PickUpType.SELF:
|
574 |
if pickUp == PickUpType.RUNNER or pickUp == PickUpType.SELF:
|
| 574 |
current_time = datetime.datetime.now()
|
575 |
current_time = datetime.datetime.now()
|
| 575 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp)
|
- |
|
| 576 |
order.logistics_provider_id = logistics_info.providerId
|
- |
|
| 577 |
if pdu.isFofo:
|
576 |
if pdu.isFofo:
|
| - |
|
577 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp, -1)
|
| - |
|
578 |
else:
|
| 578 |
###For fofo always use RQuick - Surface i.e. 48
|
579 |
stateMaster = fetchStateMaster()
|
| 579 |
##Changed to Self pickup for now i.e. 4
|
580 |
stateId = -1
|
| 580 |
order.logistics_provider_id = 4
|
581 |
for k, v in stateMaster.iteritems():
|
| 581 |
logistics_info.deliveryTime = logistics_info.shippingTime + 1
|
582 |
if v.stateName == order.customer_state:
|
| 582 |
|
583 |
stateId = k
|
| 583 |
# if fofoWarehousesMap:
|
584 |
break
|
| 584 |
# order.fulfilmentWarehouseId = fofoWarehousesMap.get(item_id).id
|
585 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp, stateId)
|
| 585 |
# order.warehouse_id = fofoWarehousesMap.get(item_id).billingWarehouseId
|
586 |
order.logistics_provider_id = logistics_info.providerId
|
| 586 |
|
587 |
|
| 587 |
order.warehouse_id = logistics_info.warehouseId
|
588 |
order.warehouse_id = logistics_info.warehouseId
|
| 588 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
589 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
| 589 |
|
590 |
|
| 590 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
591 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| Line 606... |
Line 607... |
| 606 |
|
607 |
|
| 607 |
elif order.source == OrderSource.WEBSITE:
|
608 |
elif order.source == OrderSource.WEBSITE:
|
| 608 |
try:
|
609 |
try:
|
| 609 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
610 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
| 610 |
inventory_client = InventoryClient().get_client()
|
611 |
inventory_client = InventoryClient().get_client()
|
| 611 |
fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1)
|
612 |
fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1, -1)
|
| 612 |
except Exception as ex:
|
613 |
except Exception as ex:
|
| 613 |
raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
|
614 |
raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
|
| 614 |
|
615 |
|
| 615 |
expectedDelayMap[item_id] = expected_delay
|
616 |
expectedDelayMap[item_id] = expected_delay
|
| 616 |
if billingWarehouseIdMap.has_key(billingWarehouseId):
|
617 |
if billingWarehouseIdMap.has_key(billingWarehouseId):
|
| Line 788... |
Line 789... |
| 788 |
else:
|
789 |
else:
|
| 789 |
|
790 |
|
| 790 |
try:
|
791 |
try:
|
| 791 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
792 |
#Get the id and location of actual warehouse that'll be used to fulfil this order.
|
| 792 |
inventory_client = InventoryClient().get_client()
|
793 |
inventory_client = InventoryClient().get_client()
|
| 793 |
fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1)
|
794 |
fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1, -1)
|
| 794 |
except Exception as ex:
|
795 |
except Exception as ex:
|
| 795 |
raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
|
796 |
raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
|
| 796 |
|
797 |
|
| 797 |
expectedDelayMap[item_id] = expected_delay
|
798 |
expectedDelayMap[item_id] = expected_delay
|
| 798 |
if billingWarehouseIdMap.has_key(billingWarehouseId):
|
799 |
if billingWarehouseIdMap.has_key(billingWarehouseId):
|
| Line 4467... |
Line 4468... |
| 4467 |
|
4468 |
|
| 4468 |
if warehouse_id == order.warehouse_id:
|
4469 |
if warehouse_id == order.warehouse_id:
|
| 4469 |
raise TransactionServiceException(118, "You have selected the current warehouse again. Nothing to do")
|
4470 |
raise TransactionServiceException(118, "You have selected the current warehouse again. Nothing to do")
|
| 4470 |
|
4471 |
|
| 4471 |
lineitem = order.lineitems[0]
|
4472 |
lineitem = order.lineitems[0]
|
| 4472 |
catalog_client = CatalogClient().get_client()
|
4473 |
userClient = UserClient().get_client()
|
| 4473 |
inventoryClient = InventoryClient().get_client()
|
4474 |
inventoryClient = InventoryClient().get_client()
|
| 4474 |
try:
|
4475 |
try:
|
| 4475 |
warehouse = inventoryClient.getWarehouse(warehouse_id)
|
4476 |
warehouse = inventoryClient.getWarehouse(warehouse_id)
|
| 4476 |
except:
|
4477 |
except:
|
| 4477 |
raise TransactionServiceException(119, "No warehouse with id" + str(warehouse_id))
|
4478 |
raise TransactionServiceException(119, "No warehouse with id" + str(warehouse_id))
|
| Line 4479... |
Line 4480... |
| 4479 |
if not warehouse.billingWarehouseId:
|
4480 |
if not warehouse.billingWarehouseId:
|
| 4480 |
raise TransactionServiceException(119, "Shifting of warehouse allowed to warehouse with billing support only")
|
4481 |
raise TransactionServiceException(119, "Shifting of warehouse allowed to warehouse with billing support only")
|
| 4481 |
|
4482 |
|
| 4482 |
# If One gives a billing warehouse for warehouse shift, we should assign order to the GOOD warehouse
|
4483 |
# If One gives a billing warehouse for warehouse shift, we should assign order to the GOOD warehouse
|
| 4483 |
# present within it with maximum availability
|
4484 |
# present within it with maximum availability
|
| - |
|
4485 |
userClient, isFofo = __is_Fofo(userClient, order.customer_id)
|
| - |
|
4486 |
|
| - |
|
4487 |
stateId = warehouse.state.id
|
| 4484 |
vendorWarehouse = None
|
4488 |
vendorWarehouse = None
|
| 4485 |
if warehouse.id == warehouse.billingWarehouseId:
|
4489 |
if warehouse.id == warehouse.billingWarehouseId:
|
| 4486 |
warehouses = inventoryClient.getWarehouses(None, InventoryType.GOOD, 0, 0, warehouse.id)
|
- |
|
| 4487 |
if warehouses:
|
- |
|
| 4488 |
itemInventory = inventoryClient.getItemInventoryByItemId(lineitem.item_id)
|
4490 |
itemAvailability = inventoryClient.getItemAvailabilityAtLocation(lineitem.item_id, sourceId, stateId)
|
| 4489 |
vendorWarehouse = warehouses[0]
|
- |
|
| 4490 |
maxAvailability = 0
|
- |
|
| 4491 |
for goodWarehouse in warehouses:
|
- |
|
| 4492 |
if itemInventory.availability.has_key(goodWarehouse.id) and maxAvailability < itemInventory.availability[goodWarehouse.id]:
|
- |
|
| 4493 |
vendorWarehouse = goodWarehouse
|
- |
|
| 4494 |
maxAvailability = itemInventory.availability[goodWarehouse.id]
|
- |
|
| 4495 |
|
- |
|
| 4496 |
# Use preferred vendor's warehouse if not available anywhere
|
- |
|
| 4497 |
'''
|
- |
|
| 4498 |
if not maxAvailability:
|
- |
|
| 4499 |
item = catalog_client.getItem(lineitem.item_id)
|
- |
|
| 4500 |
if item.preferredVendor:
|
- |
|
| 4501 |
for goodWarehouse in warehouses:
|
- |
|
| 4502 |
if goodWarehouse.vendor.id == item.preferredVendor:
|
- |
|
| 4503 |
warehouse = goodWarehouse
|
- |
|
| 4504 |
'''
|
- |
|
| 4505 |
else:
|
- |
|
| 4506 |
pass
|
- |
|
| 4507 |
|
4491 |
|
| 4508 |
#if vendorWarehouse is None or vendorWarehouse.billingWarehouseId != warehouse.id:
|
4492 |
#if vendorWarehouse is None or vendorWarehouse.billingWarehouseId != warehouse.id:
|
| 4509 |
#assign it to first vendorwarehouse available with
|
4493 |
#assign it to first vendorwarehouse available with
|
| 4510 |
#inventoryClient.reserveItemInWarehouse(lineitem.item_id, warehouse.id, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), lineitem.quantity)
|
- |
|
| 4511 |
if order.productCondition != ProductCondition.BAD:
|
4494 |
if order.productCondition != ProductCondition.BAD:
|
| 4512 |
inventoryClient.updateReservationForOrder(lineitem.item_id, vendorWarehouse.id, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), lineitem.quantity)
|
4495 |
inventoryClient.updateReservationForOrder(lineitem.item_id, itemAvailability[0], sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), lineitem.quantity)
|
| 4513 |
#__update_inventory_reservation(order)
|
4496 |
#__update_inventory_reservation(order)
|
| 4514 |
if order.status == OrderStatus.ACCEPTED:
|
4497 |
if order.status == OrderStatus.ACCEPTED:
|
| 4515 |
__update_transfer_price(order, vendorWarehouse.id)
|
4498 |
__update_transfer_price(order, vendorWarehouse.id)
|
| 4516 |
order.warehouse_id = vendorWarehouse.billingWarehouseId
|
4499 |
order.warehouse_id = vendorWarehouse.billingWarehouseId
|
| 4517 |
order.fulfilmentWarehouseId = vendorWarehouse.id
|
4500 |
order.fulfilmentWarehouseId = vendorWarehouse.id
|
| Line 4858... |
Line 4841... |
| 4858 |
order.status = OrderStatus.CANCEL_REQUEST_CONFIRMED
|
4841 |
order.status = OrderStatus.CANCEL_REQUEST_CONFIRMED
|
| 4859 |
order.statusDescription = "Cancellation request confirmed"
|
4842 |
order.statusDescription = "Cancellation request confirmed"
|
| 4860 |
session.commit()
|
4843 |
session.commit()
|
| 4861 |
refund_order(order.id, "crm-team", "As per Customer's Request")
|
4844 |
refund_order(order.id, "crm-team", "As per Customer's Request")
|
| 4862 |
|
4845 |
|
| - |
|
4846 |
@memoized(3600)
|
| - |
|
4847 |
def __is_Fofo(userClient, user_id):
|
| - |
|
4848 |
if not userClient or not userClient.isAlive():
|
| - |
|
4849 |
userClient = UserClient().get_client()
|
| - |
|
4850 |
return userClient, userClient.getPrivateDealUser(user_id).isFofo
|
| - |
|
4851 |
|
| 4863 |
def move_orders_to_correct_warehouse():
|
4852 |
def move_orders_to_correct_warehouse():
|
| 4864 |
completedOrders = []
|
4853 |
completedOrders = []
|
| 4865 |
pendingOrders = ""
|
4854 |
pendingOrders = ""
|
| 4866 |
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]))).order_by(Order.promised_shipping_time).all()
|
4855 |
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]))).order_by(Order.promised_shipping_time).all()
|
| 4867 |
logistics_client = LogisticsClient().get_client()
|
- |
|
| 4868 |
inventoryClient = InventoryClient().get_client()
|
4856 |
inventoryClient = InventoryClient().get_client()
|
| - |
|
4857 |
userClient = UserClient().get_client()
|
| - |
|
4858 |
|
| 4869 |
#warehouses = inventoryClient.getWarehouses(None, None, None, None, None)
|
4859 |
#warehouses = inventoryClient.getWarehouses(None, None, None, None, None)
|
| 4870 |
for order in orders:
|
4860 |
for order in orders:
|
| - |
|
4861 |
stateMaster = fetchStateMaster()
|
| - |
|
4862 |
stateId = -1
|
| - |
|
4863 |
userClient, isFofo = __is_Fofo(userClient, order.customer_id)
|
| - |
|
4864 |
if isFofo:
|
| - |
|
4865 |
for k, v in stateMaster.iteritems():
|
| - |
|
4866 |
if v.stateName == order.customer_state:
|
| - |
|
4867 |
stateId = k
|
| - |
|
4868 |
break
|
| 4871 |
lineitem = order.lineitems[0]
|
4869 |
lineitem = order.lineitems[0]
|
| 4872 |
try:
|
4870 |
try:
|
| 4873 |
if not logistics_client or not logistics_client.isAlive():
|
4871 |
if not inventoryClient or not inventoryClient.isAlive():
|
| 4874 |
logistics_client = LogisticsClient().get_client()
|
4872 |
inventoryClient = InventoryClient().get_client()
|
| 4875 |
logistics_info = logistics_client.getLogisticsEstimation(lineitem.item_id, order.customer_pincode, order.cod)
|
4873 |
fulfilmentWarehouseId = inventoryClient.getItemAvailabilityAtLocation(lineitem.item_id, sourceId, stateId)[0]
|
| 4876 |
if order.fulfilmentWarehouseId != logistics_info.fulfilmentWarehouseId:
|
4874 |
if order.fulfilmentWarehouseId != fulfilmentWarehouseId:
|
| 4877 |
if not inventoryClient or not inventoryClient.isAlive():
|
- |
|
| 4878 |
inventoryClient = InventoryClient().get_client()
|
- |
|
| 4879 |
netavailability = inventoryClient.getItemAvailibilityAtWarehouse(logistics_info.fulfilmentWarehouseId, lineitem.item_id)
|
4875 |
netavailability = inventoryClient.getItemAvailibilityAtWarehouse(fulfilmentWarehouseId, lineitem.item_id)
|
| 4880 |
if netavailability >= lineitem.quantity:
|
4876 |
if netavailability >= lineitem.quantity:
|
| 4881 |
try:
|
4877 |
try:
|
| 4882 |
print "++++" + str(order.id) + "=" + str(order.fulfilmentWarehouseId) + "->"+ str(logistics_info.fulfilmentWarehouseId)
|
4878 |
print "++++" + str(order.id) + "=" + str(order.fulfilmentWarehouseId) + "->"+ str(fulfilmentWarehouseId)
|
| 4883 |
change_warehouse(order.id, logistics_info.fulfilmentWarehouseId)
|
4879 |
change_warehouse(order.id, fulfilmentWarehouseId)
|
| 4884 |
completedOrders.append(order.id)
|
4880 |
completedOrders.append(order.id)
|
| 4885 |
except:
|
4881 |
except:
|
| 4886 |
print "++++" + str(order.id)
|
4882 |
print "++++" + str(order.id)
|
| 4887 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
4883 |
pendingOrders = pendingOrders + str(order.id) + "|"
|
| 4888 |
except:
|
4884 |
except:
|