Subversion Repositories SmartDukaan

Rev

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

Rev 2248 Rev 2251
Line 164... Line 164...
164
    
164
    
165
    ds_item.bestDealText = item.bestDealText
165
    ds_item.bestDealText = item.bestDealText
166
    ds_item.bestDealValue = item.bestDealValue
166
    ds_item.bestDealValue = item.bestDealValue
167
    ds_item.bestSellingRank = item.bestSellingRank
167
    ds_item.bestSellingRank = item.bestSellingRank
168
    ds_item.defaultForEntity = item.defaultForEntity
168
    ds_item.defaultForEntity = item.defaultForEntity
-
 
169
    ds_item.risky = item.risky
169
    ds_item.updated_on = datetime.datetime.now()
170
    ds_item.updated_on = datetime.datetime.now()
170
    
171
    
171
    session.commit();
172
    session.commit();
172
    return ds_item.id
173
    return ds_item.id
173
 
174
 
Line 249... Line 250...
249
    if item.bestDealText:
250
    if item.bestDealText:
250
        ds_item.bestDealText = item.bestDealText
251
        ds_item.bestDealText = item.bestDealText
251
    if item.bestSellingRank:
252
    if item.bestSellingRank:
252
        ds_item.bestSellingRank = item.bestSellingRank
253
        ds_item.bestSellingRank = item.bestSellingRank
253
    ds_item.defaultForEntity = item.defaultForEntity
254
    ds_item.defaultForEntity = item.defaultForEntity
-
 
255
    ds_item.risky = item.risky
254
    
256
    
255
    # Check if a similar item already exists in our database
257
    # Check if a similar item already exists in our database
256
    similar_item = Item.query.filter_by(product_group=item.productGroup, brand = item.brand, model_number=item.modelNumber, hotspotCategory=item.hotspotCategory).first()
258
    similar_item = Item.query.filter_by(product_group=item.productGroup, brand = item.brand, model_number=item.modelNumber, hotspotCategory=item.hotspotCategory).first()
257
    print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2} {3} {4}".format(item.productGroup, item.brand, item.modelNumber, item.hotspotCategory, item.color)
259
    print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2} {3} {4}".format(item.productGroup, item.brand, item.modelNumber, item.hotspotCategory, item.color)
258
                 
260
                 
Line 304... Line 306...
304
                current_inventory_snapshot.warehouse = warehouse
306
                current_inventory_snapshot.warehouse = warehouse
305
                current_inventory_snapshot.availibility = 0
307
                current_inventory_snapshot.availibility = 0
306
                current_inventory_snapshot.reserved = 0
308
                current_inventory_snapshot.reserved = 0
307
            # added the difference in the current inventory    
309
            # added the difference in the current inventory    
308
            current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
310
            current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
-
 
311
            
-
 
312
            mark_item_risky(item, current_inventory_snapshot.availibility, current_inventory_snapshot.reserved)
-
 
313
            
309
        except:
314
        except:
310
            raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
315
            raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
311
    session.commit() 
316
    session.commit() 
312
 
317
 
313
def get_item_inventoy(item_id):
318
def get_item_inventoy(item_id):
Line 383... Line 388...
383
    item = get_item(item_id)
388
    item = get_item(item_id)
384
    if not item:
389
    if not item:
385
        raise InventoryServiceException(108, "item id not present")
390
        raise InventoryServiceException(108, "item id not present")
386
    add_status_change_log(item, new_status)
391
    add_status_change_log(item, new_status)
387
    item.status = new_status
392
    item.status = new_status
-
 
393
    if item.status == status.PHASED_OUT:
-
 
394
        item.status_description = "This item has been phased out"
-
 
395
    elif item.status == status.DELETED:
-
 
396
        item.status_description = "This item has been deleted"
-
 
397
    elif item.status == status.PAUSED:
-
 
398
        item.status_description = "This item is currently out of stock"        
