| Line 14... |
Line 14... |
| 14 |
to_t_vendor_item_pricing, to_t_source
|
14 |
to_t_vendor_item_pricing, to_t_source
|
| 15 |
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
|
15 |
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
|
| 16 |
ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo, ItemChangeLog, \
|
16 |
ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo, ItemChangeLog, \
|
| 17 |
Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
|
17 |
Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
|
| 18 |
SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
|
18 |
SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
|
| 19 |
MissedInventoryUpdate, VendorItemProcurementDelay
|
19 |
MissedInventoryUpdate, VendorItemProcurementDelay, VendorHolidays
|
| 20 |
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
|
20 |
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
|
| 21 |
status, ItemShippingInfo
|
21 |
status, ItemShippingInfo, HolidayType
|
| 22 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
22 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
| 23 |
from shop2020.utils import EmailAttachmentSender
|
23 |
from shop2020.utils import EmailAttachmentSender
|
| 24 |
from shop2020.utils.EmailAttachmentSender import mail
|
24 |
from shop2020.utils.EmailAttachmentSender import mail
|
| 25 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
25 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
| 26 |
from sqlalchemy import desc, asc
|
26 |
from sqlalchemy import desc, asc
|
| Line 29... |
Line 29... |
| 29 |
from string import Template
|
29 |
from string import Template
|
| 30 |
from urllib2 import HTTPBasicAuthHandler
|
30 |
from urllib2 import HTTPBasicAuthHandler
|
| 31 |
import datetime
|
31 |
import datetime
|
| 32 |
import sys
|
32 |
import sys
|
| 33 |
import urllib2
|
33 |
import urllib2
|
| - |
|
34 |
import calendar
|
| 34 |
|
35 |
|
| 35 |
def initialize():
|
36 |
def initialize():
|
| 36 |
DataService.initialize()
|
37 |
DataService.initialize()
|
| 37 |
|
38 |
|
| 38 |
def get_all_items_by_status(status, offset=0, limit=None):
|
39 |
def get_all_items_by_status(status, offset=0, limit=None):
|
| Line 749... |
Line 750... |
| 749 |
else:
|
750 |
else:
|
| 750 |
expectedDelay = int(item.expectedDelay)
|
751 |
expectedDelay = int(item.expectedDelay)
|
| 751 |
|
752 |
|
| 752 |
if total_availability <= 0:
|
753 |
if total_availability <= 0:
|
| 753 |
expectedDelay = expectedDelay + __get_expected_procurement_delay(item)
|
754 |
expectedDelay = expectedDelay + __get_expected_procurement_delay(item)
|
| - |
|
755 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(item, expectedDelay)
|
| 754 |
|
756 |
|
| 755 |
return [logisticsLocation, int(warehouse_retid), total_availability, expectedDelay]
|
757 |
return [logisticsLocation, int(warehouse_retid), total_availability, expectedDelay]
|
| 756 |
|
758 |
|
| 757 |
def __get_warehouse_with_max_availability(warehouse_loc, warehouse_ids, item):
|
759 |
def __get_warehouse_with_max_availability(warehouse_loc, warehouse_ids, item):
|
| 758 |
|
760 |
|
| Line 802... |
Line 804... |
| 802 |
total_availability = total_availability + availability
|
804 |
total_availability = total_availability + availability
|
| 803 |
return total_availability
|
805 |
return total_availability
|
| 804 |
'''
|
806 |
'''
|
| 805 |
|
807 |
|
| 806 |
def __get_expected_procurement_delay(item):
|
808 |
def __get_expected_procurement_delay(item):
|
| 807 |
procurementDelay = 0
|
809 |
procurementDelay = 2
|
| 808 |
try:
|
810 |
try:
|
| 809 |
if item.preferredVendor:
|
811 |
if item.preferredVendor:
|
| 810 |
delays = VendorItemProcurementDelay.query.filter_by(vendor_id = item.preferredVendor, item_id = item.id).all()
|
812 |
delays = VendorItemProcurementDelay.query.filter_by(vendor_id = item.preferredVendor, item_id = item.id).all()
|
| 811 |
else:
|
813 |
else:
|
| 812 |
delays = VendorItemProcurementDelay.query.filter_by(item_id = item.id).all()
|
814 |
delays = VendorItemProcurementDelay.query.filter_by(item_id = item.id).all()
|
| Line 814... |
Line 816... |
| 814 |
procurementDelay= min([delay.procurementDelay for delay in delays])
|
816 |
procurementDelay= min([delay.procurementDelay for delay in delays])
|
| 815 |
except Exception as e:
|
817 |
except Exception as e:
|
| 816 |
print e
|
818 |
print e
|
| 817 |
return procurementDelay
|
819 |
return procurementDelay
|
| 818 |
|
820 |
|
| - |
|
821 |
def __get_vendor_holiday_delay(item, expectedDelay):
|
| - |
|
822 |
holidayDelay = 0
|
| 819 |
|
823 |
try:
|
| - |
|
824 |
if item.preferredVendor:
|
| - |
|
825 |
holidays = VendorHolidays.query.filter_by(vendor_id = item.preferredVendor).all()
|
| - |
|
826 |
currentDate = datetime.date.today()
|
| - |
|
827 |
expectedDate = currentDate + datetime.timedelta(days = expectedDelay)
|
| - |
|
828 |
for holiday in holidays:
|
| - |
|
829 |
if holiday.holidayType == HolidayType.WEEKLY and holiday.holidayValue != calendar.SUNDAY:
|
| - |
|
830 |
if currentDate.weekday() > holiday.holidayValue:
|
| - |
|
831 |
holidayDate = currentDate + datetime.timedelta(days=holiday.holidayValue-currentDate.weekday(), weeks=1)
|
| - |
|
832 |
else:
|
| - |
|
833 |
holidayDate = currentDate + datetime.timedelta(days=holiday.holidayValue-currentDate.weekday())
|
| - |
|
834 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
| - |
|
835 |
holidayDelay = holidayDelay + 1
|
| - |
|
836 |
elif holiday.holidayType == HolidayType.MONTHLY:
|
| - |
|
837 |
holidayDate = datetime.date(currentDate.year, currentDate.month, holiday.holidayValue)
|
| - |
|
838 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
| - |
|
839 |
holidayDelay = holidayDelay + 1
|
| - |
|
840 |
elif holiday.holidayType == HolidayType.SPECIFIC:
|
| - |
|
841 |
holidayDate = datetime.date(holiday.holidayValue[:4], holiday.holidayValue[4:6], holiday.holidayValue[6:8])
|
| - |
|
842 |
if holidayDate >= currentDate and holidayDate <= expectedDate:
|
| - |
|
843 |
holidayDelay = holidayDelay + 1
|
| - |
|
844 |
except Exception as e:
|
| - |
|
845 |
print e
|
| - |
|
846 |
return holidayDelay
|
| 820 |
def get_warehouses_for_item(item_id):
|
847 |
def get_warehouses_for_item(item_id):
|
| 821 |
|
848 |
|
| 822 |
if not item_id:
|
849 |
if not item_id:
|
| 823 |
raise InventoryServiceException(101, "bad item_id")
|
850 |
raise InventoryServiceException(101, "bad item_id")
|
| 824 |
item = get_item(item_id)
|
851 |
item = get_item(item_id)
|