Subversion Repositories SmartDukaan

Rev

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

Rev 24262 Rev 24907
Line 3489... Line 3489...
3489
    # For orders that are cancelled after being billed, we need to scan in the scanned out
3489
    # For orders that are cancelled after being billed, we need to scan in the scanned out
3490
    # inventory item and change availability accordingly
3490
    # inventory item and change availability accordingly
3491
    inventoryClient = InventoryClient().get_client()
3491
    inventoryClient = InventoryClient().get_client()
3492
    warehouse = inventoryClient.getWarehouse(order.warehouse_id)
3492
    warehouse = inventoryClient.getWarehouse(order.warehouse_id)
3493
    if warehouse.billingType == BillingType.OURS or warehouse.billingType == BillingType.OURS_EXTERNAL:
3493
    if warehouse.billingType == BillingType.OURS or warehouse.billingType == BillingType.OURS_EXTERNAL:
-
 
3494
        #Now BILLED orders can also be refunded directly with low inventory cancellations 
-
 
3495
        if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]:
-
 
3496
            __create_refund(order, order.wallet_amount, reason)
3494
        if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH] or (order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED and order.previousStatus in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]):
3497
        if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH] or (order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED and order.previousStatus in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]):
3495
            lineitem = order.lineitems[0]
3498
            lineitem = order.lineitems[0]
3496
            catalogClient = CatalogClient().get_client()
3499
            catalogClient = CatalogClient().get_client()
3497
            item = catalogClient.getItem(lineitem.item_id)
3500
            item = catalogClient.getItem(lineitem.item_id)
3498
            warehouseClient = WarehouseClient().get_client()
3501
            warehouseClient = WarehouseClient().get_client()
Line 11158... Line 11161...
11158
    return True
11161
    return True
11159
    
11162
    
11160
 
11163
 
11161
 
11164
 
11162
 
11165
 
-
 
11166
def process_failed_payment(new_status, transaction_id, description, sourceId, pickUp):
-
 
11167
    logging.info("########change transaction status called" + str(transaction_id))
-
 
11168
    transaction = get_transaction(transaction_id)
-
 
11169
    
-
 
11170
    transaction.status = new_status
-
 
11171
    transaction.status_message = description
-
 
11172
    order = transaction.orders[0]
-
 
11173
    expectedDelayMap = {}
-
 
11174
    billingWarehouseIdMap = {}
-
 
11175
    billingWarehouseTxnMap = {}
-
 
11176
    
-
 
11177
    
-
 
11178
    
-
 
11179
    if new_status == TransactionStatus.FAILED:
-
 
11180
        for order in transaction.orders:
-
 
11181
            order.status = OrderStatus.PAYMENT_FAILED
-
 
11182
            order.statusDescription = "Payment Failed"
-
 
11183
    elif new_status == TransactionStatus.AUTHORIZED or new_status == TransactionStatus.FLAGGED:                  
-
 
11184
        user_client = UserClient().get_client()
-
 
11185
        catalog_client = CatalogClient().get_client()
-
 
11186
        
-
 
11187
        pdu = user_client.getPrivateDealUser(transaction.orders[0].customer_id)
-
 
11188
        print "pdu.isFofo----", pdu.isFofo
-
 
11189
        fofoWarehousesMap = {} 
-
 
11190
        if pdu.isFofo:
-
 
11191
            fofoDealMap = catalog_client.getAllFofoDeals([order.lineitems[0].item_id], [4,7])
-
 
11192
            if fofoDealMap:
-
 
11193
                itemIds = []
-
 
11194
                for order in transaction.orders:
-
 
11195
                    itemIds.append(order.lineitems[0].item_id)
-
 
11196
                inventory_client = InventoryClient().get_client()
-
 
11197
                print "calling getFofoFulFillmentWarehouseMap" 
-
 
11198
                fofoWarehousesMap = inventory_client.getFofoFulFillmentWarehouseMap(itemIds)
-
 
11199
                print "called getFofoFulFillmentWarehouseMap" 
-
 
11200
        
-
 
11201
 
-
 
11202
        expectedDelayMap = {}
-
 
11203
        billingWarehouseIdMap = {}
-
 
11204
        billingWarehouseTxnMap = {}
-
 
11205
        subOrderAmountsMap = {}       
-
 
11206
        for order in transaction.orders:
-
 
11207
            if new_status == TransactionStatus.AUTHORIZED:
-
 
11208
                order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
