Blame | Last modification | View Log | RSS feed
from elixir import *from functools import partialfrom shop2020.clients.CatalogClient import CatalogClientfrom shop2020.clients.TransactionClient import TransactionClientfrom shop2020.model.v1.inventory.impl import DataServicefrom shop2020.model.v1.inventory.impl.Convertors import to_t_warehouse, \to_t_itemidwarehouseid, to_t_statefrom shop2020.model.v1.inventory.impl.DataService import Warehouse, \ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \VendorHolidays, ItemAvailabilityCache, \CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \OOSStatus, AmazonInventorySnapshot, StateMaster, HoldInventoryDetail, AmazonFbaInventorySnapshot, \SnapdealInventorySnapshot, FlipkartInventorySnapshot, SnapdealStockAtEOD, FlipkartStockAtEOD, StockWeightedNlcInfofrom shop2020.model.v1.inventory.impl.DataAcessors import clear_item_availability_cachefrom shop2020.thriftpy.model.v1.order.ttypes import AlertTypefrom shop2020.thriftpy.purchase.ttypes import PurchaseServiceExceptionfrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.EmailAttachmentSender import mailfrom shop2020.utils.Utils import to_py_date, to_java_datefrom sqlalchemy.orm.exc import MultipleResultsFound, NoResultFoundfrom sqlalchemy.sql import or_from sqlalchemy.sql.expression import and_, func, distinct, descfrom sqlalchemy.sql.functions import countimport calendarimport datetimeimport sysimport threadingimport mathimport xlrddef add_inventory(itemId, warehouseId, quantity):current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)if not current_inventory_snapshot:current_inventory_snapshot = CurrentInventorySnapshot()current_inventory_snapshot.item_id = itemIdcurrent_inventory_snapshot.warehouse_id = warehouseIdcurrent_inventory_snapshot.availability = 0current_inventory_snapshot.reserved = 0current_inventory_snapshot.held = 0# added the difference in the current inventorycurrent_inventory_snapshot.availability = current_inventory_snapshot.availability + quantitysession.commit()def read_data(filename):DataService.initialize(db_hostname='192.168.190.114')workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowscount =0itemIds = []for rownum in range(1, num_rows):print sheet.row_values(rownum)itemId = long(sheet.row_values(rownum)[0])warehouse_id = long(sheet.row_values(rownum)[1])quantity = long(sheet.row_values(rownum)[2])add_inventory(itemId, warehouse_id, quantity)itemIds.append(itemId)count = count+1clear_item_availability_cache(itemIds)print "Count", countsession.close()def main():read_data("/home/manish/virtualInv.xls")if __name__ == '__main__':main()