| Line 10... |
Line 10... |
| 10 |
ItemChangeLog, BestSellers, Category
|
10 |
ItemChangeLog, BestSellers, Category
|
| 11 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
11 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
| 12 |
InventoryServiceException, status
|
12 |
InventoryServiceException, status
|
| 13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
| 14 |
import datetime
|
14 |
import datetime
|
| - |
|
15 |
import sys
|
| 15 |
from shop2020.utils.Utils import log_entry, to_py_date
|
16 |
from shop2020.utils.Utils import log_entry, to_py_date
|
| 16 |
from sqlalchemy import desc, asc
|
17 |
from sqlalchemy import desc, asc
|
| 17 |
|
18 |
|
| 18 |
|
19 |
|
| 19 |
def initialize():
|
20 |
def initialize():
|
| Line 261... |
Line 262... |
| 261 |
if not current_inventory_snapshot:
|
262 |
if not current_inventory_snapshot:
|
| 262 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
263 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| 263 |
current_inventory_snapshot.item = item
|
264 |
current_inventory_snapshot.item = item
|
| 264 |
current_inventory_snapshot.warehouse = warehouse
|
265 |
current_inventory_snapshot.warehouse = warehouse
|
| 265 |
current_inventory_snapshot.availibility = 0
|
266 |
current_inventory_snapshot.availibility = 0
|
| - |
|
267 |
current_inventory_snapshot.reserved = 0
|
| 266 |
# added the difference in the current inventory
|
268 |
# added the difference in the current inventory
|
| 267 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
|
269 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
|
| 268 |
except:
|
270 |
except:
|
| 269 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
271 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 270 |
session.commit()
|
272 |
session.commit()
|
| Line 363... |
Line 365... |
| 363 |
|
365 |
|
| 364 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id)
|
366 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id)
|
| 365 |
query = query.filter_by(item_id = item.id)
|
367 |
query = query.filter_by(item_id = item.id)
|
| 366 |
try:
|
368 |
try:
|
| 367 |
current_inventory_snapshot = query.one()
|
369 |
current_inventory_snapshot = query.one()
|
| 368 |
return current_inventory_snapshot.availibility
|
370 |
return current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
| 369 |
except:
|
371 |
except:
|
| 370 |
return 0
|
372 |
return 0
|
| 371 |
"""
|
373 |
"""
|
| 372 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id == warehouse_id, CurrentInventorySnapshot.item_id == item_id).one()
|
374 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id == warehouse_id, CurrentInventorySnapshot.item_id == item_id).one()
|
| 373 |
if not current_inventory_snapshot:
|
375 |
if not current_inventory_snapshot:
|
| 374 |
return 0
|
376 |
return 0
|
| 375 |
else:
|
377 |
else:
|
| 376 |
return current_inventory_snapshot.availibility
|
378 |
return current_inventory_snapshot.availibility
|
| 377 |
"""
|
379 |
"""
|
| 378 |
|
380 |
|
| - |
|
381 |
def reserve_item_in_warehouse(item_id, warehouse_id, quantity):
|
| - |
|
382 |
if not warehouse_id:
|
| - |
|
383 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| - |
|
384 |
if not item_id:
|
| - |
|
385 |
raise InventoryServiceException(101, "bad item_id")
|
| - |
|
386 |
|
| - |
|
387 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
|
| - |
|
388 |
try:
|
| - |
|
389 |
current_inventory_snapshot = query.one()
|
| - |
|
390 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved + quantity
|
| - |
|
391 |
session.commit()
|
| - |
|
392 |
return True
|
| - |
|
393 |
except:
|
| - |
|
394 |
print "Unexpected error:", sys.exc_info()[0]
|
| - |
|
395 |
return False
|
| - |
|
396 |
|
| - |
|
397 |
def reduce_reservation_count(item_id, warehouse_id, quantity):
|
| - |
|
398 |
if not warehouse_id:
|
| - |
|
399 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| - |
|
400 |
if not item_id:
|
| - |
|
401 |
raise InventoryServiceException(101, "bad item_id")
|
| - |
|
402 |
|
| - |
|
403 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
|
| - |
|
404 |
try:
|
| - |
|
405 |
current_inventory_snapshot = query.one()
|
| - |
|
406 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
|
| - |
|
407 |
session.commit()
|
| - |
|
408 |
return True
|
| - |
|
409 |
except:
|
| - |
|
410 |
print "Unexpected error:", sys.exc_info()[0]
|
| - |
|
411 |
return False
|
| - |
|
412 |
|
| 379 |
def mark_item_as_content_complete(entity_id):
|
413 |
def mark_item_as_content_complete(entity_id):
|
| 380 |
content_complete_status = status.CONTENT_COMPLETE
|
414 |
content_complete_status = status.CONTENT_COMPLETE
|
| 381 |
items = Item.query.filter_by(catalog_item_id=entity_id).all()
|
415 |
items = Item.query.filter_by(catalog_item_id=entity_id).all()
|
| 382 |
current_timestamp = datetime.datetime.now()
|
416 |
current_timestamp = datetime.datetime.now()
|
| 383 |
for item in items:
|
417 |
for item in items:
|
| Line 402... |
Line 436... |
| 402 |
warehouse_ids = [warehouse.id for warehouse in warehouses]
|
436 |
warehouse_ids = [warehouse.id for warehouse in warehouses]
|
| 403 |
warehouse_retid = -1
|
437 |
warehouse_retid = -1
|
| 404 |
global_availability = 0
|
438 |
global_availability = 0
|
| 405 |
for warehouse_id in warehouse_ids:
|
439 |
for warehouse_id in warehouse_ids:
|
| 406 |
try:
|
440 |
try:
|
| 407 |
availability = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one().availibility
|
441 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one()
|
| - |
|
442 |
availability = current_inventory_snapshot.availibility - current_inventory_snapshot.reserved
|
| 408 |
except:
|
443 |
except:
|
| 409 |
availability = 0
|
444 |
availability = 0
|
| 410 |
if availability > global_availability:
|
445 |
if availability > global_availability:
|
| 411 |
warehouse_retid = warehouse_id
|
446 |
warehouse_retid = warehouse_id
|
| 412 |
global_availability = availability
|
447 |
global_availability = availability
|