-
 
11209
                order.statusDescription = "Submitted to warehouse"
-
 
11210
            elif new_status == TransactionStatus.FLAGGED:
-
 
11211
                order.status = OrderStatus.PAYMENT_FLAGGED
-
 
11212
                order.statusDescription = "Payment flagged by gateway"
-
 
11213
            order.cod = False
-
 
11214
            #Order type cant be changed during authorization
-
 
11215
            #if orderType is not None:
-
 
11216
            #    order.orderType = orderType
-
 
11217
            #After we got payment success, we will set logistics info also 
-
 
11218
            logistics_client = LogisticsClient().get_client()
-
 
11219
            #FIXME line item is only one now. If multiple will come, need to fix.
-
 
11220
            item_id = order.lineitems[0].item_id
-
 
11221
            if pickUp == PickUpType.RUNNER or pickUp == PickUpType.SELF:
-
 
11222
                current_time = datetime.datetime.now()
-
 
11223
                if pdu.isFofo:
-
 
11224
                    stateMaster = fetchStateMaster()
-
 
11225
                    stateId = -1
-
 
11226
                    for k, v in stateMaster.iteritems():
-
 
11227
                        if v.stateName == order.customer_state:
-
 
11228
                            stateId = k
-
 
11229
                            break
-
 
11230
                    logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp, stateId)
-
 
11231
                else:
-
 
11232
                    logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID, pickUp, -1)
-
 
11233
                order.logistics_provider_id = logistics_info.providerId
-
 
11234
                
-
 
11235
                order.warehouse_id = logistics_info.warehouseId
-
 
11236
                order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
-
 
11237
                
-
 
11238
                logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
-
 
11239
                logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
-
 
11240
                logistics_info.deliveryDelay = adjust_delivery_time(current_time, (logistics_info.shippingTime+logistics_info.deliveryDelay))
-
 
11241
                
-
 
