Subversion Repositories SmartDukaan

Rev

Rev 11654 | Rev 11793 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11654 Rev 11786
Line 3492... Line 3492...
3492
        actual_delivery_delay = adjust_delivery_time(order.expected_delivery_time, further_delay)
3492
        actual_delivery_delay = adjust_delivery_time(order.expected_delivery_time, further_delay)
3493
        order.expected_delivery_time = order.expected_delivery_time + datetime.timedelta(days=actual_delivery_delay)
3493
        order.expected_delivery_time = order.expected_delivery_time + datetime.timedelta(days=actual_delivery_delay)
3494
        
3494
        
3495
        actual_shipping_delay = adjust_delivery_time(order.expected_shipping_time, further_delay)
3495
        actual_shipping_delay = adjust_delivery_time(order.expected_shipping_time, further_delay)
3496
        order.expected_shipping_time = order.expected_shipping_time + datetime.timedelta(days=actual_shipping_delay)
3496
        order.expected_shipping_time = order.expected_shipping_time + datetime.timedelta(days=actual_shipping_delay)
3497
            
3497
        if order.courier_delivery_time:
3498
        order.courier_delivery_time = order.courier_delivery_time + datetime.timedelta(days=adjust_delivery_time(order.courier_delivery_time, further_delay))
3498
            order.courier_delivery_time = order.courier_delivery_time + datetime.timedelta(days=adjust_delivery_time(order.courier_delivery_time, further_delay))
3499
        
3499
        else
-
 
3500
            order.courier_delivery_time = order.expected_delivery_time + datetime.timedelta(days=adjust_delivery_time(order.expected_delivery_time, further_delay))
3500
        session.commit()
3501
        session.commit()
3501
 
3502
 
3502
        try:
3503
        try:
3503
            transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
3504
            transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
3504
            transaction_requiring_extra_processing.category = 'DELAYED_DELIVERY'
3505
            transaction_requiring_extra_processing.category = 'DELAYED_DELIVERY'
Line 6643... Line 6644...
6643
        print "order count"
6644
        print "order count"
6644
        print item[1]
6645
        print item[1]
6645
        item_ordercount[item[0]] = item[1]
6646
        item_ordercount[item[0]] = item[1]
6646
    print item_ordercount    
6647
    print item_ordercount    
6647
    return item_ordercount    
6648
    return item_ordercount    
-
 
6649
'''
-
 
6650
def change_easyship_mfn_order_txn_status(transaction_id, new_status, description, pickUp, orderType, source, shipTimestamp, deliveryTimeStamp):
-
 
6651
    transaction = get_transaction(transaction_id)
-
 
6652
    transaction.status = new_status
-
 
6653
    transaction.status_message = description
-
 
6654
    ## Assign runner in case of delhi pincodes
-
 
6655
    if transaction.orders[0].pickupStoreId:
-
 
6656
        logistics_client = LogisticsClient().get_client() 
-
 
6657
        store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
-
 
6658
        if delhi_pincodes.__contains__(store.pin):
-
 
6659
            pickUp = PickUpType.RUNNER  
-
 
6660
        
-
 
6661
    if new_status == TransactionStatus.FAILED:
-
 
6662
        for order in transaction.orders:
-
 
6663
            order.status = OrderStatus.PAYMENT_FAILED
-
 
6664
            order.statusDescription = "Payment Failed"
-
 
6665
    elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:
-
 
6666
        for order in transaction.orders:
-
 
6667
            if new_status == TransactionStatus.AUTHORIZED:
-
 
6668
                order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
-
 
6669
                order.statusDescription = "Submitted to warehouse"
-
 
6670
            elif new_status == TransactionStatus.FLAGGED:
-
 
6671
                order.status = OrderStatus.PAYMENT_FLAGGED
-
 
6672
                order.statusDescription = "Payment flagged by gateway"
-
 
6673
            order.cod = False
-
 
6674
            order.orderType = orderType
-
 
6675
            #After we got payment success, we will set logistics info also 
-
 
6676
            logistics_client = LogisticsClient().get_client()
-
 
6677
            #FIXME line item is only one now. If multiple will come, need to fix.
-
 
6678
            item_id = order.lineitems[0].item_id
-
 
6679
            logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp)
-
 
6680
            '''
-
 
6681
            current_time = datetime.datetime.now()
-
 
6682
            
-
 
6683
            logistics_info.deliveryTime = adjust_delivery_time(to_py_date(deliveryTimeStamp), 0)
-
 
