Subversion Repositories SmartDukaan

Rev

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

Rev 19438 Rev 19474
Line 40... Line 40...
40
    RechargeTransaction, HotspotStore, WalletForCompany, WalletHistoryForCompany, \
40
    RechargeTransaction, HotspotStore, WalletForCompany, WalletHistoryForCompany, \
41
    FRC, OperatorSeries, SourceDetail, Company, EbayOrder, AmazonFbaSalesSnapshot, \
41
    FRC, OperatorSeries, SourceDetail, Company, EbayOrder, AmazonFbaSalesSnapshot, \
42
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
42
    AmazonOrder, StoreOrderDetail, EdcBank, StoreOrderCollection, \
43
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
43
    HotspotServiceMatrix, SnapdealOrder, FlipkartOrder, DataInsuranceDetailForOrder, \
44
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
44
    AmazonFbaOrderReturns, FlipkartAdvantageOrder, InvoiceCounterGenerator, \
45
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, LoanHistory
45
    TransactionShipmentSequence, HsOrder, Creditor, UserSanction, CreditHistory, LoanHistory, \
-
 
46
    ShipmentLogisticsCostDetail
46
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
47
from shop2020.model.v1.order.impl.model.BaseOrder import BaseOrder
47
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
48
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
48
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
49
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
49
    MobileRechargeOrder
50
    MobileRechargeOrder
50
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
51
from shop2020.model.v1.order.impl.model.RechargeDenomination import \
Line 69... Line 70...
69
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
70
    TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
70
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
71
    HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType, RechargeOrderStatus, \
71
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
72
    RechargeType, RechargeStatistics, DeviceNumberInfo, EmiChargeType, PayMethod, \
72
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
73
    OrderSource, StorePaymentStatus, ProductCondition, TaxType, \
73
    AmazonFCWarehouseLocation, RechargeMode, CreditTxnType, CreditHistory as TCreditHistory, \
74
    AmazonFCWarehouseLocation, RechargeMode, CreditTxnType, CreditHistory as TCreditHistory, \
74
    LoanHistory as TLoanHistory
75
    LoanHistory as TLoanHistory, ShipmentLogisticsCostDetail as TShipmentLogisticsCostDetail
75
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
76
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType, CouponCategory, \
76
    User, Sex
77
    User, Sex
77
from shop2020.thriftpy.payments.ttypes import PaymentException
78
from shop2020.thriftpy.payments.ttypes import PaymentException
78
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
79
from shop2020.thriftpy.utils.ttypes import UserSmsInfo, SmsType
79
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
80
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
Line 445... Line 446...
445
            order.status = OrderStatus.PAYMENT_FAILED
446
            order.status = OrderStatus.PAYMENT_FAILED
446
            order.statusDescription = "Payment Failed"
447
            order.statusDescription = "Payment Failed"
447
    elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:                  
448
    elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:                  
448
        expectedDelayMap = {}
449
        expectedDelayMap = {}
449
        billingWarehouseIdMap = {}
450
        billingWarehouseIdMap = {}
450
        billingWarehouseTxnMap = {}       
451
        billingWarehouseTxnMap = {}
-
 
452
        subOrderAmountsMap = {}       
451
        for order in transaction.orders:
453
        for order in transaction.orders:
452
            if new_status == TransactionStatus.AUTHORIZED:
454
            if new_status == TransactionStatus.AUTHORIZED:
453
                order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
455
                order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
454
                order.statusDescription = "Submitted to warehouse"
456
                order.statusDescription = "Submitted to warehouse"
455
            elif new_status == TransactionStatus.FLAGGED:
457
            elif new_status == TransactionStatus.FLAGGED:
Line 543... Line 545...
543
                    transactionWeight = transactionWeight+order.total_weight
545
                    transactionWeight = transactionWeight+order.total_weight
544
                    billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
546
                    billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
545
                else:
547
                else:
546
                    billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
548
                    billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
547
                    
549
                    
-
 
550
                subOrderAmountsMap[long(order.lineitems[0].unit_price)] = order
-
 
551
                    
