Subversion Repositories SmartDukaan

Rev

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

Rev 22721 Rev 22722
Line 50... Line 50...
50
warehouseMap = {}
50
warehouseMap = {}
51
logisticsLocationWarehouseMap = {}
51
logisticsLocationWarehouseMap = {}
52
 
52
 
53
OOS_CALCULATION_TIME = 23
53
OOS_CALCULATION_TIME = 23
54
physicalWarehouseIdsForFofo = [7678, 7681]
54
physicalWarehouseIdsForFofo = [7678, 7681]
-
 
55
vendorWarehouseIdsForFofo = []
55
 
56
 
56
last_date = datetime.date.today()
57
last_date = datetime.date.today()
57
adjusted_dates={}
58
adjusted_dates={}
58
 
59
 
59
def initialize(dbname='inventory', db_hostname="localhost"):
60
def initialize(dbname='inventory', db_hostname="localhost"):
Line 65... Line 66...
65
    for warehouse in warehouses:
66
    for warehouse in warehouses:
66
        warehouseMap[warehouse.id] = warehouse
67
        warehouseMap[warehouse.id] = warehouse
67
        if not logisticsLocationWarehouseMap.has_key(warehouse.logisticsLocation):
68
        if not logisticsLocationWarehouseMap.has_key(warehouse.logisticsLocation):
68
            logisticsLocationWarehouseMap[warehouse.logisticsLocation] = []
69
            logisticsLocationWarehouseMap[warehouse.logisticsLocation] = []
69
        logisticsLocationWarehouseMap[warehouse.logisticsLocation].append(warehouse.id)
70
        logisticsLocationWarehouseMap[warehouse.logisticsLocation].append(warehouse.id)
-
 
71
        if warehouse.billingWarehouseId in physicalWarehouseIdsForFofo:
-
 
72
            vendorWarehouseIdsForFofo.append(warehouse.id)
70
    
73
    
71
    
74
    
72
def get_Warehouse(warehouse_id):
75
def get_Warehouse(warehouse_id):
73
    return Warehouse.get_by(id=warehouse_id)
76
    return Warehouse.get_by(id=warehouse_id)
74
 
77
 
Line 130... Line 133...
130
 
133
 
131
def get_ignored_warehouses(item_id):
134
def get_ignored_warehouses(item_id):
132
    warehouses = []
135
    warehouses = []
133
    #No item availability cache for Hotspot Specific Store
136
    #No item availability cache for Hotspot Specific Store
134
    #No virtual is allowed
137
    #No virtual is allowed
135
#    hotspotPhysicalWarehouses = [7678, 7681]
-
 
136
#    hotspotVendorWarehouses = Warehouse.query.filter(Warehouse.billingWarehouseId.in_(hotspotPhysicalWarehouses)).filter(Warehouse.inventoryType=='GOOD').all()
-
 
137
#    for warehouse in hotspotVendorWarehouses:
-
 
138
#        warehouses.append(warehouse.id)
-
 
139
    Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).all()
138
    Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).all()
140
    for Ignored_inventory_item in Ignored_inventory_items:
139
    for Ignored_inventory_item in Ignored_inventory_items:
141
        warehouses.append(Ignored_inventory_item.warehouse_id)
140
        warehouses.append(Ignored_inventory_item.warehouse_id)
142
    return warehouses
141
    return warehouses + vendorWarehouseIdsForFofo
143
 
142
 
144
def update_inventory_history(warehouse_id, timestamp, availability):
143
def update_inventory_history(warehouse_id, timestamp, availability):
145
    warehouse = get_Warehouse(warehouse_id)
144
    warehouse = get_Warehouse(warehouse_id)
146
    if not warehouse:
145
    if not warehouse:
147
        raise InventoryServiceException(107, "Warehouse? Where?")
146
        raise InventoryServiceException(107, "Warehouse? Where?")
Line 324... Line 323...
324
def get_fofo_availability(item_ids):
323
def get_fofo_availability(item_ids):
325
    #TODO: Amit Should be removed physicalWarehouseIdsForFofo
