| Line 18... |
Line 18... |
| 18 |
IgnoredInventoryUpdateItems, ItemStockPurchaseParams, OOSStatus, \
|
18 |
IgnoredInventoryUpdateItems, ItemStockPurchaseParams, OOSStatus, \
|
| 19 |
AmazonInventorySnapshot, StateMaster, HoldInventoryDetail, \
|
19 |
AmazonInventorySnapshot, StateMaster, HoldInventoryDetail, \
|
| 20 |
AmazonFbaInventorySnapshot, SnapdealInventorySnapshot, FlipkartInventorySnapshot, \
|
20 |
AmazonFbaInventorySnapshot, SnapdealInventorySnapshot, FlipkartInventorySnapshot, \
|
| 21 |
SnapdealStockAtEOD, FlipkartStockAtEOD, StockWeightedNlcInfo, \
|
21 |
SnapdealStockAtEOD, FlipkartStockAtEOD, StockWeightedNlcInfo, \
|
| 22 |
ItemLocationAvailabilityCache
|
22 |
ItemLocationAvailabilityCache
|
| - |
|
23 |
from shop2020.thriftpy.logistics.ttypes import LocationInfo, PickUpType
|
| 23 |
from shop2020.thriftpy.model.v1.inventory.ttypes import \
|
24 |
from shop2020.thriftpy.model.v1.inventory.ttypes import \
|
| 24 |
InventoryServiceException, HolidayType, InventoryType, WarehouseType,\
|
25 |
InventoryServiceException, HolidayType, InventoryType, WarehouseType, \
|
| 25 |
ItemLocationAvailability, ItemPincodeAvailability
|
26 |
ItemLocationAvailability, ItemPincodeAvailability
|
| 26 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType, TransactionStatus
|
27 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType, TransactionStatus
|
| 27 |
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
|
28 |
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
|
| 28 |
from shop2020.utils import EmailAttachmentSender
|
29 |
from shop2020.utils import EmailAttachmentSender
|
| 29 |
from shop2020.utils.EmailAttachmentSender import mail
|
30 |
from shop2020.utils.EmailAttachmentSender import mail
|
| 30 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
31 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| - |
|
32 |
from shop2020.utils.caching.SimpleCaching import memoized
|
| 31 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
33 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
| 32 |
from sqlalchemy.sql import or_
|
34 |
from sqlalchemy.sql import or_
|
| 33 |
from sqlalchemy.sql.expression import and_, func, distinct, desc
|
35 |
from sqlalchemy.sql.expression import and_, func, distinct, desc
|
| 34 |
from sqlalchemy.sql.functions import count
|
36 |
from sqlalchemy.sql.functions import count
|
| 35 |
import calendar
|
37 |
import calendar
|
| 36 |
import datetime
|
38 |
import datetime
|
| - |
|
39 |
import json
|
| 37 |
import math
|
40 |
import math
|
| 38 |
import sys
|
41 |
import sys
|
| 39 |
import threading
|
42 |
import threading
|
| 40 |
import json
|
- |
|
| 41 |
from shop2020.thriftpy.logistics.ttypes import LocationInfo, PickUpType
|
- |
|
| 42 |
|
43 |
|
| 43 |
to_addresses = ["khushal.bhatia@shop2020.in", "chaitnaya.vats@shop2020.in", "chandan.kumar@shop2020.in",'manoj.kumar@shop2020.in']
|
44 |
to_addresses = ["khushal.bhatia@shop2020.in", "chaitnaya.vats@shop2020.in", "chandan.kumar@shop2020.in",'manoj.kumar@shop2020.in']
|
| 44 |
mail_user = "cnc.center@shop2020.in"
|
45 |
mail_user = "cnc.center@shop2020.in"
|
| 45 |
mail_password = "5h0p2o2o"
|
46 |
mail_password = "5h0p2o2o"
|
| 46 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
47 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
| 47 |
193 : [5839] }
|
48 |
193 : [5839] }
|
| 48 |
|
49 |
|
| 49 |
pincodePricingServiceabilityMap = {}
|
50 |
pincodePricingServiceabilityMap = {}
|
| 50 |
warehouseMap = {}
|
51 |
warehouseMap = {}
|
| 51 |
stateWarehouseMap = {}
|
- |
|
| 52 |
|
52 |
|
| 53 |
OOS_CALCULATION_TIME = 23
|
53 |
OOS_CALCULATION_TIME = 23
|
| 54 |
|
54 |
|
| 55 |
#right now these warehouse ids are ignored.
|
55 |
#right now these warehouse ids are ignored.
|
| 56 |
#physicalWarehouseIdsForFofo = [7678, 7681]
|
56 |
#physicalWarehouseIdsForFofo = [7678, 7681]
|
| Line 58... |
Line 58... |
| 58 |
vendorWarehouseIdsForFofo = []
|
58 |
vendorWarehouseIdsForFofo = []
|
| 59 |
|
59 |
|
| 60 |
last_date = datetime.date.today()
|
60 |
last_date = datetime.date.today()
|
| 61 |
adjusted_dates={}
|
61 |
adjusted_dates={}
|
| 62 |
|
62 |
|
| 63 |
partnerMap = {}
|
63 |
partnerMap = {}
|
| - |
|
64 |
|
| - |
|
65 |
|
| - |
|
66 |
default_virtual_vendor = 285
|
| - |
|
67 |
virtualVendorWarehouses = {}
|
| - |
|
68 |
bra
|
| 64 |
|
69 |
|
| 65 |
def initialize(dbname='inventory', db_hostname="localhost"):
|
70 |
def initialize(dbname='inventory', db_hostname="localhost"):
|
| 66 |
DataService.initialize(dbname, db_hostname)
|
71 |
DataService.initialize(dbname, db_hostname)
|
| 67 |
__populateWarehouseMap()
|
72 |
__populateWarehouseMap()
|
| 68 |
|
73 |
|
| - |
|
74 |
@memoized(3600)
|
| 69 |
def __populateWarehouseMap():
|
75 |
def __populateWarehouseMap():
|
| 70 |
warehouses = Warehouse.query.filter(Warehouse.warehouseType.in_(['OURS', 'THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').all()
|
76 |
warehouses = Warehouse.query.filter(Warehouse.warehouseType.in_(['OURS', 'THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').all()
|
| 71 |
for warehouse in warehouses:
|
77 |
for warehouse in warehouses:
|
| 72 |
warehouseMap[warehouse.id] = warehouse
|
78 |
warehouseMap[warehouse.id] = warehouse
|
| 73 |
if not stateWarehouseMap.has_key(warehouse.state_id):
|
79 |
if warehouse.vendor_id==default_virtual_vendor and warehouse.warehouseType == 'THIRD_PARTY':
|
| 74 |
stateWarehouseMap[warehouse.state_id] = []
|
80 |
virtualVendorWarehouses[warehouse.state_id] = warehouse.id
|
| 75 |
stateWarehouseMap[warehouse.logisticsLocation].append(warehouse.id)
|
- |
|
| 76 |
if warehouse.billingWarehouseId in physicalWarehouseIdsForFofo:
|
81 |
if warehouse.billingWarehouseId in physicalWarehouseIdsForFofo:
|
| 77 |
vendorWarehouseIdsForFofo.append(warehouse.id)
|
82 |
vendorWarehouseIdsForFofo.append(warehouse.id)
|
| 78 |
|
83 |
|
| 79 |
|
84 |
|
| 80 |
def get_Warehouse(warehouse_id):
|
85 |
def get_Warehouse(warehouse_id):
|
| Line 662... |
Line 667... |
| 662 |
|
667 |
|
| 663 |
#This is not the source as in snapdeal or website, this source is to incorporate different pricing depending upon source id.
|
668 |
#This is not the source as in snapdeal or website, this source is to incorporate different pricing depending upon source id.
|
| 664 |
#i.e. if user visiting to our site has specific source he would see pricing on that source basis. Default source is 1.
|
669 |
#i.e. if user visiting to our site has specific source he would see pricing on that source basis. Default source is 1.
|
| 665 |
# Have to add another source id 2 for fofo warehouses
|
670 |
# Have to add another source id 2 for fofo warehouses
|
| 666 |
|
671 |
|
| 667 |
def get_item_availability_for_user(itemId, sourceId, stateId):
|
672 |
def get_item_availability_for_state(itemId, sourceId, stateId):
|
| - |
|
673 |
__populateWarehouseMap()
|
| 668 |
currentInventorySnapshots = get_item_inventory_by_item_id(itemId)
|
674 |
currentInventorySnapshots = get_item_inventory_by_item_id(itemId)
|
| - |
|
675 |
totalAvailability = 0
|
| - |
|
676 |
expectedDelay = 0
|
| 669 |
if len(currentInventorySnapshots) > 0:
|
677 |
if len(currentInventorySnapshots) > 0:
|
| 670 |
for currentInventorySnapshot in currentInventorySnapshots:
|
678 |
for currentInventorySnapshot in currentInventorySnapshots:
|
| 671 |
warehouseIds = stateWarehouseMap.get(stateId)
|
679 |
if warehouseMap[currentInventorySnapshot.warehouseId].state_id == stateId:
|
| - |
|
680 |
availability = currentInventorySnapshot.availability - currentInventorySnapshot.reserved
|
| 672 |
if warehouseIds:
|
681 |
if availability > 0:
|
| 673 |
if warehouseMap[currentInventorySnapshot.warehouseId].state_id == stateId:
|
682 |
warehouse = warehouseMap[currentInventorySnapshot.warehouseId]
|
| - |
|
683 |
totalAvailability += availability
|
| - |
|
684 |
if totalAvailability <= 0:
|
| - |
|
685 |
warehouse = warehouseMap[virtualVendorWarehouses.get(stateId)]
|
| 674 |
pass
|
686 |
expectedDelay = 2
|
| - |
|
687 |
|
| - |
|
688 |
ia = get_item_availability_for_location(itemId, sourceId)
|
| - |
|
689 |
return [warehouse.id, expectedDelay, warehouse.billingWarehouseId, ia[3], totalAvailability, ia[5]]
|
| 675 |
|
690 |
|
| 676 |
|
691 |
|
| 677 |
def get_item_availability_for_location(item_id, source_id):
|
692 |
def get_item_availability_for_location(item_id, source_id):
|
| 678 |
item_availability = ItemAvailabilityCache.get_by(itemId=item_id, sourceId = source_id)
|
693 |
item_availability = ItemAvailabilityCache.get_by(itemId=item_id, sourceId = source_id)
|
| 679 |
if item_availability:
|
694 |
if item_availability:
|