548
                order.fulfilmentWarehouseId = fulfilmentWhId
552
                order.fulfilmentWarehouseId = fulfilmentWhId
549
                
553
                
550
                fulfilmentWarehouseId = fulfilmentWhId
554
                fulfilmentWarehouseId = fulfilmentWhId
551
                if OrderType.B2B == order.orderType:
555
                if OrderType.B2B == order.orderType:
552
                    #get state
556
                    #get state
Line 606... Line 610...
606
            process_credit_transaction(transaction.id, singleOrder.customer_id, 1, creditTxns)
610
            process_credit_transaction(transaction.id, singleOrder.customer_id, 1, creditTxns)
607
            
611
            
608
        for billingWarehouseId, orders in billingWarehouseIdMap.items():
612
        for billingWarehouseId, orders in billingWarehouseIdMap.items():
609
            logistics_client = LogisticsClient().get_client()
613
            logistics_client = LogisticsClient().get_client()
610
            transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
614
            transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
611
            costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, False, transactionWeight, billingWarehouseId)
615
            costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, False, transactionWeight, billingWarehouseId, False)
-
 
616
            if costingAndDeliveryEstimateObj is None:
-
 
617
                subOrderAmountsList = sorted(subOrderAmountsMap.keys())
-
 
618
                maxUnitPriceOrder = subOrderAmountsMap.get(subOrderAmountsList[len(subOrderAmountsList)-1])
-
 
619
                costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, maxUnitPriceOrder.lineitems[0].unit_price, False, maxUnitPriceOrder.lineitems[0].unit_weight, billingWarehouseId, False)
-
 
620
            if costingAndDeliveryEstimateObj is None:
-
 
621
                raise TransactionServiceException(108, "No Logistics Provider Assigned")
612
            logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
622
            logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
613
            logisticsCostInOrders = 0
623
            logisticsCostInOrders = 0
614
            current_time = datetime.datetime.now()
624
            current_time = datetime.datetime.now()
615
            #delivery_delay
625
            #delivery_delay
616
            for order in orders:
626
            for order in orders:
Line 634... Line 644...
634
                order.courier_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
644
                order.courier_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
635
                order.expected_shipping_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
645
                order.expected_shipping_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
636
                order.promised_shipping_time = order.expected_shipping_time
646
                order.promised_shipping_time = order.expected_shipping_time
637
                order.expected_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
647
                order.expected_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
638
                order.promised_delivery_time = order.expected_delivery_time
648
                order.promised_delivery_time = order.expected_delivery_time
639
                itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 0)
649
                itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 2)
640
                logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
650
                logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
641
                order.lineitems[0].logisticsCost = itemLevelLogisticsCost
651
                order.lineitems[0].logisticsCost = itemLevelLogisticsCost
642
                order.lineitems[0].codCollectionCharges = 0
652
                order.lineitems[0].codCollectionCharges = 0
643
        
653
        
644
            orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (logisticsCost-logisticsCostInOrders)
654
            orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
645
                                
655
                                
646
    elif new_status == TransactionStatus.COD_IN_PROCESS:
656
    elif new_status == TransactionStatus.COD_IN_PROCESS:
647
        expectedDelayMap = {}
657
        expectedDelayMap = {}
648
        billingWarehouseIdMap = {}
658
        billingWarehouseIdMap = {}
649
        billingWarehouseTxnMap = {}
659
        billingWarehouseTxnMap = {}
-
 
660
        subOrderAmountsMap = {}
650
        for order in transaction.orders:
661
        for order in transaction.orders:
651
            order.status = OrderStatus.COD_VERIFICATION_PENDING
662
            order.status = OrderStatus.COD_VERIFICATION_PENDING
652
            order.statusDescription = "Verification Pending"
663
            order.statusDescription = "Verification Pending"
653
            order.cod = True
664
            order.cod = True
654
            order.orderType = orderType
665
            order.orderType = orderType
Line 744... Line 755...
744
                    transactionWeight = transactionWeight+order.total_weight
755
                    transactionWeight = transactionWeight+order.total_weight
