| 17973 |
manish.sha |
1 |
from elixir import *
|
|
|
2 |
from functools import partial
|
|
|
3 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
4 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
5 |
from shop2020.model.v1.inventory.impl import DataService
|
|
|
6 |
from shop2020.model.v1.inventory.impl.Convertors import to_t_warehouse, \
|
|
|
7 |
to_t_itemidwarehouseid, to_t_state
|
|
|
8 |
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
|
|
|
9 |
ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \
|
|
|
10 |
VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \
|
|
|
11 |
VendorHolidays, ItemAvailabilityCache, \
|
|
|
12 |
CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \
|
|
|
13 |
OOSStatus, AmazonInventorySnapshot, StateMaster, HoldInventoryDetail, AmazonFbaInventorySnapshot, \
|
|
|
14 |
SnapdealInventorySnapshot, FlipkartInventorySnapshot, SnapdealStockAtEOD, FlipkartStockAtEOD, StockWeightedNlcInfo
|
|
|
15 |
|
|
|
16 |
from shop2020.model.v1.inventory.impl.DataAcessors import clear_item_availability_cache
|
|
|
17 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
|
|
18 |
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
|
|
|
19 |
from shop2020.utils import EmailAttachmentSender
|
|
|
20 |
from shop2020.utils.EmailAttachmentSender import mail
|
|
|
21 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
|
|
22 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
|
|
23 |
from sqlalchemy.sql import or_
|
|
|
24 |
from sqlalchemy.sql.expression import and_, func, distinct, desc
|
|
|
25 |
from sqlalchemy.sql.functions import count
|
|
|
26 |
import calendar
|
|
|
27 |
import datetime
|
|
|
28 |
import sys
|
|
|
29 |
import threading
|
|
|
30 |
import math
|
|
|
31 |
import xlrd
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
def add_inventory(itemId, warehouseId, quantity):
|
|
|
35 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
|
|
36 |
if not current_inventory_snapshot:
|
|
|
37 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
|
|
38 |
current_inventory_snapshot.item_id = itemId
|
|
|
39 |
current_inventory_snapshot.warehouse_id = warehouseId
|
|
|
40 |
current_inventory_snapshot.availability = 0
|
|
|
41 |
current_inventory_snapshot.reserved = 0
|
|
|
42 |
current_inventory_snapshot.held = 0
|
|
|
43 |
# added the difference in the current inventory
|
|
|
44 |
current_inventory_snapshot.availability = current_inventory_snapshot.availability + quantity
|
|
|
45 |
session.commit()
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
def read_data(filename):
|
|
|
49 |
DataService.initialize(db_hostname='192.168.190.114')
|
|
|
50 |
workbook = xlrd.open_workbook(filename)
|
|
|
51 |
sheet = workbook.sheet_by_index(0)
|
|
|
52 |
num_rows = sheet.nrows
|
|
|
53 |
count =0
|
|
|
54 |
itemIds = []
|
|
|
55 |
for rownum in range(1, num_rows):
|
|
|
56 |
print sheet.row_values(rownum)
|
|
|
57 |
itemId = long(sheet.row_values(rownum)[0])
|
|
|
58 |
warehouse_id = long(sheet.row_values(rownum)[1])
|
|
|
59 |
quantity = long(sheet.row_values(rownum)[2])
|
|
|
60 |
add_inventory(itemId, warehouse_id, quantity)
|
|
|
61 |
itemIds.append(itemId)
|
|
|
62 |
count = count+1
|
|
|
63 |
|
|
|
64 |
clear_item_availability_cache(itemIds)
|
|
|
65 |
print "Count", count
|
|
|
66 |
session.close()
|
|
|
67 |
|
|
|
68 |
def main():
|
|
|
69 |
read_data("/home/manish/virtualInv.xls")
|
|
|
70 |
|
|
|
71 |
if __name__ == '__main__':
|
|
|
72 |
main()
|