| Line 645... |
Line 645... |
| 645 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
645 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 646 |
order.lineitems[0].nlc = item_pricing.nlc
|
646 |
order.lineitems[0].nlc = item_pricing.nlc
|
| 647 |
except:
|
647 |
except:
|
| 648 |
print "Not able to get transfer price. Skipping"
|
648 |
print "Not able to get transfer price. Skipping"
|
| 649 |
|
649 |
|
| 650 |
catalog_client = CatalogClient().get_client()
|
- |
|
| 651 |
|
- |
|
| 652 |
for billingWarehouseId, orders in billingWarehouseIdMap.items():
|
- |
|
| 653 |
logistics_client = LogisticsClient().get_client()
|
- |
|
| 654 |
transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
|
- |
|
| 655 |
costingAndDeliveryEstimateObj = None
|
- |
|
| 656 |
try:
|
- |
|
| 657 |
costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, False, transactionWeight, billingWarehouseId, False)
|
- |
|
| 658 |
except:
|
- |
|
| 659 |
try:
|
- |
|
| 660 |
#This will pass the maximum unit price of available product in all scenarios.
|
- |
|
| 661 |
subOrderAmountsList = sorted(subOrderAmountsMap.keys())
|
- |
|
| 662 |
maxUnitPriceOrder = subOrderAmountsMap.get(subOrderAmountsList[len(subOrderAmountsList)-1])
|
- |
|
| 663 |
costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, maxUnitPriceOrder.lineitems[0].unit_price, False, maxUnitPriceOrder.lineitems[0].unit_weight, billingWarehouseId, False)
|
- |
|
| 664 |
except:
|
- |
|
| 665 |
#TODO:
|
- |
|
| 666 |
raise TransactionServiceException(108, "No Logistics Provider Assigned")
|
- |
|
| 667 |
#This should not be raised lets go ahead
|
- |
|
| 668 |
|
- |
|
| 669 |
|
- |
|
| 670 |
logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
|
- |
|
| 671 |
logisticsCostInOrders = 0
|
- |
|
| 672 |
current_time = datetime.datetime.now()
|
- |
|
| 673 |
#delivery_delay
|
- |
|
| 674 |
for order in orders:
|
- |
|
| 675 |
deliveryTime = costingAndDeliveryEstimateObj.deliveryTime
|
- |
|
| 676 |
shippingTime = costingAndDeliveryEstimateObj.shippingTime
|
- |
|
| 677 |
delivery_delay = costingAndDeliveryEstimateObj.delivery_delay
|
- |
|
| 678 |
expectedDelay = expectedDelayMap.get(order.lineitems[0].item_id)
|
- |
|
| 679 |
shipping_delay = 24 * expectedDelay
|
- |
|
| 680 |
if shipping_delay < 0:
|
- |
|
| 681 |
shipping_delay = shippingTime
|
- |
|
| 682 |
else:
|
- |
|
| 683 |
shipping_delay = shipping_delay + 24 * shippingTime
|
- |
|
| 684 |
shipping_delay = int(math.ceil(shipping_delay/24.0))
|
- |
|
| 685 |
deliveryTime = adjust_delivery_time(current_time, deliveryTime+shipping_delay)
|
- |
|
| 686 |
shippingTime = adjust_delivery_time(current_time, shipping_delay)
|
- |
|
| 687 |
delivery_delay = adjust_delivery_time(current_time, shipping_delay+delivery_delay)
|
- |
|
| 688 |
#Otg is currently available to both type of users.
|
- |
|
| 689 |
order.otg = costingAndDeliveryEstimateObj.otgAvailable
|
- |
|
| 690 |
|
- |
|
| 691 |
#If RQuick Surface then dont change shipping details
|
- |
|
| 692 |
if order.logistics_provider_id != 48:
|
- |
|
| 693 |
order.logistics_provider_id = costingAndDeliveryEstimateObj.logistics_provider_id
|
- |
|
| 694 |
#Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
|
- |
|
| 695 |
#order.airwaybill_no = logistics_info.airway_billno
|
- |
|
| 696 |
#order.tracking_id = order.airwaybill_no
|
- |
|
| 697 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
- |
|
| 698 |
#TODO APR2516 Promised Delivery Time should also consider delivery delay.
|
- |
|
| 699 |
order.courier_delivery_time = (current_time + datetime.timedelta(days=delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 700 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 701 |
order.promised_shipping_time = order.expected_shipping_time
|
- |
|
| 702 |
order.expected_delivery_time = (current_time + datetime.timedelta(days=deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 703 |
order.promised_delivery_time = order.expected_delivery_time
|
- |
|
| 704 |
itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 2)
|
- |
|
| 705 |
logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
|
- |
|
| 706 |
order.lineitems[0].logisticsCost = itemLevelLogisticsCost
|
- |
|
| 707 |
order.lineitems[0].codCollectionCharges = 0
|
- |
|
| 708 |
|
- |
|
| 709 |
orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
|
- |
|
| 710 |
|
- |
|
| 711 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
650 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
| 712 |
expectedDelayMap = {}
|
651 |
expectedDelayMap = {}
|
| 713 |
billingWarehouseIdMap = {}
|
652 |
billingWarehouseIdMap = {}
|
| 714 |
billingWarehouseTxnMap = {}
|
653 |
billingWarehouseTxnMap = {}
|
| 715 |
subOrderAmountsMap = {}
|
654 |
subOrderAmountsMap = {}
|
| Line 762... |
Line 701... |
| 762 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
701 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 763 |
order.lineitems[0].nlc = item_pricing.nlc
|
702 |
order.lineitems[0].nlc = item_pricing.nlc
|
| 764 |
except:
|
703 |
except:
|
| 765 |
print "Not able to get transfer price. Skipping"
|
704 |
print "Not able to get transfer price. Skipping"
|
| 766 |
|
705 |
|
| 767 |
for billingWarehouseId, orders in billingWarehouseIdMap.items():
|
- |
|
| 768 |
logistics_client = LogisticsClient().get_client()
|
- |
|
| 769 |
transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
|
- |
|
| 770 |
costingAndDeliveryEstimateObj = None
|
- |
|
| 771 |
try:
|
- |
|
| 772 |
costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, True, transactionWeight, billingWarehouseId, False)
|
- |
|
| 773 |
except:
|
- |
|
| 774 |
try:
|
- |
|
| 775 |
subOrderAmountsList = sorted(subOrderAmountsMap.keys())
|
- |
|
| 776 |
maxUnitPriceOrder = subOrderAmountsMap.get(subOrderAmountsList[len(subOrderAmountsList)-1])
|
- |
|
| 777 |
costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, maxUnitPriceOrder.lineitems[0].unit_price, True, maxUnitPriceOrder.lineitems[0].unit_weight, billingWarehouseId, False)
|
- |
|
| 778 |
except:
|
- |
|
| 779 |
raise TransactionServiceException(108, "No Logistics Provider Assigned")
|
- |
|
| 780 |
|
- |
|
| 781 |
current_time = datetime.datetime.now()
|
- |
|
| 782 |
logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
|
- |
|
| 783 |
logisticsCostInOrders = 0
|
- |
|
| 784 |
codCollectionCharges = costingAndDeliveryEstimateObj.codCollectionCharges
|
- |
|
| 785 |
codCollectionChargesInOrders = 0
|
- |
|
| 786 |
#delivery_delay
|
- |
|
| 787 |
for order in orders:
|
- |
|
| 788 |
deliveryTime = costingAndDeliveryEstimateObj.deliveryTime
|
- |
|
| 789 |
shippingTime = costingAndDeliveryEstimateObj.shippingTime
|
- |
|
| 790 |
delivery_delay = costingAndDeliveryEstimateObj.delivery_delay
|
- |
|
| 791 |
expectedDelay = expectedDelayMap.get(order.lineitems[0].item_id)
|
- |
|
| 792 |
shipping_delay = 24 * expectedDelay
|
- |
|
| 793 |
if shipping_delay < 0:
|
- |
|
| 794 |
shipping_delay = shippingTime
|
- |
|
| 795 |
else:
|
- |
|
| 796 |
shipping_delay = shipping_delay + 24 * shippingTime
|
- |
|
| 797 |
shipping_delay = int(math.ceil(shipping_delay/24.0))
|
- |
|
| 798 |
deliveryTime = adjust_delivery_time(current_time, deliveryTime+shipping_delay)
|
- |
|
| 799 |
shippingTime = adjust_delivery_time(current_time, shipping_delay)
|
- |
|
| 800 |
delivery_delay = adjust_delivery_time(current_time, shipping_delay+delivery_delay)
|
- |
|
| 801 |
order.otg = costingAndDeliveryEstimateObj.otgAvailable
|
- |
|
| 802 |
|
- |
|
| 803 |
order.logistics_provider_id = costingAndDeliveryEstimateObj.logistics_provider_id
|
- |
|
| 804 |
#Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
|
- |
|
| 805 |
#order.airwaybill_no = logistics_info.airway_billno
|
- |
|
| 806 |
#order.tracking_id = order.airwaybill_no
|
- |
|
| 807 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
- |
|
| 808 |
order.courier_delivery_time = (current_time + datetime.timedelta(days=delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 809 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 810 |
order.promised_shipping_time = order.expected_shipping_time
|
- |
|
| 811 |
order.expected_delivery_time = (current_time + datetime.timedelta(days=deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 812 |
order.promised_delivery_time = order.expected_delivery_time
|
- |
|
| 813 |
itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 2)
|
- |
|
| 814 |
logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
|
- |
|
| 815 |
itemLevelCodCollectionCharges = round((order.total_amount *codCollectionCharges)/transactionAmount, 2)
|
- |
|
| 816 |
codCollectionChargesInOrders = codCollectionChargesInOrders + itemLevelCodCollectionCharges
|
- |
|
| 817 |
order.lineitems[0].logisticsCost = itemLevelLogisticsCost
|
- |
|
| 818 |
order.lineitems[0].codCollectionCharges = itemLevelCodCollectionCharges
|
- |
|
| 819 |
|
- |
|
| 820 |
orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
|
- |
|
| 821 |
orders[0].lineitems[0].codCollectionCharges = orders[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)
|
- |
|
| 822 |
session.commit()
|
706 |
session.commit()
|
| 823 |
|
707 |
|
| 824 |
if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
|
708 |
if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
|
| 825 |
try:
|
709 |
try:
|
| 826 |
if order.source == OrderSource.WEBSITE:
|
710 |
if order.source == OrderSource.WEBSITE:
|
| Line 832... |
Line 716... |
| 832 |
elif new_status == TransactionStatus.FLAGGED:
|
716 |
elif new_status == TransactionStatus.FLAGGED:
|
| 833 |
transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
|
717 |
transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
|
| 834 |
transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
|
718 |
transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
|
| 835 |
transaction_requiring_extra_processing.transaction_id = transaction_id
|
719 |
transaction_requiring_extra_processing.transaction_id = transaction_id
|
| 836 |
session.commit()
|
720 |
session.commit()
|
| 837 |
elif order.source == OrderSource.STORE:
|
- |
|
| 838 |
order.otg = False
|
- |
|
| 839 |
session.commit()
|
- |
|
| 840 |
catalog_client = CatalogClient().get_client()
|
- |
|
| 841 |
sourcePricing = catalog_client.getStorePricing(order.lineitems[0].item_id)
|
- |
|
| 842 |
if order.total_amount >= sourcePricing.minPrice:
|
- |
|
| 843 |
order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
|
- |
|
| 844 |
order.statusDescription = "Order Accepted"
|
- |
|
| 845 |
session.commit()
|
- |
|
| 846 |
sod = StoreOrderDetail.get_by(orderId = order.id)
|
- |
|
| 847 |
__push_store_collection_to_hotspot(order, "advance", sod.cashAmount, sod.cardAmount)
|
- |
|
| 848 |
|
- |
|
| 849 |
else:
|
- |
|
| 850 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
- |
|
| 851 |
order.statusDescription = "Approval Pending"
|
- |
|
| 852 |
content = "<html><body>"
|
- |
|
| 853 |
content += "<h4>Order Id: " + str(order.id) + "</h4>"
|
- |
|
| 854 |
content += "<h4>Product: " + str(order.lineitems[0]) + "</h4>"
|
- |
|
| 855 |
content += "<h4>Min Price: " + str(sourcePricing.minPrice) + "</h4>"
|
- |
|
| 856 |
content += "<h4>Recommended Price: " + str(sourcePricing.recommendedPrice) + "</h4>"
|
- |
|
| 857 |
content += "<h2>Approval Requested for Price: " + str(order.total_amount) + "</h2>"
|
- |
|
| 858 |
content += "<h2>Note 1: If this discount price is approved then reply 'Approved' otherwise 'Not Approved' without changing anythig in the Mail.</h2>"
|
- |
|
| 859 |
content += "<h2>Note 2: For Quick approval using browser <a href='http://support.shop2020.in:8080/Support/price-approval?xszbg=" + base64.b64encode(str(order.id)) + "'>Click Here</a></h2>"
|
- |
|
| 860 |
content += "<br><br></body></html>"
|
- |
|
| 861 |
store = get_hotspot_store(order.storeId, "")
|
- |
|
| 862 |
helper_client = HelperClient().get_client()
|
- |
|
| 863 |
helper_client.saveUserEmailForSending(store.approvalEmail.split(';'), SaholicHelpEmailId, "Price approval requested for " + str(order.lineitems[0]) + " order Id " + str(order.id) + " in store " + store.hotspotId , content, str(transaction_id), "PriceApproval", [], [], 1)
|
- |
|
| 864 |
session.commit()
|
- |
|
| 865 |
else:
|
721 |
else:
|
| 866 |
order.otg = False
|
722 |
order.otg = False
|
| 867 |
session.commit()
|
723 |
session.commit()
|
| 868 |
except Exception as e:
|
724 |
except Exception as e:
|
| 869 |
print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
|
725 |
print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
|
| Line 10030... |
Line 9886... |
| 10030 |
session.commit()
|
9886 |
session.commit()
|
| 10031 |
return True
|
9887 |
return True
|
| 10032 |
|
9888 |
|
| 10033 |
def logisticsProviderFinalCheck(ordersList):
|
9889 |
def logisticsProviderFinalCheck(ordersList):
|
| 10034 |
return ordersList
|
9890 |
return ordersList
|
| 10035 |
#TODO: Primary logic for provider assignment will suffice no need to reassign.
|
- |
|
| 10036 |
shipmentAmount = 0
|
- |
|
| 10037 |
shipmentWeight = 0
|
- |
|
| 10038 |
isCod = False
|
- |
|
| 10039 |
if ordersList[0].cod:
|
- |
|
| 10040 |
isCod = True
|
- |
|
| 10041 |
|
- |
|
| 10042 |
if ordersList[0].logistics_provider_in [4, 5]:
|
- |
|
| 10043 |
return ordersList
|
- |
|
| 10044 |
|
- |
|
| 10045 |
for order in ordersList:
|
- |
|
| 10046 |
shipmentAmount = shipmentAmount + order.total_amount
|
- |
|
| 10047 |
shipmentWeight = shipmentWeight + order.total_weight
|
- |
|
| 10048 |
|
- |
|
| 10049 |
logistics_client = LogisticsClient().get_client()
|
- |
|
| 10050 |
costingAndDeliveryEstimateObj = None
|
- |
|
| 10051 |
try:
|
- |
|
| 10052 |
costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(ordersList[0].customer_pincode, shipmentAmount, isCod, shipmentWeight, ordersList[0].warehouse_id, False)
|
- |
|
| 10053 |
except:
|
- |
|
| 10054 |
raise TransactionServiceException(227, "No Provider Assigned for these orders. Please select less orders.")
|
- |
|
| 10055 |
|
- |
|
| 10056 |
logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
|
- |
|
| 10057 |
logisticsCostInOrders = 0
|
- |
|
| 10058 |
codCollectionCharges = costingAndDeliveryEstimateObj.codCollectionCharges
|
- |
|
| 10059 |
codCollectionChargesInOrders = 0
|
- |
|
| 10060 |
for order in ordersList:
|
- |
|
| 10061 |
current_time = order.created_timestamp
|
- |
|
| 10062 |
deliveryTime = costingAndDeliveryEstimateObj.deliveryTime
|
- |
|
| 10063 |
shippingTime = costingAndDeliveryEstimateObj.shippingTime
|
- |
|
| 10064 |
delivery_delay = costingAndDeliveryEstimateObj.delivery_delay
|
- |
|
| 10065 |
shipping_delay = 24 * shippingTime
|
- |
|
| 10066 |
shipping_delay = int(math.ceil(shipping_delay/24.0))
|
- |
|
| 10067 |
deliveryTime = adjust_delivery_time(current_time, deliveryTime+shipping_delay)
|
- |
|
| 10068 |
shippingTime = adjust_delivery_time(current_time, shipping_delay)
|
- |
|
| 10069 |
delivery_delay = adjust_delivery_time(current_time, shipping_delay+delivery_delay)
|
- |
|
| 10070 |
order.otg = costingAndDeliveryEstimateObj.otgAvailable
|
- |
|
| 10071 |
|
- |
|
| 10072 |
order.logistics_provider_id = costingAndDeliveryEstimateObj.logistics_provider_id
|
- |
|
| 10073 |
#Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
|
- |
|
| 10074 |
#order.airwaybill_no = logistics_info.airway_billno
|
- |
|
| 10075 |
#order.tracking_id = order.airwaybill_no
|
- |
|
| 10076 |
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
|
- |
|
| 10077 |
order.courier_delivery_time = (current_time + datetime.timedelta(days=delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 10078 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 10079 |
order.promised_shipping_time = order.expected_shipping_time
|
- |
|
| 10080 |
order.expected_delivery_time = (current_time + datetime.timedelta(days=deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
- |
|
| 10081 |
order.promised_delivery_time = order.expected_delivery_time
|
- |
|
| 10082 |
itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/shipmentWeight, 2)
|
- |
|
| 10083 |
logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
|
- |
|
| 10084 |
if codCollectionCharges >0:
|
- |
|
| 10085 |
itemLevelCodCollectionCharges = round((order.total_amount *codCollectionCharges)/shipmentAmount, 2)
|
- |
|
| 10086 |
codCollectionChargesInOrders = codCollectionChargesInOrders + itemLevelCodCollectionCharges
|
- |
|
| 10087 |
order.lineitems[0].codCollectionCharges = itemLevelCodCollectionCharges
|
- |
|
| 10088 |
order.lineitems[0].logisticsCost = itemLevelLogisticsCost
|
- |
|
| 10089 |
|
- |
|
| 10090 |
|
- |
|
| 10091 |
ordersList[0].lineitems[0].logisticsCost = ordersList[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
|
- |
|
| 10092 |
if codCollectionCharges>0:
|
- |
|
| 10093 |
ordersList[0].lineitems[0].codCollectionCharges = ordersList[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)
|
- |
|
| 10094 |
session.commit()
|
- |
|
| 10095 |
|
- |
|
| 10096 |
return ordersList
|
- |
|
| 10097 |
|
9891 |
|
| 10098 |
def __create_return_order_info(order, status, quantity=0):
|
9892 |
def __create_return_order_info(order, status, quantity=0):
|
| 10099 |
returnOrderInfo = ReturnOrderInfo()
|
9893 |
returnOrderInfo = ReturnOrderInfo()
|
| 10100 |
returnOrderInfo.orderId = order.id
|
9894 |
returnOrderInfo.orderId = order.id
|
| 10101 |
returnOrderInfo.lineItemId = order.lineitems[0].id
|
9895 |
returnOrderInfo.lineItemId = order.lineitems[0].id
|