745
                    billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
756
                    billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
746
                else:
757
                else:
747
                    billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
758
                    billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
748
                    
759
                    
-
 
760
                subOrderAmountsMap[long(order.lineitems[0].unit_price)] = order
-
 
761
                    
749
                order.fulfilmentWarehouseId = fulfilmentWhId
762
                order.fulfilmentWarehouseId = fulfilmentWhId
750
                
763
                
751
                fulfilmentWarehouseId = fulfilmentWhId
764
                fulfilmentWarehouseId = fulfilmentWhId
752
                if OrderType.B2B == order.orderType:
765
                if OrderType.B2B == order.orderType:
753
                    #get state
766
                    #get state
Line 796... Line 809...
796
                __create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
809
                __create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
797
 
810
 
798
        for billingWarehouseId, orders in billingWarehouseIdMap.items():
811
        for billingWarehouseId, orders in billingWarehouseIdMap.items():
799
            logistics_client = LogisticsClient().get_client()
812
            logistics_client = LogisticsClient().get_client()
800
            transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
813
            transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
801
            costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, True, transactionWeight, billingWarehouseId)
814
            costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, transactionAmount, True, transactionWeight, billingWarehouseId, False)
-
 
815
            if costingAndDeliveryEstimateObj is None:
-
 
816
                subOrderAmountsList = sorted(subOrderAmountsMap.keys())
-
 
817
                maxUnitPriceOrder = subOrderAmountsMap.get(subOrderAmountsList[len(subOrderAmountsList)-1])
-
 
818
                costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(orders[0].customer_pincode, maxUnitPriceOrder.lineitems[0].unit_price, True, maxUnitPriceOrder.lineitems[0].unit_weight, billingWarehouseId, False)
-
 
819
            if costingAndDeliveryEstimateObj is None:
-
 
820
                raise TransactionServiceException(108, "No Logistics Provider Assigned")
-
 
821
            
802
            current_time = datetime.datetime.now()
822
            current_time = datetime.datetime.now()
803
            logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
823
            logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
804
            logisticsCostInOrders = 0
824
            logisticsCostInOrders = 0
805
            codCollectionCharges = costingAndDeliveryEstimateObj.codCollectionCharges
825
            codCollectionCharges = costingAndDeliveryEstimateObj.codCollectionCharges
806
            codCollectionChargesInOrders = 0
826
            codCollectionChargesInOrders = 0
Line 826... Line 846...
826
                order.courier_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
846
                order.courier_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
827
                order.expected_shipping_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
847
                order.expected_shipping_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
828
                order.promised_shipping_time = order.expected_shipping_time
848
                order.promised_shipping_time = order.expected_shipping_time
829
                order.expected_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
849
                order.expected_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
830
                order.promised_delivery_time = order.expected_delivery_time
850
                order.promised_delivery_time = order.expected_delivery_time
831
                itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 0)
851
                itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/transactionWeight, 2)
832
                logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
852
                logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
833
                itemLevelCodCollectionCharges = round((order.total_amount *codCollectionCharges)/transactionAmount, 0)
853
                itemLevelCodCollectionCharges = round((order.total_amount *codCollectionCharges)/transactionAmount, 2)
834
                codCollectionChargesInOrders = codCollectionChargesInOrders + itemLevelCodCollectionCharges
854
                codCollectionChargesInOrders = codCollectionChargesInOrders + itemLevelCodCollectionCharges
835
                order.lineitems[0].logisticsCost = itemLevelLogisticsCost
855
                order.lineitems[0].logisticsCost = itemLevelLogisticsCost
836
                order.lineitems[0].codCollectionCharges = itemLevelCodCollectionCharges
856
                order.lineitems[0].codCollectionCharges = itemLevelCodCollectionCharges
837
                
857
                
838
            orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (logisticsCost-logisticsCostInOrders)
