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