| Line 13... |
Line 13... |
| 13 |
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
|
13 |
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
|
| 14 |
ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \
|
14 |
ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \
|
| 15 |
VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \
|
15 |
VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \
|
| 16 |
VendorItemProcurementDelay, VendorHolidays, ItemAvailabilityCache, \
|
16 |
VendorItemProcurementDelay, VendorHolidays, ItemAvailabilityCache, \
|
| 17 |
CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \
|
17 |
CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \
|
| 18 |
OOSStatus, AmazonInventorySnapshot, StateMaster
|
18 |
OOSStatus, AmazonInventorySnapshot, StateMaster, HoldInventoryDetail
|
| 19 |
from shop2020.thriftpy.model.v1.inventory.ttypes import \
|
19 |
from shop2020.thriftpy.model.v1.inventory.ttypes import \
|
| 20 |
InventoryServiceException, HolidayType, InventoryType, WarehouseType
|
20 |
InventoryServiceException, HolidayType, InventoryType, WarehouseType
|
| 21 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
21 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
| 22 |
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
|
22 |
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
|
| 23 |
from shop2020.utils import EmailAttachmentSender
|
23 |
from shop2020.utils import EmailAttachmentSender
|
| Line 349... |
Line 349... |
| 349 |
reservation.created_timestamp = to_py_date(created_timestamp)
|
349 |
reservation.created_timestamp = to_py_date(created_timestamp)
|
| 350 |
reservation.promised_shipping_timestamp = to_py_date(promised_shipping_timestamp)
|
350 |
reservation.promised_shipping_timestamp = to_py_date(promised_shipping_timestamp)
|
| 351 |
reservation.reserved = quantity
|
351 |
reservation.reserved = quantity
|
| 352 |
|
352 |
|
| 353 |
session.commit()
|
353 |
session.commit()
|
| - |
|
354 |
|
| - |
|
355 |
try:
|
| - |
|
356 |
order_client = TransactionClient().get_client()
|
| - |
|
357 |
order = order_client.getOrder(order_id)
|
| - |
|
358 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id = item_id, warehouse_id = warehouse_id, source = order.source).first()
|
| - |
|
359 |
if holdInventoryDetail is not None:
|
| - |
|
360 |
holdInventoryDetail.held = holdInventoryDetail.held -quantity
|
| - |
|
361 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=warehouse_id)
|
| - |
|
362 |
if current_inventory_snapshot is not None:
|
| - |
|
363 |
if current_inventory_snapshot.held>0:
|
| - |
|
364 |
current_inventory_snapshot.held = current_inventory_snapshot.held - quantity
|
| - |
|
365 |
session.commit()
|
| - |
|
366 |
except:
|
| - |
|
367 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
| - |
|
368 |
|
| 354 |
#**Update item availability cache**#
|
369 |
#**Update item availability cache**#
|
| 355 |
clear_item_availability_cache(item_id)
|
370 |
clear_item_availability_cache(item_id)
|
| 356 |
return True
|
371 |
return True
|
| 357 |
|
372 |
|
| 358 |
def update_reservation_for_order(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
373 |
def update_reservation_for_order(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
| Line 381... |
Line 396... |
| 381 |
new_reservation.order_id = order_id
|
396 |
new_reservation.order_id = order_id
|
| 382 |
new_reservation.created_timestamp = to_py_date(created_timestamp)
|
397 |
new_reservation.created_timestamp = to_py_date(created_timestamp)
|
| 383 |
new_reservation.promised_shipping_timestamp = to_py_date(promised_shipping_timestamp)
|
398 |
new_reservation.promised_shipping_timestamp = to_py_date(promised_shipping_timestamp)
|
| 384 |
new_reservation.reserved = quantity
|
399 |
new_reservation.reserved = quantity
|
| 385 |
|
400 |
|
| - |
|
401 |
try:
|
| - |
|
402 |
order_client = TransactionClient().get_client()
|
| - |
|
403 |
order = order_client.getOrder(order_id)
|
| - |
|
404 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id = item_id, warehouse_id = warehouse_id, source = order.source).first()
|
| - |
|
405 |
if holdInventoryDetail is not None:
|
| - |
|
406 |
holdInventoryDetail.held = holdInventoryDetail.held -quantity
|
| - |
|
407 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=warehouse_id)
|
| - |
|
408 |
if current_inventory_snapshot is not None:
|
| - |
|
409 |
if current_inventory_snapshot.held>0:
|
| - |
|
410 |
current_inventory_snapshot.held = current_inventory_snapshot.held - quantity
|
| - |
|
411 |
session.commit()
|
| - |
|
412 |
except:
|
| - |
|
413 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
| - |
|
414 |
|
| 386 |
order_client = TransactionClient().get_client()
|
415 |
order_client = TransactionClient().get_client()
|
| 387 |
order = order_client.getOrder(order_id)
|
416 |
order = order_client.getOrder(order_id)
|
| 388 |
for lineitem in order.lineitems:
|
417 |
for lineitem in order.lineitems:
|
| 389 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id)
|
418 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id)
|
| 390 |
try:
|
419 |
try:
|
| Line 402... |
Line 431... |
| 402 |
try:
|
431 |
try:
|
| 403 |
if current_inventory_snapshot.reserved < 0:
|
432 |
if current_inventory_snapshot.reserved < 0:
|
| 404 |
item = __get_item_from_master(lineitem.item_id)
|
433 |
item = __get_item_from_master(lineitem.item_id)
|
| 405 |
__send_alert_for_negative_reserved(item, current_inventory_snapshot.reserved, get_Warehouse(order.fulfilmentWarehouseId))
|
434 |
__send_alert_for_negative_reserved(item, current_inventory_snapshot.reserved, get_Warehouse(order.fulfilmentWarehouseId))
|
| 406 |
except:
|
435 |
except:
|
| 407 |
print "Error in send negative reserved alert:", sys.exc_info()[0]
|
436 |
print "Error in sending negative reserved alert:", sys.exc_info()[0]
|
| 408 |
return False
|
437 |
return False
|
| 409 |
except:
|
438 |
except:
|
| 410 |
print "Error in reducing reservation for item:", sys.exc_info()[0]
|
439 |
print "Error in reducing reservation for item:", sys.exc_info()[0]
|
| 411 |
return False
|
440 |
return False
|
| 412 |
session.commit()
|
441 |
session.commit()
|
| Line 586... |
Line 615... |
| 586 |
|
615 |
|
| 587 |
if not ignoreAvailability:
|
616 |
if not ignoreAvailability:
|
| 588 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
617 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
| 589 |
entry.reserved = max(entry.reserved, 0)
|
618 |
entry.reserved = max(entry.reserved, 0)
|
| 590 |
#if entry.availability > entry.reserved:
|
619 |
#if entry.availability > entry.reserved:
|
| 591 |
warehousesAvailability[entry.warehouse_id] = [entry.availability, entry.reserved]
|
620 |
warehousesAvailability[entry.warehouse_id] = [entry.availability, entry.reserved, entry.held]
|
| 592 |
|
621 |
|
| 593 |
if len(ignoredWhs) > 0:
|
622 |
if len(ignoredWhs) > 0:
|
| 594 |
for whid in ignoredWhs:
|
623 |
for whid in ignoredWhs:
|
| 595 |
if warehousesAvailability.has_key(whid):
|
624 |
if warehousesAvailability.has_key(whid):
|
| 596 |
warehousesAvailability[whid][0] = 0
|
625 |
warehousesAvailability[whid][0] = 0
|
| 597 |
warehousesAvailability[whid][1] = 0
|
626 |
warehousesAvailability[whid][1] = 0
|
| - |
|
627 |
warehousesAvailability[whid][2] = 0
|
| 598 |
|
628 |
|
| 599 |
for warehouse in warehouses.values():
|
629 |
for warehouse in warehouses.values():
|
| 600 |
if not ignoreAvailability:
|
630 |
if not ignoreAvailability:
|
| 601 |
#TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
631 |
#TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
| 602 |
if warehouse.id not in warehousesAvailability:
|
632 |
if warehouse.id not in warehousesAvailability:
|
| 603 |
continue
|
633 |
continue
|
| 604 |
entry = warehousesAvailability[warehouse.id]
|
634 |
entry = warehousesAvailability[warehouse.id]
|
| 605 |
if warehouse.billingWarehouseId in availabilityForBillingWarehouses:
|
635 |
if warehouse.billingWarehouseId in availabilityForBillingWarehouses:
|
| 606 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
636 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
| 607 |
availabilityForBillingWarehouses[warehouse.billingWarehouseId] = availabilityForBillingWarehouses[warehouse.billingWarehouseId] + entry[0] - entry[1]
|
637 |
availabilityForBillingWarehouses[warehouse.billingWarehouseId] = availabilityForBillingWarehouses[warehouse.billingWarehouseId] + entry[0] - entry[1] - entry[2]
|
| 608 |
else:
|
638 |
else:
|
| 609 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
639 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
| 610 |
availabilityForBillingWarehouses[warehouse.billingWarehouseId] = entry[0] - entry[1]
|
640 |
availabilityForBillingWarehouses[warehouse.billingWarehouseId] = entry[0] - entry[1] - entry[2]
|
| 611 |
if entry[0] <= entry[1]:
|
641 |
if entry[0] <= (entry[1] + entry[2]):
|
| 612 |
continue
|
642 |
continue
|
| 613 |
total_availability += entry[0] - entry[1]
|
643 |
total_availability += entry[0] - entry[1] - entry[2]
|
| 614 |
|
644 |
|
| 615 |
# Missing transfer price cases should not impact warehouse assignment
|
645 |
# Missing transfer price cases should not impact warehouse assignment
|
| 616 |
transferPrice = None
|
646 |
transferPrice = None
|
| 617 |
if item_pricing.has_key(warehouse.vendor_id):
|
647 |
if item_pricing.has_key(warehouse.vendor_id):
|
| 618 |
transferPrice = item_pricing[warehouse.vendor_id].nlc
|
648 |
transferPrice = item_pricing[warehouse.vendor_id].nlc
|
| Line 638... |
Line 668... |
| 638 |
entry.reserved = max(entry.reserved, 0)
|
668 |
entry.reserved = max(entry.reserved, 0)
|
| 639 |
if warehouses.has_key(entry.warehouse_id):
|
669 |
if warehouses.has_key(entry.warehouse_id):
|
| 640 |
warehouse = warehouses[entry.warehouse_id]
|
670 |
warehouse = warehouses[entry.warehouse_id]
|
| 641 |
#if entry.availability > entry.reserved:
|
671 |
#if entry.availability > entry.reserved:
|
| 642 |
if entry.warehouse_id not in ignoredWhs:
|
672 |
if entry.warehouse_id not in ignoredWhs:
|
| 643 |
total_availability += entry.availability - entry.reserved
|
673 |
total_availability += entry.availability - entry.reserved - entry.held
|
| 644 |
if entry.availability - entry.reserved <= 0:
|
674 |
if entry.availability - entry.reserved - entry.held <= 0:
|
| 645 |
continue
|
675 |
continue
|
| 646 |
transferDelay = warehouse.transferDelayInHours
|
676 |
transferDelay = warehouse.transferDelayInHours
|
| 647 |
if minTransferDelay is None or minTransferDelay >= transferDelay:
|
677 |
if minTransferDelay is None or minTransferDelay >= transferDelay:
|
| 648 |
if minTransferDelay != transferDelay:
|
678 |
if minTransferDelay != transferDelay:
|
| 649 |
minTransferDelayWarehouses = {}
|
679 |
minTransferDelayWarehouses = {}
|
| Line 1154... |
Line 1184... |
| 1154 |
else:
|
1184 |
else:
|
| 1155 |
inventory.availability = amazoninventorysnapshot.availability
|
1185 |
inventory.availability = amazoninventorysnapshot.availability
|
| 1156 |
inventory.reserved = amazoninventorysnapshot.reserved
|
1186 |
inventory.reserved = amazoninventorysnapshot.reserved
|
| 1157 |
session.commit()
|
1187 |
session.commit()
|
| 1158 |
|
1188 |
|
| - |
|
1189 |
def add_update_hold_inventory(itemId, warehouseId, holdQuantity, source):
|
| - |
|
1190 |
holdInventoryDetail = HoldInventoryDetail.get_by(item_id = itemId, warehouse_id=warehouseId, source = source)
|
| - |
|
1191 |
if holdInventoryDetail is None:
|
| - |
|
1192 |
diffTobeAddedInCIS = holdQuantity
|
| - |
|
1193 |
hold_inventory_detail = HoldInventoryDetail()
|
| - |
|
1194 |
hold_inventory_detail.item_id = itemId
|
| - |
|
1195 |
hold_inventory_detail.warehouse_id = warehouseId
|
| - |
|
1196 |
hold_inventory_detail.held = holdQuantity
|
| - |
|
1197 |
hold_inventory_detail.source = source
|
| 1159 |
|
1198 |
else:
|
| 1160 |
|
- |
|
| - |
|
1199 |
hold_inventory_detail.held = holdQuantity
|
| - |
|
1200 |
diffTobeAddedInCIS = holdQuantity - holdInventoryDetail.held
|
| 1161 |
|
1201 |
|
| - |
|
1202 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| - |
|
1203 |
if not current_inventory_snapshot:
|
| - |
|
1204 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| - |
|
1205 |
current_inventory_snapshot.item_id = itemId
|
| - |
|
1206 |
current_inventory_snapshot.warehouse_id = warehouseId
|
| - |
|
1207 |
current_inventory_snapshot.availability = 0
|
| - |
|
1208 |
current_inventory_snapshot.reserved = 0
|
| - |
|
1209 |
current_inventory_snapshot.held = 0
|
| - |
|
1210 |
current_inventory_snapshot.held = current_inventory_snapshot.held + diffTobeAddedInCIS
|
| - |
|
1211 |
session.commit()
|
| - |
|
1212 |
#**Update item availability cache**#
|
| - |
|
1213 |
clear_item_availability_cache(itemId)
|