| Line 11... |
Line 11... |
| 11 |
from shop2020.model.v1.inventory.impl.Convertors import to_t_warehouse, \
|
11 |
from shop2020.model.v1.inventory.impl.Convertors import to_t_warehouse, \
|
| 12 |
to_t_itemidwarehouseid
|
12 |
to_t_itemidwarehouseid
|
| 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 |
VendorHolidays, ItemAvailabilityCache, \
|
| 17 |
CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \
|
17 |
CurrentReservationSnapshot, IgnoredInventoryUpdateItems, ItemStockPurchaseParams, \
|
| 18 |
OOSStatus, AmazonInventorySnapshot, StateMaster, HoldInventoryDetail,AmazonFbaInventorySnapshot
|
18 |
OOSStatus, AmazonInventorySnapshot, StateMaster, HoldInventoryDetail,AmazonFbaInventorySnapshot
|
| 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
|
| Line 587... |
Line 587... |
| 587 |
expectedDelay = expectedDelay + 2
|
587 |
expectedDelay = expectedDelay + 2
|
| 588 |
else:
|
588 |
else:
|
| 589 |
if warehouse.transferDelayInHours:
|
589 |
if warehouse.transferDelayInHours:
|
| 590 |
expectedDelay = expectedDelay + warehouse.transferDelayInHours / 24
|
590 |
expectedDelay = expectedDelay + warehouse.transferDelayInHours / 24
|
| 591 |
|
591 |
|
| - |
|
592 |
if warehouse.warehouseType == WarehouseType.THIRD_PARTY:
|
| - |
|
593 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(warehouse.vendor_id, expectedDelay)
|
| - |
|
594 |
|
| 592 |
total_availability = 0
|
595 |
total_availability = 0
|
| 593 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
596 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
| 594 |
if entry.warehouse_id not in ignoredWhs:
|
597 |
if entry.warehouse_id not in ignoredWhs:
|
| 595 |
total_availability += entry.availability - entry.reserved
|
598 |
total_availability += entry.availability - entry.reserved
|
| 596 |
|
599 |
|
| Line 699... |
Line 702... |
| 699 |
max_availability = availability
|
702 |
max_availability = availability
|
| 700 |
total_availability += availability
|
703 |
total_availability += availability
|
| 701 |
|
704 |
|
| 702 |
return [warehouse_retid, total_availability]
|
705 |
return [warehouse_retid, total_availability]
|
| 703 |
|
706 |
|
| 704 |
def __get_expected_procurement_delay(item_id, preferredVendor):
|
707 |
def __get_vendor_holiday_delay(vendor_id, expectedDelay):
|
| 705 |
procurementDelay = 2
|
- |
|
| 706 |
try:
|
- |
|
| 707 |
if preferredVendor:
|
- |
|
| 708 |
delays = VendorItemProcurementDelay.query.filter_by(vendor_id = preferredVendor, item_id = item_id).all()
|
- |
|
| 709 |
else:
|
- |
|
| 710 |
delays = VendorItemProcurementDelay.query.filter_by(item_id = item_id).all()
|
- |
|
| 711 |
|
- |
|
| 712 |
procurementDelay= min([delay.procurementDelay for delay in delays])
|
- |
|
| 713 |
except Exception as e:
|
- |
|
| 714 |
print e
|
- |
|
| 715 |
return procurementDelay
|
- |
|
| 716 |
|
- |
|
| 717 |
def __get_vendor_holiday_delay(preferredVendor, expectedDelay):
|
708 |
## If vendor is closed two days continuously
|
| 718 |
holidayDelay = 0
|
709 |
holidayDelay = 0
|
| 719 |
try:
|
- |
|
| 720 |
if preferredVendor:
|
- |
|
| 721 |
holidays = VendorHolidays.query.filter_by(vendor_id = preferredVendor).all()
|
- |
|
| 722 |
currentDate = datetime.date.today()
|
710 |
currentDate = datetime.date.today()
|
| 723 |
expectedDate = currentDate + datetime.timedelta(days = expectedDelay)
|
711 |
expectedDate = currentDate + datetime.timedelta(days = expectedDelay)
|
| 724 |
for holiday in holidays:
|
- |
|
| 725 |
if holiday.holidayType == HolidayType.WEEKLY and holiday.holidayValue != calendar.SUNDAY:
|
- |
|
| 726 |
if currentDate.weekday() > holiday.holidayValue:
|
- |
|
| 727 |
holidayDate = currentDate + datetime.timedelta(days=holiday.holidayValue-currentDate.weekday(), weeks=1)
|
712 |
holidays = VendorHolidays.query.filter(VendorHolidays.vendor_id == vendor_id).filter(VendorHolidays.date.between(currentDate, expectedDate)).all()
|
| 728 |
else:
|
713 |
if holidays:
|
| 729 |
holidayDate = currentDate + datetime.timedelta(days=holiday.holidayValue-currentDate.weekday())
|
- |
|
| 730 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
- |
|
| 731 |
holidayDelay = holidayDelay + 1
|
- |
|
| 732 |
elif holiday.holidayType == HolidayType.MONTHLY:
|
- |
|
| 733 |
holidayDate = datetime.date(currentDate.year, currentDate.month, holiday.holidayValue)
|
- |
|
| 734 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
- |
|
| 735 |
holidayDelay = holidayDelay + 1
|
714 |
holidayDelay = holidayDelay + len(holidays)
|
| 736 |
elif holiday.holidayType == HolidayType.SPECIFIC:
|
- |
|
| 737 |
holidayValue = str(holiday.holidayValue)
|
- |
|
| 738 |
holidayDate = datetime.date(int(holidayValue[:4]), int(holidayValue[4:6]), int(holidayValue[6:8]))
|
- |
|
| 739 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
- |
|
| 740 |
holidayDelay = holidayDelay + 1
|
- |
|
| 741 |
except Exception as e:
|
- |
|
| 742 |
print e
|
- |
|
| 743 |
return holidayDelay
|
715 |
return holidayDelay
|
| 744 |
|
716 |
|
| 745 |
def get_item_pricing(item_id, vendorId):
|
717 |
def get_item_pricing(item_id, vendorId):
|
| 746 |
'''
|
718 |
'''
|
| 747 |
if vendor id is -1 then we calculate an average transfer price to be populated
|
719 |
if vendor id is -1 then we calculate an average transfer price to be populated
|