6684
            logistics_info.shippingTime = adjust_delivery_time(to_py_date(shipTimestamp), 0)
-
 
6685
            logistics_info.deliveryDelay = 0
-
 
6686
            '''
-
 
6687
            
-
 
6688
            order.otg = logistics_info.otgAvailable
-
 
6689
            order.warehouse_id = logistics_info.warehouseId
-
 
6690
            order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
-
 
6691
            order.logistics_provider_id = 45
-
 
6692
            #Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
-
 
6693
            #order.airwaybill_no = logistics_info.airway_billno
-
 
6694
            #order.tracking_id = order.airwaybill_no
-
 
6695
            #End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
6696
            
-
 
6697
            order.courier_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6698
            order.expected_shipping_time = to_py_date(shipTimestamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6699
            order.promised_shipping_time = order.expected_shipping_time
-
 
6700
            order.expected_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6701
            order.promised_delivery_time = order.expected_delivery_time 
-
 
6702
            
-
 
6703
            if order.pickupStoreId:
-
 
6704
                order.otg = False
-
 
6705
                
-
 
6706
            inventory_client = InventoryClient().get_client()
-
 
6707
            if order.productCondition != ProductCondition.BAD:
-
 
6708
                inventory_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
-
 
6709
 
-
 
6710
            try:
-
 
6711
                item_pricing = inventory_client.getItemPricing(item_id, -1)
-
 
6712
                order.lineitems[0].transfer_price = item_pricing.transferPrice
-
 
6713
                order.lineitems[0].nlc = item_pricing.nlc
-
 
6714
            except:
-
 
6715
                print "Not able to get transfer price. Skipping"
-
 
6716
            
-
 
6717
            catalog_client = CatalogClient().get_client() 
-
 
6718
            voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
-
 
6719
            if voucherAmount:
-
 
6720
                __create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
-
 
6721
            #Note 2 Buy back Offer
-
 
6722
            if item_id in (7974, 7558) and transaction.coupon_code is not None and transaction.coupon_code.lower() == "note2buyback":    
-
 
6723
                order.status = OrderStatus.COD_VERIFICATION_PENDING
-
 
6724
                order.statusDescription = "Note 2 Buy Back Offer - Approval Pending from CRM Team"
-
 
6725
                order.otg = False
-
 
6726
                                
-
 
6727
    elif new_status == TransactionStatus.COD_IN_PROCESS:
-
 
6728
        for order in transaction.orders:
-
 
6729
            order.status = OrderStatus.COD_VERIFICATION_PENDING
-
 
6730
            order.statusDescription = "Verification Pending"
-
 
6731
            order.cod = True
-
 
6732
            order.orderType = orderType
-
 
6733
            #After we got payment success, we will set logistics info also 
-
 
6734
            logistics_client = LogisticsClient().get_client()
-
 
6735
            #FIXME line item is only one now. If multiple will come, need to fix.
-
 
6736
            item_id = order.lineitems[0].item_id
-
 
6737
            if order.pickupStoreId:
-
 
6738
                # Need to send prepaid awb number for store pick up orders
-
 
6739
                logistics_info = logistics_client.getLogisticsEstimation(item_id, order.customer_pincode, DeliveryType.COD)
-
 
6740
                #//Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
6741
                #prepaid_logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp)
-
 
6742
                #logistics_info.airway_billno = prepaid_logistics_info.airway_billno
-
 
6743
                #logistics_info.providerId = prepaid_logistics_info.providerId
-
 
6744
                #End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
6745
                # Will not provide OTG in pickup store
-
 
6746
                order.otg = False
-
 
6747
            else:
-
 
6748
                logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD, pickUp)
-
 
6749
                order.otg = logistics_info.otgAvailable
-
 
6750
            
-
 
6751
            '''   
-
 
6752
            current_time = datetime.datetime.now()
-
 
6753
            logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
-
 
6754
            logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
-
 
6755
            logistics_info.deliveryDelay = adjust_delivery_time(current_time, (logistics_info.shippingTime+logistics_info.deliveryDelay))
-
 