858
            orders[0].lineitems[0].logisticsCost = orders[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
839
            orders[0].lineitems[0].codCollectionCharges = orders[0].lineitems[0].codCollectionCharges + (codCollectionCharges-codCollectionChargesInOrders)                        
859
            orders[0].lineitems[0].codCollectionCharges = orders[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)                        
840
    session.commit()
860
    session.commit()
841
 
861
 
842
    if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
862
    if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
843
        try:
863
        try:
844
            if order.source == OrderSource.WEBSITE:    
864
            if order.source == OrderSource.WEBSITE:    
Line 1887... Line 1907...
1887
        
1907
        
1888
def accept_order(orderId):
1908
def accept_order(orderId):
1889
    logging.info("Accepting order no: " + str(orderId))
1909
    logging.info("Accepting order no: " + str(orderId))
1890
    order = get_order(orderId)
1910
    order = get_order(orderId)
1891
    
1911
    
-
 
1912
    ordersList = []
-
 
1913
    ordersList.append(order)
-
 
1914
    updatedOrders = logisticsProviderFinalCheck(ordersList)
-
 
1915
    order = updatedOrders[0]
1892
    logistics_client = LogisticsClient().get_client()
1916
    logistics_client = LogisticsClient().get_client()
1893
    provider = logistics_client.getProvider(order.logistics_provider_id)
1917
    provider = logistics_client.getProvider(order.logistics_provider_id)
1894
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, order.customer_pincode)
1918
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, order.customer_pincode)
1895
    
1919
    
1896
    if order.total_weight is None or order.total_weight == 0:
1920
    if order.total_weight is None or order.total_weight == 0:
Line 7376... Line 7400...
7376
    order = Order.get_by(id = orderId)
7400
    order = Order.get_by(id = orderId)
7377
    order.airwaybill_no=airwayBillNo
7401
    order.airwaybill_no=airwayBillNo
7378
    order.tracking_id=airwayBillNo
7402
    order.tracking_id=airwayBillNo
7379
    #order.logisticsTransactionId = str(order.transaction_id)+airwayBillNo
7403
    #order.logisticsTransactionId = str(order.transaction_id)+airwayBillNo
7380
    session.commit()
7404
    session.commit()
-
 
7405
    shipmentLogisticsCostObj = TShipmentLogisticsCostDetail()
-
 
7406
    shipmentLogisticsCostObj.airwayBillNo = airwayBillNo
-
 
7407
    shipmentLogisticsCostObj.logisticsTransactionId = order.logisticsTransactionId
-
 
7408
    shipmentLogisticsCostObj.shipmentAmount = order.total_amount
-
 
7409
    shipmentLogisticsCostObj.shipmentCodCollectionCharges = order.lineitems[0].codCollectionCharges
-
 
7410
    shipmentLogisticsCostObj.shipmentLogsiticsCost = order.lineitems[0].logisticsCost
-
 
7411
    shipmentLogisticsCostObj.shipmentWeight = order.total_weight
-
 
7412
    
-
 
7413
    shipmentLogisticsCostDetails = []
-
 
7414
    shipmentLogisticsCostDetails.append(shipmentLogisticsCostObj)
-
 
7415
    add_or_update_shipment_logistics_cost_details(shipmentLogisticsCostObj)
7381
    return order
7416
    return order
7382
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
7417
#End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
7383
 
7418
 
7384
def get_hotspot_service_matrices():
7419
def get_hotspot_service_matrices():
7385
    hotspotServiceMatrices = HotspotServiceMatrix.query.all()
7420
    hotspotServiceMatrices = HotspotServiceMatrix.query.all()
Line 8277... Line 8312...
8277
        orderObj = Order.get_by(id=orderId)
8312
        orderObj = Order.get_by(id=orderId)
8278
        totalOrderQuantity = totalOrderQuantity + long(orderObj.lineitems[0].quantity)
8313
        totalOrderQuantity = totalOrderQuantity + long(orderObj.lineitems[0].quantity)
8279
        ordersList.append(orderObj)
8314
        ordersList.append(orderObj)
8280
        
8315
        
8281
    print orders
8316
    print orders
-
 
8317
    
-
 
8318
    updatedOrders = logisticsProviderFinalCheck(ordersList)
8282
        
8319
        
