Subversion Repositories SmartDukaan

Rev

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

Rev 19490 Rev 19520
Line 1911... Line 1911...
1911
    logging.info("Accepting order no: " + str(orderId))
1911
    logging.info("Accepting order no: " + str(orderId))
1912
    order = get_order(orderId)
1912
    order = get_order(orderId)
1913
    
1913
    
1914
    ordersList = []
1914
    ordersList = []
1915
    ordersList.append(order)
1915
    ordersList.append(order)
1916
    updatedOrders = logisticsProviderFinalCheck(ordersList)
1916
    logisticsProviderFinalCheck(ordersList)
1917
    order = updatedOrders[0]
1917
    order = get_order(orderId)
1918
    logistics_client = LogisticsClient().get_client()
1918
    logistics_client = LogisticsClient().get_client()
1919
    provider = logistics_client.getProvider(order.logistics_provider_id)
1919
    provider = logistics_client.getProvider(order.logistics_provider_id)
1920
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, order.customer_pincode)
1920
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, order.customer_pincode)
1921
    
1921
    
1922
    if order.total_weight is None or order.total_weight == 0:
1922
    if order.total_weight is None or order.total_weight == 0:
Line 8315... Line 8315...
8315
        totalOrderQuantity = totalOrderQuantity + long(orderObj.lineitems[0].quantity)
8315
        totalOrderQuantity = totalOrderQuantity + long(orderObj.lineitems[0].quantity)
8316
        ordersList.append(orderObj)
8316
        ordersList.append(orderObj)
8317
        
8317
        
8318
    print orders
8318
    print orders
8319
    
8319
    
8320
    updatedOrders = logisticsProviderFinalCheck(ordersList)
8320
    logisticsProviderFinalCheck(ordersList)
8321
        
8321
        
8322
    user_client = UserClient().get_client()
8322
    user_client = UserClient().get_client()
8323
    isPrivateDealUser = user_client.isPrivateDealUser(updatedOrders[0].customer_id)
8323
    isPrivateDealUser = user_client.isPrivateDealUser(ordersList[0].customer_id)
8324
    privateDealUser = None
8324
    privateDealUser = None
8325
    if isPrivateDealUser:
8325
    if isPrivateDealUser:
8326
        privateDealUser = user_client.getPrivateDealUser(updatedOrders[0].customer_id)
8326
        privateDealUser = user_client.getPrivateDealUser(ordersList[0].customer_id)
8327
    logistics_client = LogisticsClient().get_client()
8327
    logistics_client = LogisticsClient().get_client()
-
 
8328
    singleOrder = get_order(ordersList[0].id)
8328
    provider = logistics_client.getProvider(updatedOrders[0].logistics_provider_id)
8329
    provider = logistics_client.getProvider(singleOrder.logistics_provider_id)
8329
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, updatedOrders[0].customer_pincode)
8330
    providerLimits = logistics_client.getProviderLimitDetailsForPincode(provider.id, ordersList[0].customer_pincode)
8330
    print 'Accpet Order Process Started'
8331
    print 'Accpet Order Process Started'
8331
    
8332
    
8332
    '''
8333
    '''
8333
    Check For Pre Conditions
8334
    Check For Pre Conditions
8334
    '''
8335
    '''
8335
    for order in updatedOrders:
8336
    for order in ordersList:
8336
        if order.total_weight is None or order.total_weight ==0:
8337
        if order.total_weight is None or order.total_weight ==0:
8337
            raise TransactionServiceException(208, "Weight Value Not Defined for order:- "+ str(order.id)+". Contact Category Team.")
8338
            raise TransactionServiceException(208, "Weight Value Not Defined for order:- "+ str(order.id)+". Contact Category Team.")
8338
        totalWeight = totalWeight + order.total_weight
8339
        totalWeight = totalWeight + order.total_weight
8339
        #if order.cod:
8340
        #if order.cod:
8340
        totalOrdersAmount = totalOrdersAmount + order.total_amount
8341
        totalOrdersAmount = totalOrdersAmount + order.total_amount
Line 8365... Line 8366...
8365
            
8366
            
8366
            if not order.cod:
8367
            if not order.cod:
8367
                if totalOrdersAmount > providerPrepaidLimit:
8368
                if totalOrdersAmount > providerPrepaidLimit:
8368
                    raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
8369
                    raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit))
8369
    
8370
    
8370
    for order in updatedOrders:
8371
    for order in ordersList:
8371
        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]:
8372
        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]:
8372
            if not order.cod:
8373
            if not order.cod:
8373
                if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
8374
                if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
8374
                    __capture_txn(order)
8375
                    __capture_txn(order)
8375
        break
8376
        break
Line 8380... Line 8381...
8380
    except:
8381
    except:
8381
        raise TransactionServiceException(212, "Unable to connect to Inventory System")
8382
        raise TransactionServiceException(212, "Unable to connect to Inventory System")
8382
    #conn = getDbConnection("localhost","root","shop2020","inventory")
