Subversion Repositories SmartDukaan

Rev

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

Rev 7755 Rev 7968
Line 353... Line 353...
353
    session.commit()
353
    session.commit()
354
    #**Update item availability cache**#
354
    #**Update item availability cache**#
355
    clear_item_availability_cache(item_id)
355
    clear_item_availability_cache(item_id)
356
    return True
356
    return True
357
 
357
 
-
 
358
def update_reservation_for_order(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):    
-
 
359
    if not warehouse_id:
-
 
360
        raise InventoryServiceException(101, "bad warehouse_id")
-
 
361
    warehouse = get_Warehouse(warehouse_id)
-
 
362
    item_pricing = get_item_pricing(item_id, warehouse.vendor.id)
-
 
363
    if not item_pricing:
-
 
364
        raise InventoryServiceException(101, "No Pricing Info found for vendor and Item")
-
 
365
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
-
 
366
    try:
-
 
367
        new_current_inventory_snapshot = query.one()
-
 
368
    except:
-
 
369
        new_current_inventory_snapshot = CurrentInventorySnapshot()
-
 
370
        new_current_inventory_snapshot.warehouse_id = warehouse_id
-
 
371
        new_current_inventory_snapshot.item_id = item_id
-
 
372
        new_current_inventory_snapshot.availability = 0
-
 
373
        new_current_inventory_snapshot.reserved = 0
-
 
374
        
-
 
375
    new_current_inventory_snapshot.reserved = new_current_inventory_snapshot.reserved + quantity
-
 
376
    
-
 
377
    new_reservation = CurrentReservationSnapshot()
-
 
378
    new_reservation.item_id = item_id
-
 
379
    new_reservation.warehouse_id = warehouse_id
-
 
380
    new_reservation.source_id = source_id
-
 
381
    new_reservation.order_id = order_id
-
 
382
    new_reservation.created_timestamp = to_py_date(created_timestamp)
-
 
383
    new_reservation.promised_shipping_timestamp = to_py_date(promised_shipping_timestamp)
-
 
384
    new_reservation.reserved = quantity
-
 
385
    
-
 
386
    order_client = TransactionClient().get_client()
-
 
387
    order = order_client.getOrder(order_id)
-
 
388
    for lineitem in order.lineitems:
-
 
389
        query = CurrentInventorySnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id)
-
 
390
        try:
-
 
391
            current_inventory_snapshot = query.one()
-
 
392
            current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
-
 
393
            
-
 
394
            reservation = CurrentReservationSnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id, source_id = source_id, order_id = order_id).one()
-
 
395
            if reservation.reserved == quantity:
-
 
396
                reservation.delete()
-
 
397
            else:
-
 
398
                reservation.reserved -= quantity
-
 
399
            
-
 
400
            clear_item_availability_cache(lineitem.item_id)
-
 
401
            session.commit()
-
 
402
            try:
-
 
403
                if current_inventory_snapshot.reserved < 0:
-
 
404
                    item = __get_item_from_master(lineitem.item_id)
-
 
405
                    __send_alert_for_negative_reserved(item, current_inventory_snapshot.reserved, get_Warehouse(order.fulfilmentWarehouseId))
-
 
406
            except:
-
 
407
                print "Error in send negative reserved alert:", sys.exc_info()[0]
-
 
408
                return False
-
 
409
        except:
-
 
410
            print "Error in reducing reservation for item:", sys.exc_info()[0]
-
 
411
            return False
-
 
412
    session.commit()
-
 
413
    #**Update item availability cache**#
-
 
414
    clear_item_availability_cache(item_id)
-
 
415
    return True
-
 
416
 
-
 
417
 
358
def reduce_reservation_count(item_id, warehouse_id, source_id, order_id, quantity):
418
def reduce_reservation_count(item_id, warehouse_id, source_id, order_id, quantity):
359
    if not warehouse_id:
419
    if not warehouse_id:
360
        raise InventoryServiceException(101, "bad warehouse_id")
420
        raise InventoryServiceException(101, "bad warehouse_id")
361
        
421
        
362
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
422
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)