-
 
399
    elif item.status == status.ACTIVE:
-
 
400
        item.status_description = "This item is active"
-
 
401
    elif item.status == status.IN_PROCESS:
-
 
402
        item.status_description = "This item is in process"
-
 
403
    elif item.status == status.CONTENT_COMPLETE:
-
 
404
        item.status_description = "This item is in process"
388
    session.commit()
405
    session.commit()
389
    
406
    
390
def get_item_availability_for_warehouse(warehouse_id, item_id):
407
def get_item_availability_for_warehouse(warehouse_id, item_id):
391
    if not warehouse_id:
408
    if not warehouse_id:
392
        raise InventoryServiceException(101, "bad warehouse_id")
409
        raise InventoryServiceException(101, "bad warehouse_id")
Line 414... Line 431...
414
        return 0
431
        return 0
415
    else:
432
    else:
416
        return current_inventory_snapshot.availibility
433
        return current_inventory_snapshot.availibility
417
    """
434
    """
418
    
435
    
-
 
436
def mark_item_risky(item, availability, reserved):
-
 
437
    if not item.risky:
-
 
438
        return
-
 
439
    if availability - reserved <= 0:
-
 
440
        if item.status == status.ACTIVE:
-
 
441
            change_item_status(item.id, status.PAUSED)
-
 
442
    else:
-
 
443
        if item.status == status.PAUSED:
-
 
444
            change_item_status(item.id, status.ACTIVE)
-
 
445
    
-
 
446
 
419
def reserve_item_in_warehouse(item_id, warehouse_id, quantity):    
447
def reserve_item_in_warehouse(item_id, warehouse_id, quantity):    
420
    if not warehouse_id:
448
    if not warehouse_id:
421
        raise InventoryServiceException(101, "bad warehouse_id")
449
        raise InventoryServiceException(101, "bad warehouse_id")
-
 
450
    item = get_item(item_id)
422
    if not item_id:
451
    if not item:
423
        raise InventoryServiceException(101, "bad item_id")
452
        raise InventoryServiceException(101, "bad item_id")
424
        
453
        
425
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
454
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
426
    try:
455
    try:
427
        current_inventory_snapshot = query.one()
456
        current_inventory_snapshot = query.one()
428
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved + quantity
457
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved + quantity
-
 
458
        
-
 
459
        mark_item_risky(item, current_inventory_snapshot.availibility, current_inventory_snapshot.reserved)
-
 
460
        
429
        session.commit()
461
        session.commit()
430
        return True
462
        return True
431
    except:
463
    except:
432
        print "Unexpected error:", sys.exc_info()[0]
464
        print "Unexpected error:", sys.exc_info()[0]
433
        return False
465
        return False
434
 
466
 
435
def reduce_reservation_count(item_id, warehouse_id, quantity):
467
def reduce_reservation_count(item_id, warehouse_id, quantity):
436
    if not warehouse_id:
468
    if not warehouse_id:
437
        raise InventoryServiceException(101, "bad warehouse_id")
469
        raise InventoryServiceException(101, "bad warehouse_id")
-
 
470
    item = get_item(item_id)
438
    if not item_id:
471
    if not item:
439
        raise InventoryServiceException(101, "bad item_id")
472
        raise InventoryServiceException(101, "bad item_id")
440
        
473
        
441
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
474
    query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
442
    try:
475
    try:
443
        current_inventory_snapshot = query.one()
476
        current_inventory_snapshot = query.one()
444
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
477
        current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
-
 
478
        
-
 
479
        mark_item_risky(item, current_inventory_snapshot.availibility, current_inventory_snapshot.reserved)
-
 
480
        
445
        session.commit()
481
        session.commit()
446
        return True
482
        return True
447
    except:
483
    except:
448
        print "Unexpected error:", sys.exc_info()[0]
484
        print "Unexpected error:", sys.exc_info()[0]
449
        return False
485
        return False