324
    #TODO: Amit Should be removed physicalWarehouseIdsForFofo
326
    returnMap = {}
325
    returnMap = {}
327
    if not item_ids:
326
    if not item_ids:
328
        return returnMap
327
        return returnMap
329
    fofoWarehouses = Warehouse.query.filter(Warehouse.warehouseType.in_(['OURS', 'THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').filter(Warehouse.billingWarehouseId.in_(physicalWarehouseIdsForFofo)).all()
-
 
330
    warehouse_ids = []
-
 
331
    for fofoWarehouse in fofoWarehouses:
-
 
332
        warehouse_ids.append(fofoWarehouse.id)
-
 
333
    snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter(CurrentInventorySnapshot.item_id.in_(item_ids)).all()
328
    snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(vendorWarehouseIdsForFofo)).filter(CurrentInventorySnapshot.item_id.in_(item_ids)).all()
334
    for snapshot in snapshots:
329
    for snapshot in snapshots:
335
        if returnMap.has_key(snapshot.item_id):
330
        if returnMap.has_key(snapshot.item_id):
336
            returnMap[snapshot.item_id] += snapshot.availability - snapshot.reserved - snapshot.held
331
            returnMap[snapshot.item_id] += snapshot.availability - snapshot.reserved - snapshot.held
337
        else:
332
        else:
338
            returnMap[snapshot.item_id] = snapshot.availability - snapshot.reserved - snapshot.held 
333
            returnMap[snapshot.item_id] = snapshot.availability - snapshot.reserved - snapshot.held 
339
    return returnMap
334
    return returnMap
340
 
335
 
341
def get_fofo_fulfilment_warehouse_map(itemIds):
336
def get_fofo_fulfilment_warehouse_map(itemIds):
342
    returnMap = {}
337
    returnMap = {}
343
    fofoWarehouses = Warehouse.query.filter(Warehouse.warehouseType.in_(['OURS', 'THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').filter(Warehouse.billingWarehouseId.in_(physicalWarehouseIdsForFofo)).all()
-
 
344
    warehouse_ids = []
-
 
345
    for fofoWarehouse in fofoWarehouses:
-
 
346
        warehouse_ids.append(fofoWarehouse.id)
-
 
347
    snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter(CurrentInventorySnapshot.item_id.in_(itemIds)).all()
338
    snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(vendorWarehouseIdsForFofo)).filter(CurrentInventorySnapshot.item_id.in_(itemIds)).all()
348
    for snapshot in snapshots:
339
    for snapshot in snapshots:
349
        availability = snapshot.availability - snapshot.reserved - snapshot.held
340
        availability = snapshot.availability - snapshot.reserved - snapshot.held
350
        if availability > 0:
341
        if availability > 0:
351
            if not returnMap.has_key(snapshot.item_id):
342
            if not returnMap.has_key(snapshot.item_id):
352
                returnMap[snapshot.item_id] = to_t_warehouse(snapshot.warehouse)
343
                returnMap[snapshot.item_id] = to_t_warehouse(snapshot.warehouse)
Line 778... Line 769...
778
 
769
 
779
 
770
 
780
 
771
 
781
def __update_item_availability_cache(item_id, source_id, item=None):
772
def __update_item_availability_cache(item_id, source_id, item=None):
782
    """
773
    """
783
    Source 2 is completely hardcoded for fofo which has physical warehouse as 7678 and 7681
-
 
784
    Then how shoud we handle virtual because for both source virtual gonna mark
774
    Then how shoud we handle virtual because for both source virtual gonna mark
785
    """
775
    """
786
    """
776
    """
787
    Determines the warehouse that should be used to fulfil an order for the given item.
777
    Determines the warehouse that should be used to fulfil an order for the given item.
788
    Algorithm explained at https://sites.google.com/a/shop2020.in/virtual-w-h-and-inventory/technical-details
778
    Algorithm explained at https://sites.google.com/a/shop2020.in/virtual-w-h-and-inventory/technical-details