| 5944 |
mandeep.dh |
1 |
'''
|
|
|
2 |
Created on 27-Apr-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.config.client.ConfigClient import ConfigClient
|
|
|
7 |
from shop2020.model.v1.inventory.impl import DataService
|
| 5957 |
mandeep.dh |
8 |
from shop2020.model.v1.inventory.impl.Convertors import to_t_item_inventory, \
|
| 6821 |
amar.kumar |
9 |
to_t_warehouse, to_t_vendor_item_pricing, to_t_vendor, to_t_vendor_item_mapping, \
|
| 8282 |
kshitij.so |
10 |
to_t_item_stock_purchase_params, to_t_oos_status, to_t_amazon_inventory_snapshot, \
|
| 9404 |
vikram.rag |
11 |
to_t_amazon_fba_inventory_snapshot,to_t_snapdeal_inventory_snapshot
|
| 5944 |
mandeep.dh |
12 |
from shop2020.model.v1.inventory.impl.DataAcessors import add_warehouse, \
|
|
|
13 |
update_inventory, retire_warehouse, get_item_availability_for_warehouse, \
|
|
|
14 |
get_item_availability_for_location, get_all_warehouses_by_status, get_Warehouse, \
|
| 5957 |
mandeep.dh |
15 |
get_all_items_for_warehouse, close_session, add_vendor, \
|
|
|
16 |
get_item_inventory_by_item_id, reserve_item_in_warehouse, \
|
|
|
17 |
reduce_reservation_count, get_all_item_pricing, add_vendor_pricing, \
|
|
|
18 |
get_item_pricing, get_all_vendors, get_item_mappings, add_vendor_item_mapping, \
|
|
|
19 |
update_inventory_history, is_alive, add_inventory, add_bad_inventory, \
|
|
|
20 |
mark_missed_inventory_updates_as_processed, update_vendor_string, \
|
|
|
21 |
get_item_keys_to_be_processed, reset_availability, get_shipping_locations, \
|
| 5944 |
mandeep.dh |
22 |
initialize, get_inventory_snapshot, clear_item_availability_cache, \
|
| 5987 |
rajveer |
23 |
reset_availability_for_warehouse, get_vendor, get_pending_orders_inventory, \
|
| 6531 |
vikram.rag |
24 |
is_order_billable, get_our_warehouse_id_for_vendor, \
|
|
|
25 |
get_item_availability_for_our_warehouses, get_monitored_warehouses_for_vendors, \
|
|
|
26 |
get_ignored_warehouseids_and_itemids,insert_item_to_ignore_inventory_update_list, \
|
|
|
27 |
delete_item_from_ignore_inventory_update_list,get_all_ignored_inventoryupdate_items_count, \
|
| 6821 |
amar.kumar |
28 |
get_ignored_inventoryupdate_itemids, update_item_stock_purchase_params, \
|
| 6857 |
amar.kumar |
29 |
get_item_stock_purchase_params, add_oos_status_for_item, \
|
| 7149 |
amar.kumar |
30 |
get_oos_statuses_for_x_days_for_item, get_non_zero_item_stock_purchase_params, \
|
| 7281 |
kshitij.so |
31 |
get_billable_inventory_and_pending_orders,get_warehouse_name,get_amazon_inventory_for_item,get_all_amazon_inventory, \
|
| 7972 |
amar.kumar |
32 |
add_or_update_amazon_inventory_for_item, update_reservation_for_order, \
|
| 8282 |
kshitij.so |
33 |
get_last_n_day_sale_for_item, add_or_update_amazon_fba_inventory, add_update_hold_inventory,\
|
| 9404 |
vikram.rag |
34 |
get_amazon_fba_inventory,get_all_amazon_fba_inventory, get_oursgood_warehouseids_for_location, \
|
|
|
35 |
get_holdinventorydetail_forItem_forWarehouseId_exceptsource, get_snapdeal_inventory_for_item, \
|
| 9495 |
vikram.rag |
36 |
add_or_update_snapdeal_inventor_for_item, get_nlc_for_warehouse,get_snapdeal_inventory_snapshot
|
| 7972 |
amar.kumar |
37 |
|
| 5944 |
mandeep.dh |
38 |
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
|
|
|
39 |
MissedInventoryUpdate, VendorItemMapping
|
| 5957 |
mandeep.dh |
40 |
from shop2020.thriftpy.model.v1.inventory.ttypes import \
|
|
|
41 |
InventoryServiceException, WarehouseType, InventoryType, \
|
|
|
42 |
AvailableAndReservedStock
|
| 5944 |
mandeep.dh |
43 |
from shop2020.utils.Utils import log_entry, to_java_date
|
|
|
44 |
|
|
|
45 |
class InventoryServiceHandler:
|
|
|
46 |
'''
|
|
|
47 |
classdocs
|
|
|
48 |
'''
|
|
|
49 |
|
|
|
50 |
def __init__(self, dbname='catalog', db_hostname='localhost'):
|
|
|
51 |
'''
|
|
|
52 |
Constructor
|
| 6532 |
amit.gupta |
53 |
u '''
|
| 5944 |
mandeep.dh |
54 |
initialize(dbname, db_hostname)
|
|
|
55 |
try:
|
|
|
56 |
config_client = ConfigClient()
|
|
|
57 |
self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
|
|
|
58 |
self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
|
|
|
59 |
except:
|
|
|
60 |
self.latest_arrivals_limit = 50
|
|
|
61 |
self.best_sellers_limit = 50
|
|
|
62 |
|
|
|
63 |
def addWarehouse(self, warehouse):
|
|
|
64 |
"""
|
|
|
65 |
Parameters:
|
|
|
66 |
- warehouse
|
|
|
67 |
"""
|
|
|
68 |
log_entry(self, "addWarehouse called")
|
|
|
69 |
try:
|
|
|
70 |
return add_warehouse(warehouse)
|
|
|
71 |
finally:
|
|
|
72 |
close_session()
|
|
|
73 |
|
|
|
74 |
def updateInventoryHistory(self, warehouse_id, timestamp, availability):
|
|
|
75 |
"""
|
|
|
76 |
Stores the incremental warehouse updates of items.
|
|
|
77 |
|
|
|
78 |
Parameters:
|
|
|
79 |
- warehouse_id
|
|
|
80 |
- timestamp
|
|
|
81 |
- availability
|
|
|
82 |
"""
|
|
|
83 |
try:
|
|
|
84 |
return update_inventory_history(warehouse_id, timestamp, availability)
|
|
|
85 |
finally:
|
|
|
86 |
close_session()
|
|
|
87 |
|
|
|
88 |
def updateInventory(self, warehouse_id, timestamp, availability):
|
|
|
89 |
"""
|
|
|
90 |
Parameters:
|
|
|
91 |
- warehouse_id
|
|
|
92 |
- timestamp
|
|
|
93 |
- availability
|
|
|
94 |
"""
|
|
|
95 |
log_entry(self, "update Inventory called")
|
|
|
96 |
try:
|
|
|
97 |
return update_inventory(warehouse_id, timestamp, availability)
|
|
|
98 |
finally:
|
|
|
99 |
close_session()
|
|
|
100 |
|
|
|
101 |
def addInventory(self, itemId, warehouseId, quantity):
|
|
|
102 |
"""
|
|
|
103 |
Add the inventory to existing stock.
|
|
|
104 |
|
|
|
105 |
Parameters:
|
|
|
106 |
- itemId
|
|
|
107 |
- warehouseId
|
|
|
108 |
- quantity
|
|
|
109 |
"""
|
|
|
110 |
log_entry(self, "add Inventory called")
|
|
|
111 |
try:
|
|
|
112 |
return add_inventory(itemId, warehouseId, quantity)
|
|
|
113 |
finally:
|
|
|
114 |
close_session()
|
|
|
115 |
|
|
|
116 |
def retireWarehouse(self, warehouse_id):
|
|
|
117 |
"""
|
|
|
118 |
Parameters:
|
|
|
119 |
- warehouse_id
|
|
|
120 |
"""
|
|
|
121 |
log_entry(self, "retire warehouse called")
|
|
|
122 |
try:
|
|
|
123 |
return retire_warehouse(warehouse_id)
|
|
|
124 |
finally:
|
|
|
125 |
close_session()
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
def getItemInventoryByItemId(self, item_id):
|
|
|
129 |
"""
|
|
|
130 |
Parameters:
|
|
|
131 |
- item_id
|
|
|
132 |
"""
|
|
|
133 |
log_entry(self, "item inventory requested")
|
|
|
134 |
try:
|
|
|
135 |
inventory = get_item_inventory_by_item_id(item_id)
|
|
|
136 |
return to_t_item_inventory(inventory, item_id)
|
|
|
137 |
finally:
|
|
|
138 |
close_session()
|
|
|
139 |
|
| 5978 |
rajveer |
140 |
def getItemAvailabilityAtLocation(self, itemId, sourceId):
|
| 5944 |
mandeep.dh |
141 |
"""
|
|
|
142 |
Determines the warehouse that should be used to fulfil an order for the given item.
|
|
|
143 |
It first checks all the warehouses which are in the logistics location given by the
|
|
|
144 |
warehouse_loc parameter. If none of the warehouses there have any inventory, then the
|
|
|
145 |
preferred warehouse for the item is used.
|
|
|
146 |
|
|
|
147 |
Returns an ordered list of size 4 with following elements in the given order:
|
|
|
148 |
1. Logistics location of the warehouse which was finally picked up to ship the order.
|
|
|
149 |
2. Id of the warehouse which was finally picked up.
|
|
|
150 |
3. Inventory size in the selected warehouse.
|
|
|
151 |
4. Expected delay added by the category manager.
|
|
|
152 |
|
|
|
153 |
Parameters:
|
|
|
154 |
- itemId
|
| 5978 |
rajveer |
155 |
- sourceId
|
| 5944 |
mandeep.dh |
156 |
"""
|
|
|
157 |
try:
|
| 5978 |
rajveer |
158 |
return get_item_availability_for_location(itemId, sourceId)
|
| 5944 |
mandeep.dh |
159 |
finally:
|
|
|
160 |
close_session()
|
|
|
161 |
|
|
|
162 |
def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):
|
|
|
163 |
"""
|
|
|
164 |
Parameters:
|
|
|
165 |
- warehouse_id
|
|
|
166 |
- item_id
|
|
|
167 |
"""
|
|
|
168 |
log_entry(self, "item availability at warehouse requested")
|
|
|
169 |
try:
|
|
|
170 |
return get_item_availability_for_warehouse(warehouse_id, item_id)
|
|
|
171 |
finally:
|
|
|
172 |
close_session()
|
| 6484 |
amar.kumar |
173 |
|
|
|
174 |
def getItemAvailabilitiesAtOurWarehouses(self, item_ids):
|
|
|
175 |
try:
|
|
|
176 |
return get_item_availability_for_our_warehouses(item_ids)
|
|
|
177 |
finally:
|
|
|
178 |
close_session()
|
| 5944 |
mandeep.dh |
179 |
|
|
|
180 |
def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
|
|
|
181 |
"""
|
|
|
182 |
Parameters:
|
|
|
183 |
- id
|
|
|
184 |
- item_id
|
|
|
185 |
- warehouse_id
|
|
|
186 |
- from_date
|
|
|
187 |
- to_date
|
|
|
188 |
"""
|
|
|
189 |
pass
|
|
|
190 |
|
|
|
191 |
def getAllWarehouses(self, isActive):
|
|
|
192 |
"""
|
|
|
193 |
Parameters:
|
|
|
194 |
- isActive
|
|
|
195 |
"""
|
|
|
196 |
try:
|
|
|
197 |
if isActive:
|
|
|
198 |
warehouses = get_all_warehouses_by_status(3)
|
|
|
199 |
else:
|
|
|
200 |
warehouses = get_all_warehouses_by_status(None)
|
|
|
201 |
|
|
|
202 |
ret_warehouses = []
|
|
|
203 |
|
|
|
204 |
for warehouse in warehouses:
|
|
|
205 |
ret_warehouses.append(to_t_warehouse(warehouse))
|
|
|
206 |
return ret_warehouses
|
|
|
207 |
finally:
|
|
|
208 |
close_session()
|
|
|
209 |
|
|
|
210 |
def getWarehouse(self, warehouse_id):
|
|
|
211 |
"""
|
|
|
212 |
Parameters:
|
|
|
213 |
- warehouse_id
|
|
|
214 |
"""
|
|
|
215 |
log_entry(self, "get warehouse call")
|
|
|
216 |
try:
|
|
|
217 |
warehouse = get_Warehouse(warehouse_id)
|
|
|
218 |
if warehouse:
|
|
|
219 |
return to_t_warehouse(warehouse)
|
|
|
220 |
else:
|
|
|
221 |
raise InventoryServiceException(101, "no such warehouse: " + str(warehouse_id))
|
|
|
222 |
finally:
|
|
|
223 |
close_session()
|
|
|
224 |
|
|
|
225 |
def getAllItemsForWarehouse(self, warehouse_id):
|
|
|
226 |
"""
|
|
|
227 |
Parameters:
|
|
|
228 |
- warehouse_id
|
|
|
229 |
"""
|
|
|
230 |
log_entry(self, "getting all items for warehouse")
|
|
|
231 |
try:
|
|
|
232 |
all_items = get_all_items_for_warehouse(warehouse_id)
|
|
|
233 |
t_items = []
|
|
|
234 |
for item in all_items:
|
|
|
235 |
t_items.append(item.id)
|
|
|
236 |
return t_items
|
|
|
237 |
finally:
|
|
|
238 |
close_session()
|
|
|
239 |
|
| 5966 |
rajveer |
240 |
def isOrderBillable(self, itemId, warehouseId, sourceId, orderId):
|
| 5944 |
mandeep.dh |
241 |
"""
|
| 5966 |
rajveer |
242 |
Depending on reservation in the table, verify if we can bill this order or not.
|
|
|
243 |
|
|
|
244 |
Parameters:
|
|
|
245 |
- itemId
|
|
|
246 |
- warehouseId
|
|
|
247 |
- sourceId
|
|
|
248 |
- orderId
|
|
|
249 |
"""
|
|
|
250 |
try:
|
|
|
251 |
return is_order_billable(itemId, warehouseId, sourceId, orderId)
|
|
|
252 |
finally:
|
|
|
253 |
close_session()
|
|
|
254 |
|
|
|
255 |
def reserveItemInWarehouse(self, itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity):
|
|
|
256 |
"""
|
| 5944 |
mandeep.dh |
257 |
Increases the reservation count for an item in a warehouse. Should always succeed normally.
|
|
|
258 |
|
|
|
259 |
Parameters:
|
|
|
260 |
- itemId
|
|
|
261 |
- warehouseId
|
|
|
262 |
"""
|
|
|
263 |
log_entry(self, "reserveItemInWarehouse called")
|
|
|
264 |
try:
|
| 5966 |
rajveer |
265 |
return reserve_item_in_warehouse(itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity)
|
| 5944 |
mandeep.dh |
266 |
finally:
|
|
|
267 |
close_session()
|
| 7968 |
amar.kumar |
268 |
|
| 5944 |
mandeep.dh |
269 |
|
| 7968 |
amar.kumar |
270 |
def updateReservationForOrder(self, itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity):
|
|
|
271 |
"""
|
|
|
272 |
Increases the reservation count for an item in a warehouse. Should always succeed normally.
|
|
|
273 |
|
|
|
274 |
Parameters:
|
|
|
275 |
- itemId
|
|
|
276 |
- warehouseId
|
|
|
277 |
"""
|
|
|
278 |
log_entry(self, "reserveItemInWarehouse called")
|
|
|
279 |
try:
|
|
|
280 |
return update_reservation_for_order(itemId, warehouseId, sourceId, orderId, createdTimestamp, promisedShippingTimestamp, quantity)
|
|
|
281 |
finally:
|
|
|
282 |
close_session()
|
|
|
283 |
|
| 5966 |
rajveer |
284 |
def reduceReservationCount(self, itemId, warehouseId, sourceId, orderId, quantity):
|
| 5944 |
mandeep.dh |
285 |
"""
|
|
|
286 |
Decreases the reservation count for an item in a warehouse. Should always succeed normally.
|
|
|
287 |
|
|
|
288 |
Parameters:
|
|
|
289 |
- itemId
|
|
|
290 |
- warehouseId
|
|
|
291 |
"""
|
|
|
292 |
log_entry(self, "reduceReservationCount called")
|
|
|
293 |
try:
|
| 5966 |
rajveer |
294 |
return reduce_reservation_count(itemId, warehouseId, sourceId, orderId, quantity)
|
| 5944 |
mandeep.dh |
295 |
finally:
|
|
|
296 |
close_session()
|
|
|
297 |
|
|
|
298 |
def getItemPricing(self, itemId, vendorId):
|
|
|
299 |
"""
|
|
|
300 |
Returns the pricing information of an item associated with the vendor of the given warehouse.
|
|
|
301 |
Raises an exception if either the item, vendor or the associated pricing information can't be found.
|
|
|
302 |
|
|
|
303 |
Parameters:
|
|
|
304 |
- itemId
|
|
|
305 |
- warehouseId
|
|
|
306 |
"""
|
|
|
307 |
try:
|
|
|
308 |
return to_t_vendor_item_pricing(get_item_pricing(itemId, vendorId))
|
|
|
309 |
finally:
|
|
|
310 |
close_session()
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
def getAllItemPricing(self, itemId):
|
|
|
314 |
"""
|
|
|
315 |
Returns list of the pricing information of an item associated an item.
|
|
|
316 |
Raises an exception if the item can't be found.
|
|
|
317 |
|
|
|
318 |
Parameters:
|
|
|
319 |
- itemId
|
|
|
320 |
"""
|
|
|
321 |
try:
|
|
|
322 |
return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]
|
|
|
323 |
finally:
|
|
|
324 |
close_session()
|
|
|
325 |
|
|
|
326 |
def addVendorItemPricing(self, vendorItemPricing):
|
|
|
327 |
"""
|
|
|
328 |
Adds vendor prices corresponding to the item. If pricing already exists then updates the prices.
|
|
|
329 |
Raises an exception if either the item or vendor can't be found corresponding to their ids.
|
|
|
330 |
|
|
|
331 |
Parameters:
|
|
|
332 |
- vendorItemPricing
|
|
|
333 |
"""
|
|
|
334 |
log_entry(self, "updateVendorItemPricing called")
|
|
|
335 |
try:
|
|
|
336 |
return add_vendor_pricing(vendorItemPricing)
|
|
|
337 |
finally:
|
|
|
338 |
close_session()
|
|
|
339 |
|
|
|
340 |
def getVendor(self, vendorId):
|
|
|
341 |
"""
|
|
|
342 |
Return a vendor for id
|
|
|
343 |
"""
|
|
|
344 |
try:
|
|
|
345 |
return to_t_vendor(get_vendor(vendorId))
|
|
|
346 |
finally:
|
|
|
347 |
close_session()
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
def getAllVendors(self, ):
|
|
|
351 |
"""
|
|
|
352 |
Return list of all vendors
|
|
|
353 |
"""
|
|
|
354 |
try:
|
|
|
355 |
return [to_t_vendor(v) for v in get_all_vendors()]
|
|
|
356 |
finally:
|
|
|
357 |
close_session()
|
|
|
358 |
|
|
|
359 |
def addVendorItemMapping(self, key, vendorItemMapping):
|
|
|
360 |
"""
|
|
|
361 |
Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.
|
|
|
362 |
|
|
|
363 |
Parameters:
|
|
|
364 |
- key
|
|
|
365 |
- vendorItemMapping
|
|
|
366 |
"""
|
|
|
367 |
log_entry(self, "addVendorItemMapping called")
|
|
|
368 |
try:
|
|
|
369 |
return add_vendor_item_mapping(key, vendorItemMapping)
|
|
|
370 |
finally:
|
|
|
371 |
close_session()
|
|
|
372 |
|
|
|
373 |
def getVendorItemMappings(self, itemId):
|
|
|
374 |
"""
|
|
|
375 |
Returns the list of vendor item mapping corresponding to itemId passed as parameter.
|
|
|
376 |
Raises an exception if item not found corresponding to itemId
|
|
|
377 |
|
|
|
378 |
Parameters:
|
|
|
379 |
- itemId
|
|
|
380 |
"""
|
|
|
381 |
try:
|
|
|
382 |
item_mappings = get_item_mappings(itemId)
|
|
|
383 |
return [to_t_vendor_item_mapping(vim) for vim in item_mappings]
|
|
|
384 |
finally:
|
|
|
385 |
close_session()
|
|
|
386 |
|
|
|
387 |
def isAlive(self, ):
|
|
|
388 |
"""
|
|
|
389 |
For checking weather service is active alive or not. It also checks connectivity with database
|
|
|
390 |
"""
|
|
|
391 |
try:
|
|
|
392 |
return is_alive()
|
|
|
393 |
finally:
|
|
|
394 |
close_session()
|
|
|
395 |
|
|
|
396 |
def closeSession(self, ):
|
|
|
397 |
"""
|
|
|
398 |
For closing the open session in sqlalchemy
|
|
|
399 |
"""
|
|
|
400 |
close_session()
|
|
|
401 |
|
|
|
402 |
def addVendor(self, vendor):
|
|
|
403 |
"""
|
|
|
404 |
add a new vendor
|
|
|
405 |
"""
|
|
|
406 |
try:
|
|
|
407 |
return add_vendor(vendor)
|
|
|
408 |
finally:
|
|
|
409 |
close_session()
|
|
|
410 |
|
|
|
411 |
def getWarehouses(self, warehouseType, inventoryType, vendorId, billingWarehouseId, shippingWarehouseId):
|
|
|
412 |
"""
|
|
|
413 |
This method returns all warehouses for a given warehosueType, inventoryType, vendor, billingWarehouse and shippingWarehouse.
|
|
|
414 |
getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 1 for billing warehouse 7 and shipping warehouse 7
|
|
|
415 |
getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7
|
|
|
416 |
getWarehouses(null, null, 3, 7, 7) would return all type warehouses with all type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7
|
|
|
417 |
getWarehouses(null, null, 0, 0, 7) would return all type warehouses with all type inventory for all vendors for all billing warehouses at shipping warehouse 7
|
|
|
418 |
|
|
|
419 |
Parameters:
|
|
|
420 |
- warehouseType
|
|
|
421 |
- inventoryType
|
|
|
422 |
- vendorId
|
|
|
423 |
- billingWarehouseId
|
|
|
424 |
- shippingWarehouseId
|
|
|
425 |
"""
|
|
|
426 |
try:
|
|
|
427 |
query = Warehouse.query
|
|
|
428 |
if warehouseType is not None:
|
|
|
429 |
query = query.filter_by(warehouseType = WarehouseType._VALUES_TO_NAMES[warehouseType])
|
|
|
430 |
if inventoryType is not None:
|
|
|
431 |
query = query.filter_by(inventoryType = InventoryType._VALUES_TO_NAMES[inventoryType])
|
|
|
432 |
if vendorId:
|
|
|
433 |
query = query.filter_by(vendor_id = vendorId)
|
|
|
434 |
if billingWarehouseId:
|
|
|
435 |
query = query.filter_by(billingWarehouseId = billingWarehouseId)
|
|
|
436 |
if shippingWarehouseId:
|
|
|
437 |
query = query.filter_by(shippingWarehouseId = shippingWarehouseId)
|
|
|
438 |
|
|
|
439 |
return [to_t_warehouse(w) for w in query.all()]
|
|
|
440 |
finally:
|
|
|
441 |
close_session()
|
|
|
442 |
|
|
|
443 |
def getItemKeysToBeProcessed(self, warehouseId):
|
|
|
444 |
"""
|
|
|
445 |
Returns the list of item keys which need to be processed for a given warehouse.
|
|
|
446 |
This is currently used by Support application to send item keys whose inventory needs
|
|
|
447 |
to be updated from PLB
|
|
|
448 |
|
|
|
449 |
Parameters:
|
|
|
450 |
- warehouseId
|
|
|
451 |
"""
|
|
|
452 |
try:
|
|
|
453 |
return get_item_keys_to_be_processed(warehouseId)
|
|
|
454 |
finally:
|
|
|
455 |
close_session()
|
|
|
456 |
|
|
|
457 |
def markMissedInventoryUpdatesAsProcessed(self, itemKey, warehouseId):
|
|
|
458 |
"""
|
|
|
459 |
Marks/Deletes missed inventory updates for a given key and warehouse.
|
|
|
460 |
This generally happens when updates from PLB are applied on the currentinventorysnapshot for an item
|
|
|
461 |
|
|
|
462 |
Parameters:
|
|
|
463 |
- itemKey
|
|
|
464 |
- warehouseId
|
|
|
465 |
"""
|
|
|
466 |
try:
|
|
|
467 |
mark_missed_inventory_updates_as_processed(itemKey, warehouseId)
|
|
|
468 |
finally:
|
|
|
469 |
close_session()
|
|
|
470 |
|
|
|
471 |
def resetAvailability(self, itemKey, vendorId, quantity, warehouseId):
|
|
|
472 |
"""
|
|
|
473 |
Resets availability of an item to the quantity mentioned in a warehouse.
|
|
|
474 |
|
|
|
475 |
Parameters:
|
|
|
476 |
- itemKey
|
|
|
477 |
- vendorId
|
|
|
478 |
- quantity
|
|
|
479 |
- warehouseId
|
|
|
480 |
"""
|
|
|
481 |
try:
|
|
|
482 |
reset_availability(itemKey, vendorId, quantity, warehouseId)
|
|
|
483 |
finally:
|
|
|
484 |
close_session()
|
|
|
485 |
|
|
|
486 |
def resetAvailabilityForWarehouse(self, warehouseId):
|
|
|
487 |
"""
|
|
|
488 |
Resets availability of a warehouse to zero.
|
|
|
489 |
|
|
|
490 |
Parameters:
|
|
|
491 |
- warehouseId
|
|
|
492 |
"""
|
|
|
493 |
try:
|
|
|
494 |
reset_availability_for_warehouse(warehouseId)
|
|
|
495 |
finally:
|
|
|
496 |
close_session()
|
|
|
497 |
|
|
|
498 |
def getIgnoredItemKeys(self, ):
|
|
|
499 |
"""
|
|
|
500 |
Returns all the item key mappings that have been ignored until date. Value of map has the warehouse id
|
|
|
501 |
and the timestamp from where alert was raised.
|
|
|
502 |
"""
|
|
|
503 |
try:
|
|
|
504 |
itemKeysMap = {}
|
|
|
505 |
for key in MissedInventoryUpdate.query.filter_by(isIgnored = 1).all():
|
|
|
506 |
itemKeysMap[key.itemKey] = { key.warehouseId : to_java_date(key.timestamp) }
|
|
|
507 |
|
|
|
508 |
return itemKeysMap
|
|
|
509 |
finally:
|
|
|
510 |
close_session()
|
|
|
511 |
|
|
|
512 |
def addBadInventory(self, itemId, warehouseId, quantity):
|
|
|
513 |
"""
|
|
|
514 |
Add the BAD type inventory to existing stock.
|
|
|
515 |
|
|
|
516 |
Parameters:
|
|
|
517 |
- itemId
|
|
|
518 |
- warehouseId
|
|
|
519 |
- quantity
|
|
|
520 |
"""
|
|
|
521 |
try:
|
|
|
522 |
add_bad_inventory(itemId, warehouseId, quantity)
|
|
|
523 |
finally:
|
|
|
524 |
close_session()
|
|
|
525 |
|
|
|
526 |
def getShippingLocations(self, ):
|
|
|
527 |
"""
|
|
|
528 |
Returns all shipping locations
|
|
|
529 |
"""
|
|
|
530 |
try:
|
|
|
531 |
return [to_t_warehouse(w) for w in get_shipping_locations()]
|
|
|
532 |
finally:
|
|
|
533 |
close_session()
|
|
|
534 |
|
|
|
535 |
def getAllVendorItemMappings(self, ):
|
|
|
536 |
"""
|
|
|
537 |
Fetches all the vendor item mappings present.
|
|
|
538 |
"""
|
|
|
539 |
try:
|
|
|
540 |
return [to_t_vendor_item_mapping(m) for m in VendorItemMapping.query.all()]
|
|
|
541 |
finally:
|
|
|
542 |
close_session()
|
|
|
543 |
|
|
|
544 |
def getInventorySnapshot(self, warehouseId):
|
|
|
545 |
"""
|
|
|
546 |
Gets items' inventory for a warehouse
|
|
|
547 |
If warehouse is passed as zero, items' inventory across all warehouses is sent
|
|
|
548 |
|
|
|
549 |
Parameters:
|
|
|
550 |
- warehouseId
|
|
|
551 |
"""
|
|
|
552 |
try:
|
|
|
553 |
resultMap = {}
|
|
|
554 |
itemInventoryMap = get_inventory_snapshot(warehouseId)
|
|
|
555 |
for key, value in itemInventoryMap.items():
|
|
|
556 |
resultMap[key] = to_t_item_inventory(value, key)
|
|
|
557 |
|
|
|
558 |
return resultMap
|
|
|
559 |
finally:
|
|
|
560 |
close_session()
|
|
|
561 |
|
|
|
562 |
def clearItemAvailabilityCache(self, ):
|
|
|
563 |
"""
|
|
|
564 |
Clear item availability cache.
|
|
|
565 |
"""
|
|
|
566 |
try:
|
|
|
567 |
clear_item_availability_cache()
|
|
|
568 |
finally:
|
|
|
569 |
close_session()
|
| 5957 |
mandeep.dh |
570 |
|
| 6096 |
amit.gupta |
571 |
def clearItemAvailabilityCacheForItem(self, item_id):
|
|
|
572 |
"""
|
|
|
573 |
Clear item availability cache.
|
|
|
574 |
"""
|
|
|
575 |
try:
|
|
|
576 |
clear_item_availability_cache(item_id)
|
|
|
577 |
finally:
|
|
|
578 |
close_session()
|
|
|
579 |
|
| 5957 |
mandeep.dh |
580 |
def getPendingOrdersInventory(self, vendorId):
|
|
|
581 |
"""
|
|
|
582 |
Returns a list of inventory stock for items for which there are pending orders for the given vendor.
|
|
|
583 |
"""
|
|
|
584 |
try:
|
|
|
585 |
pending_items_inventory = get_pending_orders_inventory(vendorId)
|
|
|
586 |
return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in pending_items_inventory]
|
|
|
587 |
finally:
|
|
|
588 |
close_session()
|
|
|
589 |
|
| 5944 |
mandeep.dh |
590 |
def updateVendorString(self, warehouseId, vendorString):
|
|
|
591 |
"""
|
|
|
592 |
Parameters:
|
|
|
593 |
- warehouseId
|
|
|
594 |
- vendorString
|
|
|
595 |
"""
|
|
|
596 |
try:
|
|
|
597 |
update_vendor_string(warehouseId, vendorString)
|
|
|
598 |
finally:
|
|
|
599 |
close_session()
|
| 7718 |
amar.kumar |
600 |
def getOurWarehouseIdForVendor(self, vendorId, billingWarehouseId):
|
| 6467 |
amar.kumar |
601 |
"""
|
|
|
602 |
Returns warehouseId for our warehouse for a vendor
|
|
|
603 |
"""
|
|
|
604 |
try:
|
| 7718 |
amar.kumar |
605 |
return get_our_warehouse_id_for_vendor(vendorId, billingWarehouseId)
|
| 6467 |
amar.kumar |
606 |
finally:
|
| 6531 |
vikram.rag |
607 |
close_session()
|
|
|
608 |
def getMonitoredWarehouseForVendors(self, vendorIds):
|
|
|
609 |
"""
|
|
|
610 |
Returns monitored warehouse ids for vendors
|
|
|
611 |
"""
|
|
|
612 |
try:
|
|
|
613 |
return get_monitored_warehouses_for_vendors(vendorIds)
|
|
|
614 |
finally:
|
|
|
615 |
close_session()
|
|
|
616 |
def getIgnoredWarehouseidsAndItemids(self):
|
|
|
617 |
"""
|
|
|
618 |
Returns list of itemid and warehouseId for ignored inventory update
|
|
|
619 |
"""
|
|
|
620 |
try:
|
|
|
621 |
return get_ignored_warehouseids_and_itemids()
|
|
|
622 |
finally:
|
|
|
623 |
close_session()
|
|
|
624 |
|
|
|
625 |
def insertItemtoIgnoreInventoryUpdatelist(self,item_id,warehouse_id):
|
|
|
626 |
"""
|
|
|
627 |
Returns list of itemid and warehouseId for ignored inventory update
|
|
|
628 |
"""
|
|
|
629 |
try:
|
| 6532 |
amit.gupta |
630 |
return insert_item_to_ignore_inventory_update_list(item_id,warehouse_id)
|
| 6531 |
vikram.rag |
631 |
finally:
|
|
|
632 |
close_session()
|
|
|
633 |
def deleteItemFromIgnoredInventoryUpdateList(self,item_id,warehouse_id):
|
|
|
634 |
"""
|
|
|
635 |
Deletes warehouse and item entry from inventory update ignore list
|
|
|
636 |
"""
|
|
|
637 |
try:
|
|
|
638 |
return delete_item_from_ignore_inventory_update_list(item_id,warehouse_id)
|
|
|
639 |
finally:
|
|
|
640 |
close_session()
|
|
|
641 |
def getAllIgnoredInventoryupdateItemsCount(self):
|
|
|
642 |
"""
|
|
|
643 |
Returns all ignored inventory update item count
|
|
|
644 |
"""
|
| 6833 |
amar.kumar |
645 |
try:
|
|
|
646 |
return get_all_ignored_inventoryupdate_items_count()
|
|
|
647 |
finally:
|
|
|
648 |
close_session()
|
| 6531 |
vikram.rag |
649 |
|
|
|
650 |
|
|
|
651 |
def getIgnoredInventoryUpdateItemids(self,offset,limit):
|
|
|
652 |
"""
|
|
|
653 |
Returns all ignored inventory update items
|
|
|
654 |
"""
|
| 6833 |
amar.kumar |
655 |
try:
|
|
|
656 |
return get_ignored_inventoryupdate_itemids(offset,limit)
|
|
|
657 |
finally:
|
|
|
658 |
close_session()
|
| 6821 |
amar.kumar |
659 |
def updateItemStockPurchaseParams(self, item_id, numOfDaysStock, minStockLevel):
|
|
|
660 |
"""
|
|
|
661 |
Update/Add parameters required for heuristic purchase of Items
|
| 6833 |
amar.kumar |
662 |
"""
|
|
|
663 |
try:
|
|
|
664 |
update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel)
|
|
|
665 |
finally:
|
|
|
666 |
close_session()
|
|
|
667 |
|
| 6821 |
amar.kumar |
668 |
def getItemStockPurchaseParams(self, item_id):
|
|
|
669 |
"""
|
|
|
670 |
Get parameters required for heuristic purchase of Items
|
| 6833 |
amar.kumar |
671 |
"""
|
|
|
672 |
try:
|
|
|
673 |
return to_t_item_stock_purchase_params(get_item_stock_purchase_params(item_id))
|
|
|
674 |
finally:
|
|
|
675 |
close_session()
|
|
|
676 |
|
| 6821 |
amar.kumar |
677 |
def addOosStatusForItem(self, oosStatusMap, date):
|
|
|
678 |
"""
|
|
|
679 |
Add OOS status for Item
|
|
|
680 |
"""
|
| 6833 |
amar.kumar |
681 |
try:
|
|
|
682 |
add_oos_status_for_item(oosStatusMap, date)
|
|
|
683 |
finally:
|
|
|
684 |
close_session()
|
|
|
685 |
|
| 6832 |
amar.kumar |
686 |
def getOosStatusesForXDaysForItem(self, itemId, days):
|
|
|
687 |
"""
|
|
|
688 |
Get OOSStatus Objects for "days" number of days
|
|
|
689 |
"""
|
| 6833 |
amar.kumar |
690 |
try:
|
|
|
691 |
return [to_t_oos_status(oos) for oos in get_oos_statuses_for_x_days_for_item(itemId, days)]
|
|
|
692 |
finally:
|
| 6857 |
amar.kumar |
693 |
close_session()
|
|
|
694 |
|
|
|
695 |
def getNonZeroItemStockPurchaseParams(self):
|
|
|
696 |
"""
|
|
|
697 |
Get All ItemStockPurchaseParam objects where either minStockLevel or minNumOfDaysOfStock is zero
|
|
|
698 |
"""
|
|
|
699 |
try:
|
|
|
700 |
return [to_t_item_stock_purchase_params(ispp) for ispp in get_non_zero_item_stock_purchase_params()]
|
|
|
701 |
finally:
|
| 7149 |
amar.kumar |
702 |
close_session()
|
| 7972 |
amar.kumar |
703 |
|
|
|
704 |
def getLastNdaySaleForItem(self, itemId, numberOfDays):
|
|
|
705 |
"""
|
|
|
706 |
Get Sale for Last N day for an Item
|
|
|
707 |
"""
|
|
|
708 |
try:
|
|
|
709 |
return get_last_n_day_sale_for_item(itemId, numberOfDays)
|
|
|
710 |
finally:
|
|
|
711 |
close_session()
|
| 7149 |
amar.kumar |
712 |
def getBillableInventoryAndPendingOrders(self):
|
|
|
713 |
"""
|
|
|
714 |
Returns a list of inventory stock for items for which there are pending orders or have
|
|
|
715 |
billable inventory.
|
|
|
716 |
"""
|
|
|
717 |
try:
|
|
|
718 |
items_inventory = get_billable_inventory_and_pending_orders()
|
|
|
719 |
return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in items_inventory]
|
|
|
720 |
finally:
|
| 7281 |
kshitij.so |
721 |
close_session()
|
|
|
722 |
|
|
|
723 |
def getWarehouseName(self,warehouseId):
|
|
|
724 |
try:
|
|
|
725 |
name = get_warehouse_name(warehouseId)
|
|
|
726 |
return name
|
|
|
727 |
finally:
|
|
|
728 |
close_session()
|
|
|
729 |
|
|
|
730 |
def getAmazonInventoryForItem(self, amazonItemId):
|
| 7316 |
kshitij.so |
731 |
result = []
|
| 7281 |
kshitij.so |
732 |
try:
|
|
|
733 |
result = get_amazon_inventory_for_item(amazonItemId)
|
|
|
734 |
if result is not None:
|
|
|
735 |
result = to_t_amazon_inventory_snapshot(result)
|
|
|
736 |
except:
|
| 7316 |
kshitij.so |
737 |
return result
|
| 7281 |
kshitij.so |
738 |
finally:
|
|
|
739 |
close_session()
|
|
|
740 |
return result
|
|
|
741 |
|
|
|
742 |
def getAllAmazonInventory(self):
|
|
|
743 |
try:
|
|
|
744 |
amazoninventory = []
|
|
|
745 |
all_inventory = get_all_amazon_inventory()
|
|
|
746 |
for inventory in all_inventory:
|
|
|
747 |
amazoninventory.append(to_t_amazon_inventory_snapshot((inventory)))
|
|
|
748 |
return amazoninventory
|
|
|
749 |
finally:
|
|
|
750 |
close_session()
|
|
|
751 |
|
| 8282 |
kshitij.so |
752 |
def addOrUpdateAmazonInventoryForItem(self, amazoninventorysnapshot):
|
| 7281 |
kshitij.so |
753 |
try:
|
| 8282 |
kshitij.so |
754 |
return add_or_update_amazon_inventory_for_item(amazoninventorysnapshot)
|
| 7281 |
kshitij.so |
755 |
finally:
|
| 8182 |
amar.kumar |
756 |
close_session()
|
|
|
757 |
|
| 8282 |
kshitij.so |
758 |
def addOrUpdateAmazonFbaInventory(self,amazonfbainventorysnapshot):
|
|
|
759 |
try:
|
|
|
760 |
return add_or_update_amazon_fba_inventory(amazonfbainventorysnapshot)
|
|
|
761 |
finally:
|
|
|
762 |
close_session()
|
|
|
763 |
|
| 8182 |
amar.kumar |
764 |
def addUpdateHoldInventory(self, itemId, warehouseId, holdQuantity, source):
|
|
|
765 |
try:
|
|
|
766 |
add_update_hold_inventory(itemId, warehouseId, holdQuantity, source)
|
|
|
767 |
finally:
|
| 8282 |
kshitij.so |
768 |
close_session()
|
|
|
769 |
|
|
|
770 |
def getAmazonFbaItemInventory(self,itemId):
|
|
|
771 |
try:
|
|
|
772 |
return get_amazon_fba_inventory(itemId)
|
|
|
773 |
finally:
|
|
|
774 |
close_session()
|
|
|
775 |
|
| 8363 |
vikram.rag |
776 |
def getAllAmazonFbaItemInventory(self):
|
|
|
777 |
all_fba_inventory = []
|
| 8282 |
kshitij.so |
778 |
try:
|
| 8363 |
vikram.rag |
779 |
for inventory in get_all_amazon_fba_inventory():
|
|
|
780 |
all_fba_inventory.append(to_t_amazon_fba_inventory_snapshot(inventory))
|
|
|
781 |
return all_fba_inventory
|
| 8282 |
kshitij.so |
782 |
except:
|
|
|
783 |
return None
|
|
|
784 |
finally:
|
| 8363 |
vikram.rag |
785 |
close_session()
|
|
|
786 |
|
|
|
787 |
def getOursGoodWarehouseIdsForLocation(self,state_id):
|
|
|
788 |
ids=[]
|
| 8572 |
vikram.rag |
789 |
try:
|
|
|
790 |
for id in get_oursgood_warehouseids_for_location(state_id):
|
|
|
791 |
ids.append(id[0])
|
|
|
792 |
return ids
|
|
|
793 |
except:
|
|
|
794 |
return None
|
|
|
795 |
finally:
|
| 8954 |
vikram.rag |
796 |
close_session()
|
|
|
797 |
|
|
|
798 |
def getHoldInventoryDetailForItemForWarehouseIdExceptSource(self,item_id,warehouse_id,source):
|
|
|
799 |
try:
|
|
|
800 |
return get_holdinventorydetail_forItem_forWarehouseId_exceptsource(item_id,warehouse_id,source)
|
|
|
801 |
finally:
|
| 9404 |
vikram.rag |
802 |
close_session()
|
|
|
803 |
|
|
|
804 |
def getSnapdealInventoryForItem(self,item_id):
|
|
|
805 |
try:
|
|
|
806 |
return to_t_snapdeal_inventory_snapshot(get_snapdeal_inventory_for_item(item_id))
|
|
|
807 |
finally:
|
|
|
808 |
close_session()
|
|
|
809 |
def addOrUpdateSnapdealInventoryForItem(self,snapdealinventoryitem):
|
|
|
810 |
try:
|
|
|
811 |
add_or_update_snapdeal_inventor_for_item(snapdealinventoryitem)
|
|
|
812 |
finally:
|
|
|
813 |
close_session()
|
|
|
814 |
|
|
|
815 |
def getNlcForWarehouse(self,warehouse_id,item_id):
|
|
|
816 |
try:
|
|
|
817 |
return get_nlc_for_warehouse(warehouse_id,item_id)
|
|
|
818 |
finally:
|
| 9456 |
vikram.rag |
819 |
close_session()
|
|
|
820 |
|
| 9495 |
vikram.rag |
821 |
def addOrUpdateAllAmazonFbaInventory(self,allamazonfbainventorysnapshot):
|
| 9456 |
vikram.rag |
822 |
try:
|
| 9495 |
vikram.rag |
823 |
for amazonfbainventorysnapshot in allamazonfbainventorysnapshot:
|
|
|
824 |
add_or_update_amazon_fba_inventory(amazonfbainventorysnapshot)
|
| 9456 |
vikram.rag |
825 |
finally:
|
| 9482 |
vikram.rag |
826 |
close_session()
|
| 9495 |
vikram.rag |
827 |
|
|
|
828 |
def addOrUpdateAllSnapdealInventory(self,allsnapdealinventorysnapshot):
|
|
|
829 |
try:
|
|
|
830 |
for snapdealinventorysnapshot in allsnapdealinventorysnapshot:
|
|
|
831 |
add_or_update_snapdeal_inventor_for_item(snapdealinventorysnapshot)
|
|
|
832 |
finally:
|
|
|
833 |
close_session()
|
| 9456 |
vikram.rag |
834 |
|
| 9495 |
vikram.rag |
835 |
def getSnapdealInventorySnapshot(self):
|
| 9503 |
vikram.rag |
836 |
allsnapdealinventorysnapshot = []
|
|
|
837 |
try:
|
|
|
838 |
allsnapdealinventorysnapshot = get_snapdeal_inventory_snapshot()
|
|
|
839 |
for inventorysnapshot in allsnapdealinventorysnapshot:
|
|
|
840 |
to_t_snapdeal_inventory_snapshot(inventorysnapshot)
|
| 9495 |
vikram.rag |
841 |
return get_snapdeal_inventory_snapshot()
|
|
|
842 |
finally:
|
|
|
843 |
close_session()
|
|
|
844 |
|