8383
    #conn = getDbConnection("localhost","root","shop2020","inventory")
8383
    print 'Connected to Inventory DB'
8384
    print 'Connected to Inventory DB'
8384
    
8385
    
8385
    for order in updatedOrders:
8386
    for order in ordersList:
8386
        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]:
8387
        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]:
8387
            order.status = OrderStatus.ACCEPTED
8388
            order.status = OrderStatus.ACCEPTED
8388
            order.statusDescription = "Order Accepted"
8389
            order.statusDescription = "Order Accepted"
8389
            order.accepted_timestamp = datetime.datetime.now()
8390
            order.accepted_timestamp = datetime.datetime.now()
8390
            if order.source == 6 or order.source == 7 or order.source == 8:
8391
            if order.source == 6 or order.source == 7 or order.source == 8:
Line 8522... Line 8523...
8522
        logistics_client = LogisticsClient().get_client()
8523
        logistics_client = LogisticsClient().get_client()
8523
    awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
8524
    awbNumber = logistics_client.getNewEmptyAwb(provider.id, deltype, totalOrderQuantity)
8524
    '''
8525
    '''
8525
    
8526
    
8526
    txnSeqRequired = 0
8527
    txnSeqRequired = 0
8527
    txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==updatedOrders[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
8528
    txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==ordersList[0].transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
8528
    if txnShipSeq is None:
8529
    if txnShipSeq is None:
8529
        txnShipSeq = TransactionShipmentSequence()
8530
        txnShipSeq = TransactionShipmentSequence()
8530
        txnShipSeq.transactionId = updatedOrders[0].transaction_id
8531
        txnShipSeq.transactionId = ordersList[0].transaction_id
8531
        txnShipSeq.createdTimestamp = datetime.datetime.now()
8532
        txnShipSeq.createdTimestamp = datetime.datetime.now()
8532
        txnShipSeq.sequence = 1
8533
        txnShipSeq.sequence = 1
8533
        txnSeqRequired = 1
8534
        txnSeqRequired = 1
8534
    else:
8535
    else:
8535
        txnShipSeqNew = TransactionShipmentSequence()
8536
        txnShipSeqNew = TransactionShipmentSequence()
8536
        txnShipSeqNew.transactionId = txnShipSeq.transactionId
8537
        txnShipSeqNew.transactionId = txnShipSeq.transactionId
8537
        txnShipSeqNew.createdTimestamp = datetime.datetime.now()
8538
        txnShipSeqNew.createdTimestamp = datetime.datetime.now()
8538
        txnShipSeqNew.sequence = txnShipSeq.sequence + 1
8539
        txnShipSeqNew.sequence = txnShipSeq.sequence + 1
8539
        txnSeqRequired = txnShipSeq.sequence + 1    
8540
        txnSeqRequired = txnShipSeq.sequence + 1    
8540
    
8541
    
8541
    for order in updatedOrders:
8542
    for order in ordersList:
8542
        #update_order_AWB(order.id, awbNumber)
8543
        #update_order_AWB(order.id, awbNumber)
8543
        order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
8544
        order.logisticsTransactionId = str(order.transaction_id)+"-"+str(txnSeqRequired)
8544
                
8545
                
8545
    session.commit()
8546
    session.commit()
8546
    
8547
    
8547
    singleOrder = updatedOrders[0]
8548
    singleOrder = ordersList[0]
8548
    if singleOrder.orderType == OrderType.B2B:
8549
    if singleOrder.orderType == OrderType.B2B:
8549
        user_client = UserClient().get_client()
8550
        user_client = UserClient().get_client()
8550
        if user_client.isPrivateDealUser(singleOrder.customer_id):
8551
        if user_client.isPrivateDealUser(singleOrder.customer_id):
8551
            billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
8552
            billing_address = user_client.getBillingAddressForUser(singleOrder.customer_id)
8552
            if billing_address is not None:
8553
            if billing_address is not None:
Line 9844... Line 9845...
9844
                
9845
                
9845
    ordersList[0].lineitems[0].logisticsCost = ordersList[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
9846
    ordersList[0].lineitems[0].logisticsCost = ordersList[0].lineitems[0].logisticsCost + (round(logisticsCost,2)-logisticsCostInOrders)
9846
    if codCollectionCharges>0:
9847
    if codCollectionCharges>0:
9847
        ordersList[0].lineitems[0].codCollectionCharges = ordersList[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)                        
9848
        ordersList[0].lineitems[0].codCollectionCharges = ordersList[0].lineitems[0].codCollectionCharges + (round(codCollectionCharges,2)-codCollectionChargesInOrders)                        
9848
    session.commit()
9849
    session.commit()
9849
    
-
 
9850
    return ordersList  
-
 
9851
 
9850
 
9852
if __name__ == '__main__':
9851
if __name__ == '__main__':
9853
    print get_orders_by_mobile_number("9650889334")
9852
    print get_orders_by_mobile_number("9650889334")