8283
    user_client = UserClient().get_client()
8320
    user_client = UserClient().get_client()
8284
    isPrivateDealUser = user_client.isPrivateDealUser(ordersList[0].customer_id)
8321
    isPrivateDealUser = user_client.isPrivateDealUser(updatedOrders[0].customer_id)
8285
    privateDealUser = None
8322
    privateDealUser = None
8286
    if isPrivateDealUser:
8323
    if isPrivateDealUser:
8287
        privateDealUser = user_client.getPrivateDealUser(ordersList[0].customer_id)
8324
        privateDealUser = user_client.getPrivateDealUser(updatedOrders[0].customer_id)
8288
    logistics_client = LogisticsClient().get_client()
8325
    logistics_client = LogisticsClient().get_client()
8289
    provider = logistics_client.getProvider(ordersList[0].logistics_provider_id)
8326
    provider = logistics_client.getProvider(updatedOrders[0].logistics_provider_id)
8290
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, ordersList[0].customer_pincode)
8327
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, updatedOrders[0].customer_pincode)
8291
    print 'Accpet Order Process Started'
8328
    print 'Accpet Order Process Started'
8292
    
8329
    
8293
    '''
8330
    '''
8294
    Check For Pre Conditions
8331
    Check For Pre Conditions
8295
    '''
8332
    '''
8296
    for order in ordersList:
8333
    for order in updatedOrders:
8297
        if order.total_weight is None or order.total_weight ==0:
8334
        if order.total_weight is None or order.total_weight ==0:
8298
            raise TransactionServiceException(208, "Weight Value Not Defined for order:- "+ str(order.id)+". Contact Category Team.")
8335
            raise TransactionServiceException(208, "Weight Value Not Defined for order:- "+ str(order.id)+". Contact Category Team.")
8299
        totalWeight = totalWeight + order.total_weight
8336
        totalWeight = totalWeight + order.total_weight
8300
        #if order.cod:
8337
        #if order.cod:
8301
        totalOrdersAmount = totalOrdersAmount + order.total_amount
8338
        totalOrdersAmount = totalOrdersAmount + order.total_amount
Line 8326... Line 8363...
8326
            
8363
            
8327
            if not order.cod:
8364
            if not order.cod:
8328
                if totalOrdersAmount > providerPrepaidLimit:
8365
                if totalOrdersAmount > providerPrepaidLimit:
8329
                    raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
8366
                    raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
8330
    
8367
    
8331
    for order in ordersList:
8368
    for order in updatedOrders:
8332
        if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
8369
        if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
8333
            if not order.cod:
8370
            if not order.cod:
8334
                if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
8371
                if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
8335
                    __capture_txn(order)
8372
                    __capture_txn(order)
8336
        break
8373
        break
Line 8341... Line 8378...
8341
    except:
8378
    except:
8342
        raise TransactionServiceException(212, "Unable to connect to Inventory System")
8379
        raise TransactionServiceException(212, "Unable to connect to Inventory System")
8343
    #conn = getDbConnection("localhost","root","shop2020","inventory")
8380
    #conn = getDbConnection("localhost","root","shop2020","inventory")
8344
    print 'Connected to Inventory DB'
8381
    print 'Connected to Inventory DB'
8345
    
8382
    
8346
    for order in ordersList:
8383
    for order in updatedOrders:
8347
        if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
8384
        if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
8348
            order.status = OrderStatus.ACCEPTED
8385
            order.status = OrderStatus.ACCEPTED
8349
            order.statusDescription = "Order Accepted"
8386
            order.statusDescription = "Order Accepted"
8350
            order.accepted_timestamp = datetime.datetime.now()
8387
            order.accepted_timestamp = datetime.datetime.now()
8351
            if order.source == 6 or order.source == 7 or order.source == 8:
8388
            if order.source == 6 or order.source == 7 or order.source == 8:
Line 8483... Line 8520...
8483
        logistics_client = LogisticsClient().get_client()
8520
        logistics_client = LogisticsClient().get_client()
8484
    awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
8521
    awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
8485
    '''
8522
    '''