11242
                order.courier_delivery_time = (current_time + datetime.timedelta(days=logistics_info.deliveryDelay)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
11243
                order.expected_shipping_time = (current_time + datetime.timedelta(days=logistics_info.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
11244
                order.promised_shipping_time = order.expected_shipping_time
-
 
11245
                order.expected_delivery_time = (current_time + datetime.timedelta(days=logistics_info.deliveryTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
-
 
11246
                order.promised_delivery_time = order.expected_delivery_time
-
 
11247
                order.otg = False
-
 
11248
                
-
 
11249
                    
-
 
11250
                inventory_client = InventoryClient().get_client()
-
 
11251
                    
-
 
11252
                if order.productCondition != ProductCondition.BAD:
-
 
11253
                    inventory_client.reserveItemInWarehouse(item_id, order.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
-
 
11254
 
-
 
11255
            elif order.source == OrderSource.WEBSITE:
-
 
11256
                try:
-
 
11257
                    #Get the id and location of actual warehouse that'll be used to fulfil this order.
-
 
11258
                    inventory_client = InventoryClient().get_client()
-
 
11259
                    fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1, -1)
-
 
11260
                except Exception as ex:
-
 
11261
                    raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
-
 
11262
                
-
 
11263
                expectedDelayMap[item_id] = expected_delay
-
 
11264
                if billingWarehouseIdMap.has_key(billingWarehouseId):
-
 
11265
                    ordersList = billingWarehouseIdMap.get(billingWarehouseId)
-
 
11266
                    ordersList.append(order)
-
 
11267
                    billingWarehouseIdMap[billingWarehouseId] = ordersList
-
 
11268
                else:
-
 
11269
                    ordersList = []
-
 
11270
                    ordersList.append(order)
-
 
11271
                    billingWarehouseIdMap[billingWarehouseId] = ordersList
-
 
11272
                    
-
 
11273
                if billingWarehouseTxnMap.has_key(billingWarehouseId):
-
 
11274
                    transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
-
 
11275
                    transactionAmount = transactionAmount+order.total_amount
-
 
11276
                    transactionWeight = transactionWeight+order.total_weight
-
 
11277
                    billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
-
 
11278
                else:
-
 
11279
                    billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
-
 
11280
                    
-
 
11281
                subOrderAmountsMap[long(order.lineitems[0].unit_price)] = order
-
 
11282
                    
-
 
11283
                order.fulfilmentWarehouseId = fulfilmentWhId
-
 
11284
                order.warehouse_id = billingWarehouseId
-
 
11285
                
-
 
11286
                    
-
 
11287
                if order.productCondition != ProductCondition.BAD:
-
 
11288
                    inventory_client.reserveItemInWarehouse(item_id, order.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
-
 
11289
        
-
 
11290
            try:
-
 
11291
                item_pricing = inventory_client.getItemPricing(item_id, -1)
-
 
11292
                order.lineitems[0].transfer_price = item_pricing.transferPrice
-
 
11293
                order.lineitems[0].nlc = item_pricing.nlc
-
 
11294
            except:
-
 
11295
                print "Not able to get transfer price. Skipping"
-
 
11296
            
-
 
11297
    elif new_status == TransactionStatus.COD_IN_PROCESS:
-
 
11298
        expectedDelayMap = {}
-
 
11299
        billingWarehouseIdMap = {}
-
 
11300
        billingWarehouseTxnMap = {}
-
 
11301
        subOrderAmountsMap = {}
-
 
11302
        for order in transaction.orders:
-
 
11303
            order.status = OrderStatus.COD_VERIFICATION_PENDING
-
 
11304
            order.statusDescription = "Verification Pending"
-
 
11305
            order.cod = True
-
 
11306
            #OrderType cant be changed
-
 
11307
            #order.orderType = orderType
-
 
11308
            #After we got payment success, we will set logistics info also 
-
 
11309
            logistics_client = LogisticsClient().get_client()
-
 
11310
            #FIXME line item is only one now. If multiple will come, need to fix.
-
 
11311
            item_id = order.lineitems[0].item_id
-
 
11312
                        
-
 
11313
            try:
-
 
11314
                #Get the id and location of actual warehouse that'll be used to fulfil this order.
-
 
11315
                inventory_client = InventoryClient().get_client()
-
 
11316
                fulfilmentWhId, expected_delay, billingWarehouseId, sellingPrice, totalAvailability, weight = inventory_client.getItemAvailabilityAtLocation(item_id, 1, -1)
-
 
11317
            except Exception as ex:
-
 
11318
                raise TransactionServiceException(103, "Unable to fetch inventory information about this item.")
-
 
11319
            
-
 
11320
            expectedDelayMap[item_id] = expected_delay
-
 
11321
            if billingWarehouseIdMap.has_key(billingWarehouseId):
-
 
11322
                ordersList = billingWarehouseIdMap.get(billingWarehouseId)
-
 
11323
                ordersList.append(order)
-
 
11324
                billingWarehouseIdMap[billingWarehouseId] = ordersList
-
 
11325
            else:
-
 
11326
                ordersList = []
-
 
11327
                ordersList.append(order)
-
 
11328
                billingWarehouseIdMap[billingWarehouseId] = ordersList
-
 
11329
                
-
 
11330
            if billingWarehouseTxnMap.has_key(billingWarehouseId):
-
 
11331
                transactionAmount , transactionWeight = billingWarehouseTxnMap.get(billingWarehouseId)
-
 
11332
                transactionAmount = transactionAmount+order.total_amount
-
 
11333
                transactionWeight = transactionWeight+order.total_weight
-
 
11334
                billingWarehouseTxnMap[billingWarehouseId] = transactionAmount , transactionWeight
-
 
11335
            else:
-
 
11336
                billingWarehouseTxnMap[billingWarehouseId] = order.total_amount , order.total_weight
-
 
11337
                
-
 
11338
            subOrderAmountsMap[long(order.lineitems[0].unit_price)] = order
-
 
11339
                
-
 
11340
            order.fulfilmentWarehouseId = fulfilmentWhId
-
 
11341
            order.warehouse_id = billingWarehouseId
-
 
11342
                            
-
 
11343
            if order.productCondition != ProductCondition.BAD:
-
 
11344
                inventory_client.reserveItemInWarehouse(item_id, order.fulfilmentWarehouseId, sourceId, order.id, to_java_date(order.created_timestamp), to_java_date(order.promised_shipping_time), order.lineitems[0].quantity)
-
 
11345
                                
-
 
11346
            try:
-
 
11347
                item_pricing = inventory_client.getItemPricing(item_id, -1)
-
 
11348
                order.lineitems[0].transfer_price = item_pricing.transferPrice
-
 
11349
                order.lineitems[0].nlc = item_pricing.nlc        
-
 
11350
            except:
-
 
11351
                print "Not able to get transfer price. Skipping"
-
 
11352
            
-
 
11353
    session.commit()
-
 
11354
 
-
 
11355
    if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
-
 
11356
        try:
-
 
11357
            if order.source == OrderSource.WEBSITE:    
-
 
11358
                if new_status == TransactionStatus.COD_IN_PROCESS:
-
 
11359
                    transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
-
 
11360
                    transaction_requiring_extra_processing.category = 'COD_VERIFICATION'
-
 
11361
                    transaction_requiring_extra_processing.transaction_id = transaction_id
-
 
11362
                    session.commit()
-
 
11363
                elif new_status == TransactionStatus.FLAGGED:
-
 
11364
                    transaction_requiring_extra_processing = TransactionRequiringExtraProcessing()
-
 
11365
                    transaction_requiring_extra_processing.category = 'PAYMENT_FLAGGED'
-
 
11366
                    transaction_requiring_extra_processing.transaction_id = transaction_id
-
 
11367
                    session.commit()
-
 
11368
            else:
-
 
11369
                order.otg = False
-
 
11370
                session.commit()
-
 
11371
        except Exception as e:
-
 
11372
            print "Error inserting transaction Id: " + str(transaction_id) + " due to " + str(e)
-
 
11373
 
-
 
11374
    return True
11163
 
11375
 
-
 
11376
    
11164
 
11377
 
11165
 
11378
 
11166
 
11379
 
11167
if __name__ == '__main__':
11380
if __name__ == '__main__':
11168
    DataService.initialize()
11381
    DataService.initialize(db_hostname="192.168.190.112")
11169
    #transaction_ids=[1030084,1030087,1030090,1030093,1030096,1030099,1030102,1030105,1030108,1030111,1030114,1030117,1030120,1030123,1030144,1030147,1030153]
11382
    #transaction_ids=[1030084,1030087,1030090,1030093,1030096,1030099,1030102,1030105,1030108,1030111,1030114,1030117,1030120,1030123,1030144,1030147,1030153]
-
 
11383
    transaction_ids=[1043579, 1043580, 1043581, 1043582, 1043584, 1043588, 1043589]
11170
    transaction_ids=[]
11384
    #transaction_ids=[1043577]
-
 
11385
    for transaction_id in transaction_ids:
-
 
11386
        process_failed_payment(TransactionStatus.AUTHORIZED, transaction_id, "Transaction Authorised", 1, PickUpType.SELF)
-
 
11387
        
-
 
11388
    
11171
#    mark_order_for_selfpickup_temp(transaction_ids)
11389
#    mark_order_for_selfpickup_temp(transaction_ids)
11172
#    get_billed_orders_for_manifest_gen(7441, 2, True)
11390
#    get_billed_orders_for_manifest_gen(7441, 2, True)
11173
#    ordersmap = {'911319502886601':1544266,'911319502890314':1544266,'x911319502903141':1544269,'x911319502916655':1544269,'x911319502950985':1544269,'x911319502836309':1544269,'x911319502972369':1544269,'x911319502950860':1544269,'x911319502918313':1544269,
11391
#    ordersmap = {'911319502886601':1544266,'911319502890314':1544266,'x911319502903141':1544269,'x911319502916655':1544269,'x911319502950985':1544269,'x911319502836309':1544269,'x911319502972369':1544269,'x911319502950860':1544269,'x911319502918313':1544269,
11174
#                 'x911319502943436':1544269,'x911319502928056':1544269,'x911319502838263':1544269,'911319502794144':1544269,'x911319502821616':1544269,'x911319502974746':1544269,'x911319502821442':1544269,'x911319502903984':1544269,'x911319502820980':1544269,
11392
#                 'x911319502943436':1544269,'x911319502928056':1544269,'x911319502838263':1544269,'911319502794144':1544269,'x911319502821616':1544269,'x911319502974746':1544269,'x911319502821442':1544269,'x911319502903984':1544269,'x911319502820980':1544269,
11175
#                 'x911319502973102':1544269,'x911319502913009':1544269,'x911319502973979':1544269,'x911319502842729':1544269,'x911319502824784':1544269,'x911319502847249':1544269,'x911319502848387':1544269,'x911319502887021':1544269,'x911319502962634':1544269,
11393
#                 'x911319502973102':1544269,'x911319502913009':1544269,'x911319502973979':1544269,'x911319502842729':1544269,'x911319502824784':1544269,'x911319502847249':1544269,'x911319502848387':1544269,'x911319502887021':1544269,'x911319502962634':1544269,