Rev 5944 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''Load the whole inventory for a warehouse.With the amount of data that we have now and the amountof traffic we get, it's now impracitcal to do this foralready existing warehouses. It should only be used fora newly provisioned warehouse.@author: Chandranshu'''import optparseimport xlrdimport datetimeif __name__ == '__main__' and __package__ is None:import sysimport ossys.path.insert(0, os.getcwd())from shop2020.model.v1.inventory.impl import DataServicefrom shop2020.model.v1.inventory.impl.DataAcessors import update_inventoryfrom elixir import *def read_inventory_data(filename, product_group):workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowsavailability = {}for rownum in range(1, num_rows):if product_group:brand, model_number, color, quantity = sheet.row_values(rownum)[0:4]else:product_group, brand, model_number, color, quantity = sheet.row_values(rownum)[0:5]if isinstance(model_number, float):model_number = str(int(model_number))print sheet.row_values(rownum)itemid = product_group + ";" + brand + ";" + model_number + ";" + colorif availability.has_key(itemid):quantity = quantity + availability.get(itemid)availability[itemid] = quantityreturn availabilitydef load_inventory_data(filename, warehouse_id, product_group):DataService.initialize('catalog')availability = read_inventory_data(filename, product_group)update_inventory(warehouse_id, datetime.datetime.now(), availability)session.commit()print "Successfully updated the item inventory information."def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="ItemInventory.xls", type="string",help="Read the item inventory from FILE",metavar="FILE")parser.add_option("-w", "--warehouse", dest="warehouse_id",default="1", type="string",help="Load the item inventory for the warehouse with WarehouseId as id",metavar="WarehouseId")parser.add_option("-p", "--product-group", dest="product_group",default=None, type="string",help="Assume PRODUCT_GROUP to be the product group of all items",metavar="PRODUCT_GROUP")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")filename = options.filenamewarehouse_id = options.warehouse_idload_inventory_data(filename, warehouse_id, options.product_group)if __name__ == '__main__':main()