8486
    
8523
    
8487
    txnSeqRequired = 0
8524
    txnSeqRequired = 0
8488
    txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==ordersList[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
8525
    txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==updatedOrders[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
8489
    if txnShipSeq is None:
8526
    if txnShipSeq is None:
8490
        txnShipSeq = TransactionShipmentSequence()
8527
        txnShipSeq = TransactionShipmentSequence()
8491
        txnShipSeq.transactionId = ordersList[0].transaction_id
8528
        txnShipSeq.transactionId = updatedOrders[0].transaction_id
8492
        txnShipSeq.createdTimestamp = datetime.datetime.now()
8529
        txnShipSeq.createdTimestamp = datetime.datetime.now()
8493
        txnShipSeq.sequence = 1
8530
        txnShipSeq.sequence = 1
8494
        txnSeqRequired = 1
8531
        txnSeqRequired = 1
8495
    else:
8532
    else:
8496
        txnShipSeqNew = TransactionShipmentSequence()
8533
        txnShipSeqNew = TransactionShipmentSequence()
8497
        txnShipSeqNew.transactionId = txnShipSeq.transactionId
8534
        txnShipSeqNew.transactionId = txnShipSeq.transactionId
8498
        txnShipSeqNew.createdTimestamp = datetime.datetime.now()
8535
        txnShipSeqNew.createdTimestamp = datetime.datetime.now()
8499
        txnShipSeqNew.sequence = txnShipSeq.sequence + 1
8536
        txnShipSeqNew.sequence = txnShipSeq.sequence + 1
8500
        txnSeqRequired = txnShipSeq.sequence + 1    
8537
        txnSeqRequired = txnShipSeq.sequence + 1    
8501
    
8538
    
8502
    for order in ordersList:
8539
    for order in updatedOrders:
8503
        #update_order_AWB(order.id, awbNumber)
8540
        #update_order_AWB(order.id, awbNumber)
8504
        order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
8541
        order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
8505
                
8542
                
8506
    session.commit()
8543
    session.commit()
8507
    
8544
    
8508
    singleOrder = ordersList[0]
8545
    singleOrder = updatedOrders[0]
8509
    if singleOrder.orderType == OrderType.B2B:
8546
    if singleOrder.orderType == OrderType.B2B:
8510
        user_client = UserClient().get_client()
8547
        user_client = UserClient().get_client()
8511
        if user_client.isPrivateDealUser(singleOrder.customer_id):
8548
        if user_client.isPrivateDealUser(singleOrder.customer_id):
8512
            billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
8549
            billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
8513
            if billing_address is not None:
8550
            if billing_address is not None:
Line 9704... Line 9741...
9704
                attr.value = attribute.value
9741
                attr.value = attribute.value
9705
    session.commit()
9742
    session.commit()
9706
 
9743
 
9707
def update_master_order_awb(logisticsTransactionId, airwaybill_no):
9744
def update_master_order_awb(logisticsTransactionId, airwaybill_no):
9708
    orders = get_group_orders_by_logistics_txn_id(logisticsTransactionId)
9745
    orders = get_group_orders_by_logistics_txn_id(logisticsTransactionId)
-
 
9746
    shipmentAmount = 0
-
 
9747
    shipmentWeight = 0
-
 
9748
    shipmentLogisticsCost = 0
-
 
9749
    shipmentCodCollectionCharges = 0
9709
    for order in orders:
9750
    for order in orders:
9710
        order.airwaybill_no = airwaybill_no
9751
        order.airwaybill_no = airwaybill_no
9711
        order.tracking_id = airwaybill_no
9752
        order.tracking_id = airwaybill_no
-
 
9753
        shipmentAmount = shipmentAmount + order.total_amount
-
 
9754
        shipmentWeight = shipmentWeight + order.total_weight
-
 
9755
        shipmentLogisticsCost = shipmentLogisticsCost + order.lineitems[0].logisticsCost
-
 
9756
        shipmentCodCollectionCharges = shipmentCodCollectionCharges + order.lineitems[0].codCollectionCharges
-
 
9757
    session.commit()
-
 
9758
    
-
 
9759
    shipmentLogisticsCostObj = TShipmentLogisticsCostDetail()
-
 
9760
    shipmentLogisticsCostObj.airwayBillNo = airwaybill_no
-
 
9761
    shipmentLogisticsCostObj.logisticsTransactionId = logisticsTransactionId
-
 
9762
    shipmentLogisticsCostObj.shipmentAmount = shipmentAmount
-
 
9763
    shipmentLogisticsCostObj.shipmentCodCollectionCharges = shipmentCodCollectionCharges
-
 
9764
    shipmentLogisticsCostObj.shipmentLogsiticsCost = shipmentLogisticsCost
-
 
9765
    shipmentLogisticsCostObj.shipmentWeight = shipmentWeight
-
 
9766
    
-
 
9767
    shipmentLogisticsCostDetails = []
-
 
9768
    shipmentLogisticsCostDetails.append(shipmentLogisticsCostObj)
-
 
9769
    add_or_update_shipment_logistics_cost_details(shipmentLogisticsCostObj)
-
 
9770
    
-
 
9771
    return True
-
 
9772
 
-
 
9773
def add_or_update_shipment_logistics_cost_details(shipmentLogisticsCostDetails):
-
 
9774
    currentTime = datetime.datetime.now()
-
 
9775
    for shipmentLogisticsCostDetail in shipmentLogisticsCostDetails:
-
 
9776
        shipment_logisticsCostDetail = ShipmentLogisticsCostDetail.get_by(logisticsTransactionId=shipmentLogisticsCostDetail.logisticsTransactionId, airwayBillNo = shipmentLogisticsCostDetail.airwayBillNo)
-
 
9777
        if shipment_logisticsCostDetail:
-
 
9778
            shipment_logisticsCostDetail.shipmentAmount = shipmentLogisticsCostDetail.shipmentAmount
-
 
9779
            shipment_logisticsCostDetail.shipmentWeight = shipmentLogisticsCostDetail.shipmentWeight
-
 
9780
            shipment_logisticsCostDetail.shipmentLogsiticsCost = shipmentLogisticsCostDetail.shipmentLogsiticsCost
-
 
9781
            shipment_logisticsCostDetail.shipmentCodCollectionCharges = shipmentLogisticsCostDetail.shipmentCodCollectionCharges
-
 
9782
            shipment_logisticsCostDetail.updatedAt = currentTime
-
 
9783
        else:
-
 
9784
            shipment_logisticsCostDetail = ShipmentLogisticsCostDetail()
-
 
9785
            shipment_logisticsCostDetail.logisticsTransactionId = shipmentLogisticsCostDetail.logisticsTransactionId
-
 
9786
            shipment_logisticsCostDetail.airwayBillNo = shipmentLogisticsCostDetail.airwayBillNo
-
 
9787
            shipment_logisticsCostDetail.shipmentAmount = shipmentLogisticsCostDetail.shipmentAmount
-
 
9788
            shipment_logisticsCostDetail.shipmentWeight = shipmentLogisticsCostDetail.shipmentWeight
-
 
9789
            shipment_logisticsCostDetail.shipmentLogsiticsCost = shipmentLogisticsCostDetail.shipmentLogsiticsCost
-
 
9790
            shipment_logisticsCostDetail.shipmentCodCollectionCharges = shipmentLogisticsCostDetail.shipmentCodCollectionCharges
-
 
9791
            shipment_logisticsCostDetail.updatedAt = currentTime
-
 
9792
            
-
 
9793
    session.commit()
-
 
9794
    return True
-
 
9795
 
-
 
9796
def logisticsProviderFinalCheck(ordersList):
-
 
9797
    shipmentAmount = 0
-
 
9798
    shipmentWeight = 0
-
 
9799
    isCod = False
-
 
9800
    if ordersList[0].cod:
-
 
9801
        isCod = True
-
 
9802
    
-
 
9803
    for order in ordersList:
-
 
9804
        shipmentAmount = shipmentAmount + order.total_amount
-
 
9805
        shipmentWeight = shipmentWeight + order.total_weight
-
 
9806
    
-
 
9807
    logistics_client = LogisticsClient().get_client()
-
 
9808
    costingAndDeliveryEstimateObj = logistics_client.getCostingAndDeliveryEstimateForPincode(ordersList[0].customer_pincode, shipmentAmount, isCod, shipmentWeight, ordersList[0].warehouse_id, False)
-
 
9809
    if costingAndDeliveryEstimateObj is None:
-
 
9810
        raise TransactionServiceException(227, "No Provider Assigned for these orders. Please select less orders.")
-
 
9811
    logisticsCost = costingAndDeliveryEstimateObj.logisticsCost
-
 
9812
    logisticsCostInOrders = 0
-
 
9813
    codCollectionCharges = costingAndDeliveryEstimateObj.codCollectionCharges
-
 
9814
    codCollectionChargesInOrders = 0 
-
 
9815
    for order in ordersList:
-
 
9816
        current_time = order.created_timestamp
-
 
9817
        shipping_delay = 24 * costingAndDeliveryEstimateObj.shippingTime
-
 
9818
        shipping_delay = int(math.ceil(shipping_delay/24.0))
-
 
9819
        costingAndDeliveryEstimateObj.deliveryTime = adjust_delivery_time(current_time, costingAndDeliveryEstimateObj.deliveryTime+shipping_delay)
-
 
9820
        costingAndDeliveryEstimateObj.shippingTime = adjust_delivery_time(current_time, shipping_delay)
-
 
9821
        costingAndDeliveryEstimateObj.delivery_delay = adjust_delivery_time(current_time, shipping_delay+costingAndDeliveryEstimateObj.delivery_delay) 
-
 
9822
        order.otg = costingAndDeliveryEstimateObj.otgAvailable
-
 
9823
        
-
 
9824
        order.logistics_provider_id = costingAndDeliveryEstimateObj.logistics_provider_id
-
 
9825
        #Start:- Added by Manish Sharma for FedEx Integration - Shipment Creation on 31-Jul-2013
-
 
9826
        #order.airwaybill_no = logistics_info.airway_billno
-
 
9827
        #order.tracking_id = order.airwaybill_no
-
 
9828
        #End:- Added by Manish Sharma for FedEx Integration- Shipment Creation on 31-Jul-2013
-
 
9829
        order.courier_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.delivery_delay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
9830
        order.expected_shipping_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
9831
        order.promised_shipping_time = order.expected_shipping_time
-
 
9832
        order.expected_delivery_time = (current_time + datetime.timedelta(days=costingAndDeliveryEstimateObj.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
9833
        order.promised_delivery_time = order.expected_delivery_time
-
 
9834
        itemLevelLogisticsCost = round((order.total_weight *logisticsCost)/shipmentWeight, 2)
-
 
9835
        logisticsCostInOrders = logisticsCostInOrders + itemLevelLogisticsCost
-
 
9836
        if codCollectionCharges >0:
-
 
9837
            itemLevelCodCollectionCharges = round((order.total_amount *codCollectionCharges)/shipmentAmount, 2)
-
 
9838
            codCollectionChargesInOrders = codCollectionChargesInOrders + itemLevelCodCollectionCharges
-
 
9839
            order.lineitems[0].codCollectionCharges = itemLevelCodCollectionCharges
-
 
9840
        order.lineitems[0].logisticsCost = itemLevelLogisticsCost
-
 
9841
        
-
 
9842
                
-
 
9843
    ordersList[0].lineitems[0].logisticsCost = ordersList[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
-
 
9844
    if codCollectionCharges>0:
-
 
9845
        ordersList[0].lineitems[0].codCollectionCharges = ordersList[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)                        
9712
    session.commit()
9846
    session.commit()
-
 
9847
    
9713
    return True    
9848
    return ordersList  
9714
 
9849
 
9715
if __name__ == '__main__':
9850
if __name__ == '__main__':
9716
    print get_orders_by_mobile_number("9650889334")
9851
    print get_orders_by_mobile_number("9650889334")