6756
            '''
-
 
6757
                
-
 
6758
            order.warehouse_id = logistics_info.warehouseId
-
 
6759
            order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
-
 
6760
            order.logistics_provider_id = 45
-
 
6761
            #Start:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
6762
            #order.airwaybill_no = logistics_info.airway_billno
-
 
6763
            #order.tracking_id = order.airwaybill_no
-
 
6764
            #End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
6765
            order.courier_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6766
            order.expected_shipping_time = to_py_date(shipTimestamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6767
            order.promised_shipping_time = order.expected_shipping_time
-
 
6768
            order.expected_delivery_time = to_py_date(deliveryTimeStamp).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
6769
            order.promised_delivery_time = order.expected_delivery_time
-
 
6770
            
-
 
6771
            inventory_client = InventoryClient().get_client()
-
 
6772
            if order.productCondition != ProductCondition.BAD:
-
 
6773
                inventory_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
-
 
6774
 
-
 
6775
            try:
-
 
6776
                item_pricing = inventory_client.getItemPricing(item_id, -1)
-
 
6777
                order.lineitems[0].transfer_price = item_pricing.transferPrice
-
 
6778
                order.lineitems[0].nlc = item_pricing.nlc        
-
 
6779
            except:
-
 
6780
                print "Not able to get transfer price. Skipping"
-
 
6781
            
-
 
6782
            catalog_client = CatalogClient().get_client()
-
 
6783
            voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
-
 
6784
            if voucherAmount:
-
 
6785
                __create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
-
 
6786
 
-
 
6787
                                    
-
 
6788
    session.commit()
-
 
6789
 
-
 
6790
    if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
-
 
6791
        try:
-
 
6792
            if order.source == OrderSource.WEBSITE:    
-
 
6793
                if new_status == TransactionStatus.COD_IN_PROCESS:
-
 
6794
                    transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
-
 
6795
                    transaction_requiring_extra_processing.category = 'COD_VERIFICATION'
-
 
6796
                    transaction_requiring_extra_processing.transaction_id = transaction_id
-
 
6797
                    session.commit()
-
 
6798
                elif new_status == TransactionStatus.FLAGGED:
-
 
6799
                    transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
-
 
6800
                    transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
-
 
6801
                    transaction_requiring_extra_processing.transaction_id = transaction_id
-
 
6802
                    session.commit()
-
 
6803
            elif order.source == OrderSource.STORE:
-
 
6804
                order.otg = False
-
 
6805
                session.commit()
-
 
6806
                catalog_client = CatalogClient().get_client() 
-
 
6807
                sourcePricing = catalog_client.getStorePricing(order.lineitems[0].item_id)
-
 
6808
                if order.total_amount >= sourcePricing.minPrice:
-
 
6809
                    order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
-
 
6810
                    order.statusDescription = "Order Accepted"
-
 
6811
                    session.commit()
-
 
6812
                    sod = StoreOrderDetail.get_by(orderId = order.id)
-
 
6813
                    __push_store_collection_to_hotspot(order, "advance", sod.cashAmount, sod.cardAmount)
-
 
6814
                    
-
 
6815
                else: 
-
 
6816
                    order.status = OrderStatus.COD_VERIFICATION_PENDING
-
 
6817
                    order.statusDescription = "Approval Pending"
-
 
6818
                    content = "<html><body>"
-
 
6819
                    content += "<h4>Order Id:  " + str(order.id) + "</h4>"
-
 
6820
                    content += "<h4>Product:  " + str(order.lineitems[0]) + "</h4>"
-
 
6821
                    content += "<h4>Min Price: " +  str(sourcePricing.minPrice) + "</h4>"
-
 
6822
                    content += "<h4>Recommended Price: " +  str(sourcePricing.recommendedPrice) + "</h4>"
-
 
6823
                    content += "<h2>Approval Requested for Price: " +  str(order.total_amount) + "</h2>"
-
 
6824
                    content += "<h2>Note 1: If this discount price is approved then reply 'Approved' otherwise 'Not Approved' without changing anythig in the Mail.</h2>"  
-
 
6825
                    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>"
-
 
6826
                    content += "<br><br></body></html>"
-
 
6827
                    store = get_hotspot_store(order.storeId, "")
-
 
6828
                    helper_client = HelperClient().get_client()
-
 
6829
                    helper_client.saveUserEmailForSending(store.approvalEmail.split(';'), "", "Price approval requested for " + str(order.lineitems[0]) + " order Id " + str(order.id) + " in store " + store.hotspotId , content, str(transaction_id), "PriceApproval", [], [], order.source)
-
 
6830
                    session.commit()
-
 
6831
            else:
-
 
6832
                order.otg = False
-
 
6833
        except Exception as e:
-
 
6834
            print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
-
 
6835
 
-
 
6836
    return True
-
 
6837
'''
6648
 
6838
 
6649
if __name__ == '__main__':
6839
if __name__ == '__main__':
6650
    print get_orders_by_mobile_number("9650889334")
6840
    print get_orders_by_mobile_number("9650889334")