| Line 38... |
Line 38... |
| 38 |
import datetime
|
38 |
import datetime
|
| 39 |
import json
|
39 |
import json
|
| 40 |
import math
|
40 |
import math
|
| 41 |
import sys
|
41 |
import sys
|
| 42 |
import threading
|
42 |
import threading
|
| - |
|
43 |
from os.path import stat
|
| 43 |
|
44 |
|
| 44 |
to_addresses = ["khushal.bhatia@shop2020.in", "chaitnaya.vats@shop2020.in", "chandan.kumar@shop2020.in",'manoj.kumar@shop2020.in']
|
45 |
to_addresses = ["khushal.bhatia@shop2020.in", "chaitnaya.vats@shop2020.in", "chandan.kumar@shop2020.in", 'manoj.kumar@shop2020.in']
|
| 45 |
mail_user = "cnc.center@shop2020.in"
|
46 |
mail_user = "cnc.center@shop2020.in"
|
| 46 |
mail_password = "5h0p2o2o"
|
47 |
mail_password = "5h0p2o2o"
|
| 47 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
48 |
skippedItems = { 175: [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
| 48 |
193 : [5839] }
|
49 |
193: [5839] }
|
| 49 |
|
50 |
|
| 50 |
pincodePricingServiceabilityMap = {}
|
51 |
pincodePricingServiceabilityMap = {}
|
| 51 |
warehouseMap = {}
|
52 |
warehouseMap = {}
|
| 52 |
|
53 |
|
| 53 |
OOS_CALCULATION_TIME = 23
|
54 |
OOS_CALCULATION_TIME = 23
|
| 54 |
|
55 |
|
| 55 |
#right now these warehouse ids are ignored.
|
56 |
# right now these warehouse ids are ignored.
|
| 56 |
#physicalWarehouseIdsForFofo = [7678, 7681]
|
57 |
# physicalWarehouseIdsForFofo = [7678, 7681]
|
| 57 |
physicalWarehouseIdsForFofo = []
|
58 |
physicalWarehouseIdsForFofo = []
|
| 58 |
vendorWarehouseIdsForFofo = []
|
59 |
vendorWarehouseIdsForFofo = []
|
| 59 |
|
60 |
|
| 60 |
last_date = datetime.date.today()
|
61 |
last_date = datetime.date.today()
|
| 61 |
adjusted_dates={}
|
62 |
adjusted_dates = {}
|
| 62 |
|
63 |
|
| 63 |
partnerMap = {}
|
64 |
partnerMap = {}
|
| 64 |
|
65 |
|
| 65 |
|
- |
|
| 66 |
default_virtual_vendor = 290
|
66 |
default_virtual_vendor = 290
|
| 67 |
virtualVendorWarehouses = {}
|
67 |
virtualVendorWarehouses = {}
|
| 68 |
billingVendorWarehouses = {}
|
68 |
billingVendorWarehouses = {}
|
| - |
|
69 |
stateIdWarehouseIdMapWareMap = {
|
| - |
|
70 |
0: 7573,
|
| - |
|
71 |
3: 7678,
|
| - |
|
72 |
5: 7720,
|
| - |
|
73 |
12: 8468,
|
| - |
|
74 |
9: 8889,
|
| - |
|
75 |
4: 8947
|
| - |
|
76 |
}
|
| - |
|
77 |
|
| 69 |
|
78 |
|
| 70 |
def initialize(dbname='inventory', db_hostname="localhost"):
|
79 |
def initialize(dbname='inventory', db_hostname="localhost"):
|
| 71 |
DataService.initialize(dbname, db_hostname)
|
80 |
DataService.initialize(dbname, db_hostname)
|
| 72 |
__populateWarehouseMap()
|
81 |
__populateWarehouseMap()
|
| 73 |
|
82 |
|
| - |
|
83 |
|
| 74 |
@memoized(3600)
|
84 |
@memoized(3600)
|
| 75 |
def __populateWarehouseMap():
|
85 |
def __populateWarehouseMap():
|
| 76 |
warehouses = Warehouse.query.filter(Warehouse.warehouseType.in_(['OURS', 'THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').all()
|
- |
|
| 77 |
for warehouse in warehouses:
|
- |
|
| 78 |
warehouseMap[warehouse.id] = warehouse
|
86 |
for stateId, warehouseId in stateIdWarehouseIdMapWareMap.iteritems():
|
| 79 |
print warehouse.id, warehouse.vendor
|
- |
|
| 80 |
if warehouse.vendor.id==default_virtual_vendor and warehouse.warehouseType == 'THIRD_PARTY':
|
- |
|
| 81 |
virtualVendorWarehouses[warehouse.state_id] = warehouse
|
87 |
billingVendorWarehouses[stateId] = warehouseId
|
| 82 |
if warehouse.vendor.id==default_virtual_vendor and warehouse.warehouseType == 'OURS':
|
- |
|
| 83 |
billingVendorWarehouses[warehouse.state_id] = warehouse.billingWarehouseId
|
88 |
warehouse = Warehouse.query.filter(Warehouse.warehouseType.in_(['THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').filter(Warehouse.state_id == stateId).first()
|
| 84 |
|
- |
|
| 85 |
if warehouse.billingWarehouseId in physicalWarehouseIdsForFofo:
|
- |
|
| 86 |
vendorWarehouseIdsForFofo.append(warehouse.id)
|
- |
|
| 87 |
warehouse.expunge()
|
89 |
if warehouse is None:
|
| 88 |
#for punjab map to delhi
|
- |
|
| 89 |
stateList = StateMaster.query.all()
|
- |
|
| 90 |
for state in stateList:
|
- |
|
| 91 |
if not virtualVendorWarehouses.has_key(state.id):
|
- |
|
| 92 |
virtualVendorWarehouses[state.id] = virtualVendorWarehouses[0]
|
90 |
warehouse = Warehouse.query.filter(Warehouse.warehouseType.in_(['THIRD_PARTY'])).filter(Warehouse.inventoryType == 'GOOD').filter(Warehouse.state_id == 0).first()
|
| 93 |
billingVendorWarehouses[state.id] = virtualVendorWarehouses[0]
|
91 |
virtualVendorWarehouses[stateId] = warehouse
|
| - |
|
92 |
|
| 94 |
|
93 |
|
| 95 |
def get_Warehouse(warehouse_id):
|
94 |
def get_Warehouse(warehouse_id):
|
| 96 |
return Warehouse.get_by(id=warehouse_id)
|
95 |
return Warehouse.get_by(id=warehouse_id)
|
| 97 |
|
96 |
|
| - |
|
97 |
|
| 98 |
def get_vendor(vendorId):
|
98 |
def get_vendor(vendorId):
|
| 99 |
return Vendor.get_by(id=vendorId)
|
99 |
return Vendor.get_by(id=vendorId)
|
| 100 |
|
100 |
|
| - |
|
101 |
|
| 101 |
def get_state(stateId):
|
102 |
def get_state(stateId):
|
| 102 |
return StateMaster.get_by(id=stateId)
|
103 |
return StateMaster.get_by(id=stateId)
|
| 103 |
|
104 |
|
| - |
|
105 |
|
| 104 |
def get_all_warehouses_by_status(status):
|
106 |
def get_all_warehouses_by_status(status):
|
| 105 |
return Warehouse.query.all()
|
107 |
return Warehouse.query.all()
|
| 106 |
|
108 |
|
| - |
|
109 |
|
| 107 |
def get_all_items_for_warehouse(warehouse_id):
|
110 |
def get_all_items_for_warehouse(warehouse_id):
|
| 108 |
warehouse = get_Warehouse(warehouse_id)
|
111 |
warehouse = get_Warehouse(warehouse_id)
|
| 109 |
if not warehouse:
|
112 |
if not warehouse:
|
| 110 |
raise InventoryServiceException(108, "bad warehouse")
|
113 |
raise InventoryServiceException(108, "bad warehouse")
|
| 111 |
return warehouse.all_items
|
114 |
return warehouse.all_items
|
| 112 |
|
115 |
|
| - |
|
116 |
|
| 113 |
def add_warehouse(warehouse):
|
117 |
def add_warehouse(warehouse):
|
| 114 |
if not warehouse:
|
118 |
if not warehouse:
|
| 115 |
raise InventoryServiceException(108, "Bad warehouse")
|
119 |
raise InventoryServiceException(108, "Bad warehouse")
|
| 116 |
if get_Warehouse(warehouse.id):
|
120 |
if get_Warehouse(warehouse.id):
|
| 117 |
#warehouse is already present.
|
121 |
# warehouse is already present.
|
| 118 |
raise InventoryServiceException(101, "Warehouse already present")
|
122 |
raise InventoryServiceException(101, "Warehouse already present")
|
| 119 |
|
123 |
|
| 120 |
ds_warehouse = Warehouse()
|
124 |
ds_warehouse = Warehouse()
|
| 121 |
ds_warehouse.location = warehouse.location
|
125 |
ds_warehouse.location = warehouse.location
|
| 122 |
ds_warehouse.status = 3
|
126 |
ds_warehouse.status = 3
|
| Line 138... |
Line 142... |
| 138 |
if warehouse.vendorString:
|
142 |
if warehouse.vendorString:
|
| 139 |
ds_warehouse.vendorString = warehouse.vendorString
|
143 |
ds_warehouse.vendorString = warehouse.vendorString
|
| 140 |
session.commit()
|
144 |
session.commit()
|
| 141 |
return ds_warehouse.id
|
145 |
return ds_warehouse.id
|
| 142 |
|
146 |
|
| - |
|
147 |
|
| 143 |
def get_ignored_items(warehouse_id):
|
148 |
def get_ignored_items(warehouse_id):
|
| 144 |
Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(warehouse_id=warehouse_id).all()
|
149 |
Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(warehouse_id=warehouse_id).all()
|
| 145 |
negativeItems = []
|
150 |
negativeItems = []
|
| 146 |
for Ignored_inventory_item in Ignored_inventory_items:
|
151 |
for Ignored_inventory_item in Ignored_inventory_items:
|
| 147 |
try:
|
152 |
try:
|
| Line 149... |
Line 154... |
| 149 |
negativeItems.append(item_id)
|
154 |
negativeItems.append(item_id)
|
| 150 |
except:
|
155 |
except:
|
| 151 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
156 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 152 |
return negativeItems
|
157 |
return negativeItems
|
| 153 |
|
158 |
|
| - |
|
159 |
|
| 154 |
def get_ignored_warehouses(item_id):
|
160 |
def get_ignored_warehouses(item_id):
|
| 155 |
warehouses = []
|
161 |
warehouses = []
|
| 156 |
#No item availability cache for Hotspot Specific Store
|
162 |
# No item availability cache for Hotspot Specific Store
|
| 157 |
#No virtual is allowed
|
163 |
# No virtual is allowed
|
| 158 |
Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).all()
|
164 |
Ignored_inventory_items = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).all()
|
| 159 |
for Ignored_inventory_item in Ignored_inventory_items:
|
165 |
for Ignored_inventory_item in Ignored_inventory_items:
|
| 160 |
warehouses.append(Ignored_inventory_item.warehouse_id)
|
166 |
warehouses.append(Ignored_inventory_item.warehouse_id)
|
| 161 |
return warehouses
|
167 |
return warehouses
|
| 162 |
|
168 |
|
| - |
|
169 |
|
| 163 |
def update_inventory_history(warehouse_id, timestamp, availability):
|
170 |
def update_inventory_history(warehouse_id, timestamp, availability):
|
| 164 |
warehouse = get_Warehouse(warehouse_id)
|
171 |
warehouse = get_Warehouse(warehouse_id)
|
| 165 |
if not warehouse:
|
172 |
if not warehouse:
|
| 166 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
173 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
| 167 |
vendor = warehouse.vendor
|
174 |
vendor = warehouse.vendor
|
| Line 179... |
Line 186... |
| 179 |
item_inventory_history.timestamp = time
|
186 |
item_inventory_history.timestamp = time
|
| 180 |
item_inventory_history.availability = quantity
|
187 |
item_inventory_history.availability = quantity
|
| 181 |
except:
|
188 |
except:
|
| 182 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
189 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 183 |
session.commit()
|
190 |
session.commit()
|
| - |
|
191 |
|
| 184 |
|
192 |
|
| 185 |
def update_inventory(warehouse_id, timestamp, availability):
|
193 |
def update_inventory(warehouse_id, timestamp, availability):
|
| 186 |
warehouse = get_Warehouse(warehouse_id)
|
194 |
warehouse = get_Warehouse(warehouse_id)
|
| 187 |
if not warehouse:
|
195 |
if not warehouse:
|
| 188 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
196 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
| Line 214... |
Line 222... |
| 214 |
current_inventory_snapshot.availability = current_inventory_snapshot.availability + quantity
|
222 |
current_inventory_snapshot.availability = current_inventory_snapshot.availability + quantity
|
| 215 |
item = __get_item_from_master(item_id)
|
223 |
item = __get_item_from_master(item_id)
|
| 216 |
try:
|
224 |
try:
|
| 217 |
if quantity > 0 and __get_item_reserved(item_id) > 0:
|
225 |
if quantity > 0 and __get_item_reserved(item_id) > 0:
|
| 218 |
cl = TransactionClient().get_client()
|
226 |
cl = TransactionClient().get_client()
|
| 219 |
#FIXME hardcoding for warehouse id
|
227 |
# FIXME hardcoding for warehouse id
|
| 220 |
cl.addAlert(AlertType.NEW_INVENTORY_ALERT, 5, "Inventory received for item " + item.brand + " " + item.modelName + " " + item.modelNumber + " " + item.color)
|
228 |
cl.addAlert(AlertType.NEW_INVENTORY_ALERT, 5, "Inventory received for item " + item.brand + " " + item.modelName + " " + item.modelNumber + " " + item.color)
|
| 221 |
except:
|
229 |
except:
|
| 222 |
print "Not able to raise alert for incoming inventory"
|
230 |
print "Not able to raise alert for incoming inventory"
|
| 223 |
if current_inventory_snapshot.availability < 0:
|
231 |
if current_inventory_snapshot.availability < 0:
|
| 224 |
__send_alert_for_negative_availability(item, current_inventory_snapshot.availability, warehouse)
|
232 |
__send_alert_for_negative_availability(item, current_inventory_snapshot.availability, warehouse)
|
| 225 |
except:
|
233 |
except:
|
| 226 |
print "Some unforeseen error while updating inventory:", sys.exc_info()[0]
|
234 |
print "Some unforeseen error while updating inventory:", sys.exc_info()[0]
|
| 227 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
235 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 228 |
session.commit()
|
236 |
session.commit()
|
| 229 |
|
237 |
|
| 230 |
#**Update item availability cache**#
|
238 |
# **Update item availability cache**#
|
| 231 |
for item_id in item_ids:
|
239 |
for item_id in item_ids:
|
| 232 |
clear_item_availability_cache(item_id)
|
240 |
clear_item_availability_cache(item_id)
|
| 233 |
|
241 |
|
| - |
|
242 |
|
| 234 |
def __send_alert_for_negative_reserved(item, reserved, warehouse):
|
243 |
def __send_alert_for_negative_reserved(item, reserved, warehouse):
|
| 235 |
itemName = " ".join([str(item.id), str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
244 |
itemName = " ".join([str(item.id), str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
| 236 |
EmailAttachmentSender.mail(mail_user, mail_password, 'manish.sharma@shop2020.in', 'Negative reserved: ' + str(reserved) + ' for Item Id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
245 |
EmailAttachmentSender.mail(mail_user, mail_password, 'manish.sharma@shop2020.in', 'Negative reserved: ' + str(reserved) + ' for Item Id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
| 237 |
|
246 |
|
| - |
|
247 |
|
| 238 |
def __send_alert_for_negative_availability(item, availability, warehouse):
|
248 |
def __send_alert_for_negative_availability(item, availability, warehouse):
|
| 239 |
itemName = " ".join([str(item.id), str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
249 |
itemName = " ".join([str(item.id), str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
| 240 |
# EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'amar.kumar@shop2020.in', 'Negative availability ' + str(availability) + ' for Item id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
250 |
# EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'amar.kumar@shop2020.in', 'Negative availability ' + str(availability) + ' for Item id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
| 241 |
|
251 |
|
| - |
|
252 |
|
| 242 |
def __send_mail_for_missing_key(item_key, quantity, warehouse_id):
|
253 |
def __send_mail_for_missing_key(item_key, quantity, warehouse_id):
|
| 243 |
missedInventoryUpdate = MissedInventoryUpdate.get_by(itemKey = item_key, warehouseId = warehouse_id)
|
254 |
missedInventoryUpdate = MissedInventoryUpdate.get_by(itemKey=item_key, warehouseId=warehouse_id)
|
| 244 |
# One email per product key mismatch
|
255 |
# One email per product key mismatch
|
| 245 |
if not missedInventoryUpdate:
|
256 |
if not missedInventoryUpdate:
|
| 246 |
missedInventoryUpdate = MissedInventoryUpdate()
|
257 |
missedInventoryUpdate = MissedInventoryUpdate()
|
| 247 |
missedInventoryUpdate.itemKey = item_key
|
258 |
missedInventoryUpdate.itemKey = item_key
|
| 248 |
missedInventoryUpdate.quantity = quantity
|
259 |
missedInventoryUpdate.quantity = quantity
|
| Line 256... |
Line 267... |
| 256 |
print "Not able to send email. No issues, we can continue with updates."
|
267 |
print "Not able to send email. No issues, we can continue with updates."
|
| 257 |
else:
|
268 |
else:
|
| 258 |
missedInventoryUpdate.quantity += quantity
|
269 |
missedInventoryUpdate.quantity += quantity
|
| 259 |
session.commit()
|
270 |
session.commit()
|
| 260 |
|
271 |
|
| - |
|
272 |
|
| 261 |
def add_inventory(itemId, warehouseId, quantity, skipAddition=False):
|
273 |
def add_inventory(itemId, warehouseId, quantity, skipAddition=False):
|
| 262 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
274 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| 263 |
if not current_inventory_snapshot:
|
275 |
if not current_inventory_snapshot:
|
| 264 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
276 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| 265 |
current_inventory_snapshot.item_id = itemId
|
277 |
current_inventory_snapshot.item_id = itemId
|
| 266 |
current_inventory_snapshot.warehouse_id = warehouseId
|
278 |
current_inventory_snapshot.warehouse_id = warehouseId
|
| 267 |
current_inventory_snapshot.availability = 0
|
279 |
current_inventory_snapshot.availability = 0
|
| 268 |
current_inventory_snapshot.reserved = 0
|
280 |
current_inventory_snapshot.reserved = 0
|
| 269 |
current_inventory_snapshot.held = 0
|
281 |
current_inventory_snapshot.held = 0
|
| 270 |
# added the difference in the current inventory
|
282 |
# added the difference in the current inventory
|
| 271 |
if skipAddition is None or not skipAddition:
|
283 |
if skipAddition is None or not skipAddition:
|
| 272 |
current_inventory_snapshot.availability = current_inventory_snapshot.availability + quantity
|
284 |
current_inventory_snapshot.availability = current_inventory_snapshot.availability + quantity
|
| 273 |
else:
|
285 |
else:
|
| 274 |
current_inventory_snapshot.availability = quantity
|
286 |
current_inventory_snapshot.availability = quantity
|
| 275 |
session.commit()
|
287 |
session.commit()
|
| 276 |
#**Update item availability cache**#
|
288 |
# **Update item availability cache**#
|
| 277 |
clear_item_availability_cache(itemId)
|
289 |
clear_item_availability_cache(itemId)
|
| 278 |
if current_inventory_snapshot.availability < 0:
|
290 |
if current_inventory_snapshot.availability < 0:
|
| 279 |
item = __get_item_from_master(itemId)
|
291 |
item = __get_item_from_master(itemId)
|
| 280 |
__send_alert_for_negative_availability(item, current_inventory_snapshot.availability, get_Warehouse(warehouseId))
|
292 |
__send_alert_for_negative_availability(item, current_inventory_snapshot.availability, get_Warehouse(warehouseId))
|
| 281 |
|
293 |
|
| - |
|
294 |
|
| 282 |
def add_bad_inventory(itemId, warehouseId, quantity):
|
295 |
def add_bad_inventory(itemId, warehouseId, quantity):
|
| 283 |
bad_inventory_snapshot = BadInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
296 |
bad_inventory_snapshot = BadInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| 284 |
if not bad_inventory_snapshot:
|
297 |
if not bad_inventory_snapshot:
|
| 285 |
bad_inventory_snapshot = BadInventorySnapshot()
|
298 |
bad_inventory_snapshot = BadInventorySnapshot()
|
| 286 |
bad_inventory_snapshot.item_id = itemId
|
299 |
bad_inventory_snapshot.item_id = itemId
|
| Line 291... |
Line 304... |
| 291 |
session.commit()
|
304 |
session.commit()
|
| 292 |
if bad_inventory_snapshot.availability < 0:
|
305 |
if bad_inventory_snapshot.availability < 0:
|
| 293 |
item = __get_item_from_master(itemId)
|
306 |
item = __get_item_from_master(itemId)
|
| 294 |
__send_alert_for_negative_availability(item, bad_inventory_snapshot.availability, get_Warehouse(warehouseId))
|
307 |
__send_alert_for_negative_availability(item, bad_inventory_snapshot.availability, get_Warehouse(warehouseId))
|
| 295 |
|
308 |
|
| - |
|
309 |
|
| 296 |
def get_item_inventory_by_item_id(item_id):
|
310 |
def get_item_inventory_by_item_id(item_id):
|
| 297 |
return CurrentInventorySnapshot.query.filter_by(item_id=item_id).all()
|
311 |
return CurrentInventorySnapshot.query.filter_by(item_id=item_id).all()
|
| 298 |
|
312 |
|
| - |
|
313 |
|
| 299 |
def retire_warehouse(warehouse_id):
|
314 |
def retire_warehouse(warehouse_id):
|
| 300 |
if not warehouse_id:
|
315 |
if not warehouse_id:
|
| 301 |
raise InventoryServiceException(101, "Bad warehouse id")
|
316 |
raise InventoryServiceException(101, "Bad warehouse id")
|
| 302 |
warehouse = get_Warehouse(warehouse_id)
|
317 |
warehouse = get_Warehouse(warehouse_id)
|
| 303 |
if not warehouse:
|
318 |
if not warehouse:
|
| 304 |
raise InventoryServiceException(108, "warehouse id not present")
|
319 |
raise InventoryServiceException(108, "warehouse id not present")
|
| 305 |
warehouse.status = 0;
|
320 |
warehouse.status = 0;
|
| 306 |
session.commit()
|
321 |
session.commit()
|
| - |
|
322 |
|
| 307 |
|
323 |
|
| 308 |
def get_item_availability_for_warehouse(warehouse_id, item_id):
|
324 |
def get_item_availability_for_warehouse(warehouse_id, item_id):
|
| 309 |
ignore = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).filter_by(warehouse_id = warehouse_id).all()
|
325 |
ignore = IgnoredInventoryUpdateItems.query.filter_by(item_id=item_id).filter_by(warehouse_id=warehouse_id).all()
|
| 310 |
if ignore:
|
326 |
if ignore:
|
| 311 |
return 0
|
327 |
return 0
|
| 312 |
|
328 |
|
| 313 |
try:
|
329 |
try:
|
| 314 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id).filter_by(item_id = item_id).one()
|
330 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouse_id).filter_by(item_id=item_id).one()
|
| 315 |
return current_inventory_snapshot.availability - current_inventory_snapshot.reserved - current_inventory_snapshot.held
|
331 |
return current_inventory_snapshot.availability - current_inventory_snapshot.reserved - current_inventory_snapshot.held
|
| 316 |
except:
|
332 |
except:
|
| 317 |
return 0
|
333 |
return 0
|
| 318 |
|
334 |
|
| - |
|
335 |
|
| 319 |
def get_item_availability_for_our_warehouses(item_ids):
|
336 |
def get_item_availability_for_our_warehouses(item_ids):
|
| 320 |
our_warehouses = Warehouse.query.filter_by(warehouseType = 'OURS', inventoryType = 'GOOD').all()
|
337 |
our_warehouses = Warehouse.query.filter_by(warehouseType='OURS', inventoryType='GOOD').all()
|
| 321 |
our_thirdparty_warehouses = Warehouse.query.filter_by(warehouseType = 'OURS_THIRDPARTY').all()
|
338 |
our_thirdparty_warehouses = Warehouse.query.filter_by(warehouseType='OURS_THIRDPARTY').all()
|
| 322 |
warehouse_ids = []
|
339 |
warehouse_ids = []
|
| 323 |
for warehouse in our_warehouses :
|
340 |
for warehouse in our_warehouses:
|
| 324 |
warehouse_ids.append(warehouse.id)
|
341 |
warehouse_ids.append(warehouse.id)
|
| 325 |
#for warehouse in our_thirdparty_warehouses :
|
342 |
# for warehouse in our_thirdparty_warehouses :
|
| 326 |
# warehouse_ids.append(warehouse.id)
|
343 |
# warehouse_ids.append(warehouse.id)
|
| 327 |
|
344 |
|
| 328 |
availability_map = dict()
|
345 |
availability_map = dict()
|
| 329 |
|
346 |
|
| 330 |
try :
|
347 |
try:
|
| 331 |
for item_id in item_ids :
|
348 |
for item_id in item_ids:
|
| 332 |
total_availability = 0
|
349 |
total_availability = 0
|
| 333 |
for current_inventory_snapshot in CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter_by(item_id = item_id).all():
|
350 |
for current_inventory_snapshot in CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter_by(item_id=item_id).all():
|
| 334 |
total_availability += current_inventory_snapshot.availability
|
351 |
total_availability += current_inventory_snapshot.availability
|
| 335 |
if total_availability >0:
|
352 |
if total_availability > 0:
|
| 336 |
availability_map[item_id] = total_availability
|
353 |
availability_map[item_id] = total_availability
|
| 337 |
except Exception as e:
|
354 |
except Exception as e:
|
| 338 |
print e
|
355 |
print e
|
| 339 |
raise PurchaseServiceException(101, 'Exception while fetching availability of items in our warehouses')
|
356 |
raise PurchaseServiceException(101, 'Exception while fetching availability of items in our warehouses')
|
| 340 |
|
357 |
|
| 341 |
return availability_map
|
358 |
return availability_map
|
| 342 |
|
359 |
|
| - |
|
360 |
|
| 343 |
#As of now as warehouse can be managed independently we just need to return itemavailability cache for the item ids provided
|
361 |
# As of now as warehouse can be managed independently we just need to return itemavailability cache for the item ids provided
|
| 344 |
def get_fofo_availability(item_ids):
|
362 |
def get_fofo_availability(item_ids):
|
| 345 |
returnMap = {}
|
363 |
returnMap = {}
|
| 346 |
if not item_ids:
|
364 |
if not item_ids:
|
| 347 |
return returnMap
|
365 |
return returnMap
|
| 348 |
for item_id in item_ids:
|
366 |
for item_id in item_ids:
|
| 349 |
returnMap[item_id] = get_item_availability_for_location(item_id, 1)[4]
|
367 |
returnMap[item_id] = get_item_availability_for_location(item_id, 1)[4]
|
| 350 |
return returnMap
|
368 |
return returnMap
|
| 351 |
|
369 |
|
| - |
|
370 |
|
| 352 |
def get_fofo_fulfilment_warehouse_map(itemIds):
|
371 |
def get_fofo_fulfilment_warehouse_map(itemIds):
|
| 353 |
returnMap = {}
|
372 |
returnMap = {}
|
| 354 |
snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(vendorWarehouseIdsForFofo)).filter(CurrentInventorySnapshot.item_id.in_(itemIds)).all()
|
373 |
snapshots = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(vendorWarehouseIdsForFofo)).filter(CurrentInventorySnapshot.item_id.in_(itemIds)).all()
|
| 355 |
for snapshot in snapshots:
|
374 |
for snapshot in snapshots:
|
| 356 |
availability = snapshot.availability - snapshot.reserved - snapshot.held
|
375 |
availability = snapshot.availability - snapshot.reserved - snapshot.held
|
| 357 |
if availability > 0:
|
376 |
if availability > 0:
|
| 358 |
if not returnMap.has_key(snapshot.item_id):
|
377 |
if not returnMap.has_key(snapshot.item_id):
|
| 359 |
returnMap[snapshot.item_id] = to_t_warehouse(snapshot.warehouse)
|
378 |
returnMap[snapshot.item_id] = to_t_warehouse(snapshot.warehouse)
|
| 360 |
return returnMap
|
379 |
return returnMap
|
| 361 |
|
- |
|
| 362 |
|
- |
|
| 363 |
|
380 |
|
| 364 |
'''
|
381 |
'''
|
| 365 |
This method returns quantity of a particular item across all warehouses whose ids is provided
|
382 |
This method returns quantity of a particular item across all warehouses whose ids is provided
|
| 366 |
if warehouse_ids is null it checks for inventory in all warehouses.
|
383 |
if warehouse_ids is null it checks for inventory in all warehouses.
|
| 367 |
'''
|
384 |
'''
|
| - |
|
385 |
|
| - |
|
386 |
|
| 368 |
def __get_item_availability(item, warehouse_ids):
|
387 |
def __get_item_availability(item, warehouse_ids):
|
| 369 |
if warehouse_ids is None:
|
388 |
if warehouse_ids is None:
|
| 370 |
all_inventory = CurrentInventorySnapshot.query.filter_by(item = item).all()
|
389 |
all_inventory = CurrentInventorySnapshot.query.filter_by(item=item).all()
|
| 371 |
availability = 0
|
390 |
availability = 0
|
| 372 |
reserved = 0
|
391 |
reserved = 0
|
| 373 |
for currInv in all_inventory:
|
392 |
for currInv in all_inventory:
|
| 374 |
availability = availability + currInv.availability
|
393 |
availability = availability + currInv.availability
|
| 375 |
reserved = reserved + currInv.reserved
|
394 |
reserved = reserved + currInv.reserved
|
| 376 |
return availability - reserved
|
395 |
return availability - reserved
|
| 377 |
else:
|
396 |
else:
|
| 378 |
total_availability = 0
|
397 |
total_availability = 0
|
| 379 |
for current_inventory_snapshot in CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter_by(item_id = item.id).all():
|
398 |
for current_inventory_snapshot in CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).filter_by(item_id=item.id).all():
|
| 380 |
total_availability += current_inventory_snapshot.availability - current_inventory_snapshot.reserved
|
399 |
total_availability += current_inventory_snapshot.availability - current_inventory_snapshot.reserved
|
| 381 |
return total_availability
|
400 |
return total_availability
|
| 382 |
|
401 |
|
| - |
|
402 |
|
| 383 |
def __get_item_reserved(item_id):
|
403 |
def __get_item_reserved(item_id):
|
| 384 |
all_inventory = CurrentInventorySnapshot.query.filter_by(item_id = item_id).all()
|
404 |
all_inventory = CurrentInventorySnapshot.query.filter_by(item_id=item_id).all()
|
| 385 |
reserved = 0
|
405 |
reserved = 0
|
| 386 |
for currInv in all_inventory:
|
406 |
for currInv in all_inventory:
|
| 387 |
reserved = reserved + currInv.reserved
|
407 |
reserved = reserved + currInv.reserved
|
| 388 |
return reserved
|
408 |
return reserved
|
| 389 |
|
409 |
|
| - |
|
410 |
|
| 390 |
def __get_item_availability_at_warehouse(warehouse_id, item_id):
|
411 |
def __get_item_availability_at_warehouse(warehouse_id, item_id):
|
| 391 |
inventory = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).one()
|
412 |
inventory = CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id).one()
|
| 392 |
return inventory.availability
|
413 |
return inventory.availability
|
| 393 |
|
414 |
|
| - |
|
415 |
|
| 394 |
def is_order_billable(item_id, warehouse_id, source_id, order_id):
|
416 |
def is_order_billable(item_id, warehouse_id, source_id, order_id):
|
| 395 |
reservations = CurrentReservationSnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id).order_by(CurrentReservationSnapshot.promised_shipping_timestamp).order_by(CurrentReservationSnapshot.created_timestamp).all()
|
417 |
reservations = CurrentReservationSnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id).order_by(CurrentReservationSnapshot.promised_shipping_timestamp).order_by(CurrentReservationSnapshot.created_timestamp).all()
|
| 396 |
availability = __get_item_availability_at_warehouse(warehouse_id, item_id)
|
418 |
availability = __get_item_availability_at_warehouse(warehouse_id, item_id)
|
| 397 |
for reservation in reservations:
|
419 |
for reservation in reservations:
|
| 398 |
availability = availability - reservation.reserved
|
420 |
availability = availability - reservation.reserved
|
| 399 |
if reservation.order_id == order_id and reservation.source_id == source_id:
|
421 |
if reservation.order_id == order_id and reservation.source_id == source_id:
|
| 400 |
break
|
422 |
break
|
| 401 |
if availability < 0:
|
423 |
if availability < 0:
|
| 402 |
return False
|
424 |
return False
|
| 403 |
return True
|
425 |
return True
|
| - |
|
426 |
|
| 404 |
|
427 |
|
| 405 |
def reserve_item_in_warehouse(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
428 |
def reserve_item_in_warehouse(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
| 406 |
|
429 |
|
| 407 |
if not warehouse_id:
|
430 |
if not warehouse_id:
|
| 408 |
raise InventoryServiceException(101, "bad warehouse_id")
|
431 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| 409 |
|
432 |
|
| 410 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
|
433 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id)
|
| 411 |
try:
|
434 |
try:
|
| 412 |
current_inventory_snapshot = query.one()
|
435 |
current_inventory_snapshot = query.one()
|
| 413 |
except:
|
436 |
except:
|
| 414 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
437 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| 415 |
current_inventory_snapshot.warehouse_id = warehouse_id
|
438 |
current_inventory_snapshot.warehouse_id = warehouse_id
|
| Line 433... |
Line 456... |
| 433 |
|
456 |
|
| 434 |
try:
|
457 |
try:
|
| 435 |
order_client = TransactionClient().get_client()
|
458 |
order_client = TransactionClient().get_client()
|
| 436 |
order = order_client.getOrder(order_id)
|
459 |
order = order_client.getOrder(order_id)
|
| 437 |
if order.source:
|
460 |
if order.source:
|
| 438 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id = item_id, warehouse_id = warehouse_id, source = order.source).first()
|
461 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id=item_id, warehouse_id=warehouse_id, source=order.source).first()
|
| 439 |
if holdInventoryDetail is None or holdInventoryDetail.held<=0:
|
462 |
if holdInventoryDetail is None or holdInventoryDetail.held <= 0:
|
| 440 |
holdInventoryDetails = HoldInventoryDetail.query.filter_by(item_id = item_id, source = order.source).all()
|
463 |
holdInventoryDetails = HoldInventoryDetail.query.filter_by(item_id=item_id, source=order.source).all()
|
| 441 |
if holdInventoryDetails:
|
464 |
if holdInventoryDetails:
|
| 442 |
for hID in holdInventoryDetails:
|
465 |
for hID in holdInventoryDetails:
|
| 443 |
if hID.held>0:
|
466 |
if hID.held > 0:
|
| 444 |
holdInventoryDetail = hID
|
467 |
holdInventoryDetail = hID
|
| 445 |
if holdInventoryDetail is not None and holdInventoryDetail.held>0:
|
468 |
if holdInventoryDetail is not None and holdInventoryDetail.held > 0:
|
| 446 |
previousHeld = holdInventoryDetail.held
|
469 |
previousHeld = holdInventoryDetail.held
|
| 447 |
holdInventoryDetail.held = max(0, holdInventoryDetail.held -quantity)
|
470 |
holdInventoryDetail.held = max(0, holdInventoryDetail.held - quantity)
|
| 448 |
diff = previousHeld-holdInventoryDetail.held
|
471 |
diff = previousHeld - holdInventoryDetail.held
|
| 449 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=holdInventoryDetail.warehouse_id)
|
472 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=holdInventoryDetail.warehouse_id)
|
| 450 |
if current_inventory_snapshot is not None:
|
473 |
if current_inventory_snapshot is not None:
|
| 451 |
current_inventory_snapshot.held = max(0, current_inventory_snapshot.held - diff)
|
474 |
current_inventory_snapshot.held = max(0, current_inventory_snapshot.held - diff)
|
| 452 |
session.commit()
|
475 |
session.commit()
|
| 453 |
except:
|
476 |
except:
|
| 454 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
477 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
| 455 |
#session.commit()
|
478 |
# session.commit()
|
| 456 |
#**Update item availability cache**#
|
479 |
# **Update item availability cache**#
|
| 457 |
clear_item_availability_cache(item_id)
|
480 |
clear_item_availability_cache(item_id)
|
| 458 |
return True
|
481 |
return True
|
| 459 |
|
482 |
|
| - |
|
483 |
|
| 460 |
def update_reservation_for_order(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
484 |
def update_reservation_for_order(item_id, warehouse_id, source_id, order_id, created_timestamp, promised_shipping_timestamp, quantity):
|
| 461 |
if not warehouse_id:
|
485 |
if not warehouse_id:
|
| 462 |
raise InventoryServiceException(101, "bad warehouse_id")
|
486 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| 463 |
warehouse = get_Warehouse(warehouse_id)
|
487 |
warehouse = get_Warehouse(warehouse_id)
|
| 464 |
'''item_pricing = get_item_pricing(item_id, warehouse.vendor.id)
|
488 |
'''item_pricing = get_item_pricing(item_id, warehouse.vendor.id)
|
| 465 |
if not item_pricing:
|
489 |
if not item_pricing:
|
| 466 |
raise InventoryServiceException(101, "No Pricing Info found for vendor and Item")'''
|
490 |
raise InventoryServiceException(101, "No Pricing Info found for vendor and Item")'''
|
| 467 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
|
491 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id)
|
| 468 |
try:
|
492 |
try:
|
| 469 |
new_current_inventory_snapshot = query.one()
|
493 |
new_current_inventory_snapshot = query.one()
|
| 470 |
except:
|
494 |
except:
|
| 471 |
new_current_inventory_snapshot = CurrentInventorySnapshot()
|
495 |
new_current_inventory_snapshot = CurrentInventorySnapshot()
|
| 472 |
new_current_inventory_snapshot.warehouse_id = warehouse_id
|
496 |
new_current_inventory_snapshot.warehouse_id = warehouse_id
|
| Line 487... |
Line 511... |
| 487 |
|
511 |
|
| 488 |
try:
|
512 |
try:
|
| 489 |
order_client = TransactionClient().get_client()
|
513 |
order_client = TransactionClient().get_client()
|
| 490 |
order = order_client.getOrder(order_id)
|
514 |
order = order_client.getOrder(order_id)
|
| 491 |
if order.source:
|
515 |
if order.source:
|
| 492 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id = item_id, warehouse_id = warehouse_id, source = order.source).first()
|
516 |
holdInventoryDetail = HoldInventoryDetail.query.filter_by(item_id=item_id, warehouse_id=warehouse_id, source=order.source).first()
|
| 493 |
if holdInventoryDetail is None or holdInventoryDetail.held<=0:
|
517 |
if holdInventoryDetail is None or holdInventoryDetail.held <= 0:
|
| 494 |
holdInventoryDetails = HoldInventoryDetail.query.filter_by(item_id = item_id, source = order.source).all()
|
518 |
holdInventoryDetails = HoldInventoryDetail.query.filter_by(item_id=item_id, source=order.source).all()
|
| 495 |
if holdInventoryDetails:
|
519 |
if holdInventoryDetails:
|
| 496 |
for hID in holdInventoryDetails:
|
520 |
for hID in holdInventoryDetails:
|
| 497 |
if hID.held>0:
|
521 |
if hID.held > 0:
|
| 498 |
holdInventoryDetail = hID
|
522 |
holdInventoryDetail = hID
|
| 499 |
if holdInventoryDetail is not None and holdInventoryDetail.held>0:
|
523 |
if holdInventoryDetail is not None and holdInventoryDetail.held > 0:
|
| 500 |
previousHeld = holdInventoryDetail.held
|
524 |
previousHeld = holdInventoryDetail.held
|
| 501 |
holdInventoryDetail.held = max(0, holdInventoryDetail.held -quantity)
|
525 |
holdInventoryDetail.held = max(0, holdInventoryDetail.held - quantity)
|
| 502 |
diff = previousHeld-holdInventoryDetail.held
|
526 |
diff = previousHeld - holdInventoryDetail.held
|
| 503 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=holdInventoryDetail.warehouse_id)
|
527 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=item_id, warehouse_id=holdInventoryDetail.warehouse_id)
|
| 504 |
if current_inventory_snapshot is not None:
|
528 |
if current_inventory_snapshot is not None:
|
| 505 |
current_inventory_snapshot.held = max(0, current_inventory_snapshot.held - diff)
|
529 |
current_inventory_snapshot.held = max(0, current_inventory_snapshot.held - diff)
|
| 506 |
session.commit()
|
530 |
session.commit()
|
| 507 |
except:
|
531 |
except:
|
| 508 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
532 |
print "Unable to release hold Inventory for item_id " + str(item_id) + " warehouse_id " + str(warehouse_id) + " source " + str(source_id)
|
| 509 |
|
533 |
|
| 510 |
order_client = TransactionClient().get_client()
|
534 |
order_client = TransactionClient().get_client()
|
| 511 |
order = order_client.getOrder(order_id)
|
535 |
order = order_client.getOrder(order_id)
|
| 512 |
for lineitem in order.lineitems:
|
536 |
for lineitem in order.lineitems:
|
| 513 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id)
|
537 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id=order.fulfilmentWarehouseId, item_id=lineitem.item_id)
|
| 514 |
try:
|
538 |
try:
|
| 515 |
current_inventory_snapshot = query.one()
|
539 |
current_inventory_snapshot = query.one()
|
| 516 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
|
540 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
|
| 517 |
|
541 |
|
| 518 |
reservation = CurrentReservationSnapshot.query.filter_by(warehouse_id = order.fulfilmentWarehouseId, item_id = lineitem.item_id, source_id = source_id, order_id = order_id).one()
|
542 |
reservation = CurrentReservationSnapshot.query.filter_by(warehouse_id=order.fulfilmentWarehouseId, item_id=lineitem.item_id, source_id=source_id, order_id=order_id).one()
|
| 519 |
if reservation.reserved == quantity:
|
543 |
if reservation.reserved == quantity:
|
| 520 |
reservation.delete()
|
544 |
reservation.delete()
|
| 521 |
else:
|
545 |
else:
|
| 522 |
reservation.reserved -= quantity
|
546 |
reservation.reserved -= quantity
|
| 523 |
|
547 |
|
| Line 532... |
Line 556... |
| 532 |
return False
|
556 |
return False
|
| 533 |
except:
|
557 |
except:
|
| 534 |
print "Error in reducing reservation for item:", sys.exc_info()[0]
|
558 |
print "Error in reducing reservation for item:", sys.exc_info()[0]
|
| 535 |
return False
|
559 |
return False
|
| 536 |
session.commit()
|
560 |
session.commit()
|
| 537 |
#**Update item availability cache**#
|
561 |
# **Update item availability cache**#
|
| 538 |
clear_item_availability_cache(item_id)
|
562 |
clear_item_availability_cache(item_id)
|
| 539 |
return True
|
563 |
return True
|
| 540 |
|
564 |
|
| - |
|
565 |
|
| 541 |
def get_item_pincode_availability(itemPricingMap, pin_code):
|
566 |
def get_item_pincode_availability(itemPricingMap, pin_code):
|
| 542 |
returnMap = {}
|
567 |
returnMap = {}
|
| 543 |
missingItemPricingList = []
|
568 |
missingItemPricingList = []
|
| 544 |
for item_id, pricing in itemPricingMap.iteritems():
|
569 |
for item_id, pricing in itemPricingMap.iteritems():
|
| 545 |
if not pricing:
|
570 |
if not pricing:
|
| 546 |
missingItemPricingList.append(item_id)
|
571 |
missingItemPricingList.append(item_id)
|
| 547 |
if missingItemPricingList:
|
572 |
if missingItemPricingList:
|
| 548 |
cc = CatalogClient().get_client()
|
573 |
cc = CatalogClient().get_client()
|
| 549 |
items = cc.getItems(missingItemPricingList)
|
574 |
items = cc.getItems(missingItemPricingList)
|
| 550 |
lc = LogisticsClient().get_client()
|
575 |
lc = LogisticsClient().get_client()
|
| 551 |
#Consider selling price if its missing in itempricing
|
576 |
# Consider selling price if its missing in itempricing
|
| 552 |
for item in items:
|
577 |
for item in items:
|
| 553 |
itemPricingMap[item.id] = item.sellingPrice
|
578 |
itemPricingMap[item.id] = item.sellingPrice
|
| 554 |
pricingLocationInfoMap = __getLocationInfoMap(pin_code, itemPricingMap)
|
579 |
pricingLocationInfoMap = __getLocationInfoMap(pin_code, itemPricingMap)
|
| 555 |
if pricingLocationInfoMap == -1:
|
580 |
if pricingLocationInfoMap == -1:
|
| 556 |
returnMap = {"pincode_serviceable":False}
|
581 |
returnMap = {"pincode_serviceable":False}
|
| 557 |
else:
|
582 |
else:
|
| 558 |
#for item_id, sellingPrice in itemPricingMap.iteritems():
|
583 |
# for item_id, sellingPrice in itemPricingMap.iteritems():
|
| 559 |
allLocations = pricingLocationInfoMap[1].keys()
|
584 |
allLocations = pricingLocationInfoMap[1].keys()
|
| 560 |
itemLocationAvailabilityList = __get_item_location_availability_bulk(itemPricingMap.keys(), allLocations)
|
585 |
itemLocationAvailabilityList = __get_item_location_availability_bulk(itemPricingMap.keys(), allLocations)
|
| 561 |
pricingLocationsMap = {}
|
586 |
pricingLocationsMap = {}
|
| 562 |
for itemLocationAvailability in itemLocationAvailabilityList:
|
587 |
for itemLocationAvailability in itemLocationAvailabilityList:
|
| 563 |
sellingPrice = itemPricingMap[itemLocationAvailability.item_id]
|
588 |
sellingPrice = itemPricingMap[itemLocationAvailability.item_id]
|
| Line 567... |
Line 592... |
| 567 |
pricingLocationsMap[sellingPrice] = pricingLocationInfoMap[sellingPrice].keys()
|
592 |
pricingLocationsMap[sellingPrice] = pricingLocationInfoMap[sellingPrice].keys()
|
| 568 |
|
593 |
|
| 569 |
if itemLocationAvailability.location_id not in pricingLocationsMap[sellingPrice]:
|
594 |
if itemLocationAvailability.location_id not in pricingLocationsMap[sellingPrice]:
|
| 570 |
continue
|
595 |
continue
|
| 571 |
if not returnMap.has_key(itemLocationAvailability.item_id):
|
596 |
if not returnMap.has_key(itemLocationAvailability.item_id):
|
| 572 |
returnMap[itemLocationAvailability.item_id] = ItemPincodeAvailability(vatQty = 0, totalQty = 0, minDeliveryDate=-1)
|
597 |
returnMap[itemLocationAvailability.item_id] = ItemPincodeAvailability(vatQty=0, totalQty=0, minDeliveryDate=-1)
|
| 573 |
itemPincodeAvailability = ItemPincodeAvailability()
|
598 |
itemPincodeAvailability = ItemPincodeAvailability()
|
| 574 |
itemPincodeAvailability = returnMap[itemLocationAvailability.item_id]
|
599 |
itemPincodeAvailability = returnMap[itemLocationAvailability.item_id]
|
| 575 |
locationInfo = LocationInfo()
|
600 |
locationInfo = LocationInfo()
|
| 576 |
locationInfo = pricingLocationInfoMap[sellingPrice][itemLocationAvailability.location_id]
|
601 |
locationInfo = pricingLocationInfoMap[sellingPrice][itemLocationAvailability.location_id]
|
| 577 |
locationQty = itemLocationAvailability.virtual_availability + itemLocationAvailability.physical_availability
|
602 |
locationQty = itemLocationAvailability.virtual_availability + itemLocationAvailability.physical_availability
|
| Line 614... |
Line 639... |
| 614 |
pricingMap[sellingPrice] = -1
|
639 |
pricingMap[sellingPrice] = -1
|
| 615 |
else:
|
640 |
else:
|
| 616 |
pricingMap[sellingPrice] = priceLocationInfoMap[sellingPrice]
|
641 |
pricingMap[sellingPrice] = priceLocationInfoMap[sellingPrice]
|
| 617 |
|
642 |
|
| 618 |
return pricingMap
|
643 |
return pricingMap
|
| - |
|
644 |
|
| 619 |
|
645 |
|
| 620 |
def __getDeliveryDate(minDays, isCod, maxDays=None):
|
646 |
def __getDeliveryDate(minDays, isCod, maxDays=None):
|
| 621 |
curTime = datetime.datetime.now()
|
647 |
curTime = datetime.datetime.now()
|
| 622 |
if maxDays is None:
|
648 |
if maxDays is None:
|
| 623 |
maxDays = minDays
|
649 |
maxDays = minDays
|
| 624 |
if isCod and curTime.hour < 15:
|
650 |
if isCod and curTime.hour < 15:
|
| 625 |
maxDays = maxDays + 1
|
651 |
maxDays = maxDays + 1
|
| 626 |
return __getAdjustedDate(minDays), __getAdjustedDate(maxDays)
|
652 |
return __getAdjustedDate(minDays), __getAdjustedDate(maxDays)
|
| 627 |
|
653 |
|
| - |
|
654 |
|
| 628 |
def __getAdjustedDate(days):
|
655 |
def __getAdjustedDate(days):
|
| 629 |
curDate = datetime.date.today()
|
656 |
curDate = datetime.date.today()
|
| 630 |
if curDate == last_date:
|
657 |
if curDate == last_date:
|
| 631 |
if adjusted_dates.has_key(days):
|
658 |
if adjusted_dates.has_key(days):
|
| 632 |
return adjusted_dates[days]
|
659 |
return adjusted_dates[days]
|
| Line 637... |
Line 664... |
| 637 |
|
664 |
|
| 638 |
adjusted_date = to_java_date(datetime.datetime.combine(curDate, datetime.datetime.min.time()) + datetime.timedelta(days=adjusted_day))
|
665 |
adjusted_date = to_java_date(datetime.datetime.combine(curDate, datetime.datetime.min.time()) + datetime.timedelta(days=adjusted_day))
|
| 639 |
adjusted_dates[days] = adjusted_date
|
666 |
adjusted_dates[days] = adjusted_date
|
| 640 |
return adjusted_date
|
667 |
return adjusted_date
|
| 641 |
|
668 |
|
| - |
|
669 |
|
| 642 |
def reduce_reservation_count(item_id, warehouse_id, source_id, order_id, quantity):
|
670 |
def reduce_reservation_count(item_id, warehouse_id, source_id, order_id, quantity):
|
| 643 |
if not warehouse_id:
|
671 |
if not warehouse_id:
|
| 644 |
raise InventoryServiceException(101, "bad warehouse_id")
|
672 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| 645 |
|
673 |
|
| 646 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id)
|
674 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id)
|
| 647 |
try:
|
675 |
try:
|
| 648 |
current_inventory_snapshot = query.one()
|
676 |
current_inventory_snapshot = query.one()
|
| 649 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
|
677 |
current_inventory_snapshot.reserved = current_inventory_snapshot.reserved - quantity
|
| 650 |
|
678 |
|
| 651 |
reservation = CurrentReservationSnapshot.query.filter_by(warehouse_id = warehouse_id, item_id = item_id, source_id = source_id, order_id = order_id).one()
|
679 |
reservation = CurrentReservationSnapshot.query.filter_by(warehouse_id=warehouse_id, item_id=item_id, source_id=source_id, order_id=order_id).one()
|
| 652 |
if reservation.reserved == quantity:
|
680 |
if reservation.reserved == quantity:
|
| 653 |
reservation.delete()
|
681 |
reservation.delete()
|
| 654 |
else:
|
682 |
else:
|
| 655 |
reservation.reserved -= quantity
|
683 |
reservation.reserved -= quantity
|
| 656 |
session.commit()
|
684 |
session.commit()
|
| 657 |
#**Update item availability cache**#
|
685 |
# **Update item availability cache**#
|
| 658 |
clear_item_availability_cache(item_id)
|
686 |
clear_item_availability_cache(item_id)
|
| 659 |
if current_inventory_snapshot.reserved < 0:
|
687 |
if current_inventory_snapshot.reserved < 0:
|
| 660 |
item = __get_item_from_master(item_id)
|
688 |
item = __get_item_from_master(item_id)
|
| 661 |
__send_alert_for_negative_reserved(item, current_inventory_snapshot.reserved, get_Warehouse(warehouse_id))
|
689 |
__send_alert_for_negative_reserved(item, current_inventory_snapshot.reserved, get_Warehouse(warehouse_id))
|
| 662 |
return True
|
690 |
return True
|
| 663 |
except:
|
691 |
except:
|
| 664 |
print "Unexpected error:", sys.exc_info()[0]
|
692 |
print "Unexpected error:", sys.exc_info()[0]
|
| 665 |
return False
|
693 |
return False
|
| 666 |
|
694 |
|
| 667 |
#This is not the source as in snapdeal or website, this source is to incorporate different pricing depending upon source id.
|
695 |
# This is not the source as in snapdeal or website, this source is to incorporate different pricing depending upon source id.
|
| 668 |
#i.e. if user visiting to our site has specific source he would see pricing on that source basis. Default source is 1.
|
696 |
# i.e. if user visiting to our site has specific source he would see pricing on that source basis. Default source is 1.
|
| 669 |
# Have to add another source id 2 for fofo warehouses
|
697 |
# Have to add another source id 2 for fofo warehouses
|
| 670 |
|
698 |
|
| - |
|
699 |
|
| 671 |
def get_item_availability_for_state(itemId, sourceId, stateId):
|
700 |
def get_item_availability_for_state(itemId, sourceId, stateId):
|
| 672 |
__populateWarehouseMap()
|
701 |
__populateWarehouseMap()
|
| 673 |
currentInventorySnapshots = get_item_inventory_by_item_id(itemId)
|
702 |
currentInventorySnapshots = get_item_inventory_by_item_id(itemId)
|
| 674 |
totalAvailability = 0
|
703 |
totalAvailability = 0
|
| 675 |
expectedDelay = 0
|
704 |
expectedDelay = 0
|
| Line 687... |
Line 716... |
| 687 |
ia = get_item_availability_for_location(itemId, sourceId)
|
716 |
ia = get_item_availability_for_location(itemId, sourceId)
|
| 688 |
return [warehouseId, expectedDelay, billingVendorWarehouses[stateId], ia[3], totalAvailability, ia[5]]
|
717 |
return [warehouseId, expectedDelay, billingVendorWarehouses[stateId], ia[3], totalAvailability, ia[5]]
|
| 689 |
|
718 |
|
| 690 |
|
719 |
|
| 691 |
def get_item_availability_for_location(item_id, source_id):
|
720 |
def get_item_availability_for_location(item_id, source_id):
|
| 692 |
item_availability = ItemAvailabilityCache.get_by(itemId=item_id, sourceId = source_id)
|
721 |
item_availability = ItemAvailabilityCache.get_by(itemId=item_id, sourceId=source_id)
|
| 693 |
if item_availability:
|
722 |
if item_availability:
|
| 694 |
print "Selling Price", item_availability.sellingPrice
|
723 |
print "Selling Price", item_availability.sellingPrice
|
| 695 |
if item_availability.sellingPrice is None:
|
724 |
if item_availability.sellingPrice is None:
|
| 696 |
item_availability.sellingPrice = 100000
|
725 |
item_availability.sellingPrice = 100000
|
| 697 |
print "[item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight]"
|
726 |
print "[item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight]"
|
| 698 |
print item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight
|
727 |
print item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight
|
| 699 |
return [item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight]
|
728 |
return [item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, item_availability.totalAvailability, item_availability.weight]
|
| 700 |
#return [item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, 0, item_availability.weight]
|
729 |
# return [item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice, 0, item_availability.weight]
|
| 701 |
else:
|
730 |
else:
|
| 702 |
__update_item_availability_cache(item_id, source_id)
|
731 |
__update_item_availability_cache(item_id, source_id)
|
| 703 |
##Check risky status for the source
|
732 |
# #Check risky status for the source
|
| 704 |
__check_risky_item(item_id, source_id)
|
733 |
__check_risky_item(item_id, source_id)
|
| 705 |
return get_item_availability_for_location(item_id, source_id)
|
734 |
return get_item_availability_for_location(item_id, source_id)
|
| - |
|
735 |
|
| 706 |
|
736 |
|
| 707 |
def get_item_location_availability(item_id, locations=[]):
|
737 |
def get_item_location_availability(item_id, locations=[]):
|
| 708 |
if locations:
|
738 |
if locations:
|
| 709 |
newLocations = locations + [-1]
|
739 |
newLocations = locations + [-1]
|
| 710 |
itemisedItemLocationAvailability = ItemLocationAvailabilityCache.filter_by(itemId=item_id).filter(ItemLocationAvailability.locationId.in_(newLocations)).all()
|
740 |
itemisedItemLocationAvailability = ItemLocationAvailabilityCache.filter_by(itemId=item_id).filter(ItemLocationAvailability.locationId.in_(newLocations)).all()
|
| Line 720... |
Line 750... |
| 720 |
itemisedItemLocationAvailability
|
750 |
itemisedItemLocationAvailability
|
| 721 |
else:
|
751 |
else:
|
| 722 |
thriftList.append(to_t_item_location_availability(itemLocationAvailability))
|
752 |
thriftList.append(to_t_item_location_availability(itemLocationAvailability))
|
| 723 |
return thriftList
|
753 |
return thriftList
|
| 724 |
|
754 |
|
| - |
|
755 |
|
| 725 |
def __get_item_location_availability_bulk(item_ids, locations=[]):
|
756 |
def __get_item_location_availability_bulk(item_ids, locations=[]):
|
| 726 |
|
757 |
|
| 727 |
query = ItemLocationAvailabilityCache.query.filter(ItemLocationAvailabilityCache.item_id.in_(item_ids))
|
758 |
query = ItemLocationAvailabilityCache.query.filter(ItemLocationAvailabilityCache.item_id.in_(item_ids))
|
| 728 |
allPopulated = query.filter(ItemLocationAvailabilityCache.location_id==-1).all()
|
759 |
allPopulated = query.filter(ItemLocationAvailabilityCache.location_id == -1).all()
|
| 729 |
if len(item_ids) > len(allPopulated):
|
760 |
if len(item_ids) > len(allPopulated):
|
| 730 |
for item_id in allPopulated:
|
761 |
for item_id in allPopulated:
|
| 731 |
if item_id not in item_ids:
|
762 |
if item_id not in item_ids:
|
| 732 |
__update_item_location(item_id)
|
763 |
__update_item_location(item_id)
|
| 733 |
if locations:
|
764 |
if locations:
|
| 734 |
query.filter(ItemLocationAvailabilityCache.location_id.in_(locations)).all()
|
765 |
query.filter(ItemLocationAvailabilityCache.location_id.in_(locations)).all()
|
| 735 |
return query.all()
|
766 |
return query.all()
|
| 736 |
|
767 |
|
| 737 |
|
768 |
|
| 738 |
def clear_item_location_availability_cache(item_id, locations=[]):
|
769 |
def clear_item_location_availability_cache(item_id, locations=[]):
|
| 739 |
if type(item_id)==list:
|
770 |
if type(item_id) == list:
|
| 740 |
ItemLocationAvailabilityCache.query.filter(ItemLocationAvailabilityCache.itemId.in_(item_id)).delete(synchronize_session='fetch')
|
771 |
ItemLocationAvailabilityCache.query.filter(ItemLocationAvailabilityCache.itemId.in_(item_id)).delete(synchronize_session='fetch')
|
| 741 |
session.commit()
|
772 |
session.commit()
|
| 742 |
t = threading.Thread(target=_task_update_item_availability_cache, args=(item_id,))
|
773 |
t = threading.Thread(target=_task_update_item_availability_cache, args=(item_id,))
|
| 743 |
t.start()
|
774 |
t.start()
|
| 744 |
elif item_id:
|
775 |
elif item_id:
|
| 745 |
ItemLocationAvailabilityCache.query.filter_by(itemId = item_id).delete()
|
776 |
ItemLocationAvailabilityCache.query.filter_by(itemId=item_id).delete()
|
| 746 |
session.commit()
|
777 |
session.commit()
|
| 747 |
|
778 |
|
| - |
|
779 |
|
| 748 |
def clear_item_availability_cache(item_id = None):
|
780 |
def clear_item_availability_cache(item_id=None):
|
| 749 |
print item_id
|
781 |
print item_id
|
| 750 |
if type(item_id)==list:
|
782 |
if type(item_id) == list:
|
| 751 |
ItemAvailabilityCache.query.filter(ItemAvailabilityCache.itemId.in_(item_id)).delete(synchronize_session='fetch')
|
783 |
ItemAvailabilityCache.query.filter(ItemAvailabilityCache.itemId.in_(item_id)).delete(synchronize_session='fetch')
|
| 752 |
session.commit()
|
784 |
session.commit()
|
| 753 |
t = threading.Thread(target=_task_update_item_availability_cache, args=(item_id,))
|
785 |
t = threading.Thread(target=_task_update_item_availability_cache, args=(item_id,))
|
| 754 |
t.start()
|
786 |
t.start()
|
| 755 |
|
787 |
|
| 756 |
elif item_id:
|
788 |
elif item_id:
|
| 757 |
ItemAvailabilityCache.query.filter_by(itemId = item_id).delete()
|
789 |
ItemAvailabilityCache.query.filter_by(itemId=item_id).delete()
|
| 758 |
session.commit()
|
790 |
session.commit()
|
| - |
|
791 |
|
| 759 |
|
792 |
|
| 760 |
def _task_update_item_availability_cache(item_ids):
|
793 |
def _task_update_item_availability_cache(item_ids):
|
| 761 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
794 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 762 |
items = client.getItems(item_ids)
|
795 |
items = client.getItems(item_ids)
|
| 763 |
for item_id in item_ids:
|
796 |
for item_id in item_ids:
|
| Line 769... |
Line 802... |
| 769 |
except:
|
802 |
except:
|
| 770 |
print "Could not update cache for "
|
803 |
print "Could not update cache for "
|
| 771 |
continue
|
804 |
continue
|
| 772 |
return True
|
805 |
return True
|
| 773 |
|
806 |
|
| - |
|
807 |
|
| 774 |
def __update_item_location(item_id):
|
808 |
def __update_item_location(item_id):
|
| 775 |
ignoredWhs = get_ignored_warehouses(item_id)
|
809 |
ignoredWhs = get_ignored_warehouses(item_id)
|
| 776 |
|
810 |
|
| 777 |
itemsnapshot = CurrentInventorySnapshot.query.filter_by(item_id = item_id).all()
|
811 |
itemsnapshot = CurrentInventorySnapshot.query.filter_by(item_id=item_id).all()
|
| 778 |
locationsMap = {}
|
812 |
locationsMap = {}
|
| 779 |
for row in itemsnapshot:
|
813 |
for row in itemsnapshot:
|
| 780 |
warehouse = warehouseMap[row.warehouse_id]
|
814 |
warehouse = warehouseMap[row.warehouse_id]
|
| 781 |
if row.warehouse_id in ignoredWhs:
|
815 |
if row.warehouse_id in ignoredWhs:
|
| 782 |
continue
|
816 |
continue
|
| 783 |
|
817 |
|
| 784 |
location = warehouse.logisticsLocation
|
818 |
location = warehouse.logisticsLocation
|
| 785 |
if not locationsMap.has_key(location):
|
819 |
if not locationsMap.has_key(location):
|
| 786 |
locationsMap[location] = {"physicalQty":0, "virtualQty":0, "minTransferDelay":100, "maxTransferDelay":0}
|
820 |
locationsMap[location] = {"physicalQty":0, "virtualQty":0, "minTransferDelay":100, "maxTransferDelay":0}
|
| 787 |
locationMap = locationsMap[location]
|
821 |
locationMap = locationsMap[location]
|
| 788 |
if warehouse.type == 'THIRD_PARTY':
|
822 |
if warehouse.type == 'THIRD_PARTY':
|
| 789 |
locationMap["virtualQty"] += max(0, row.availability - row.reserverd - row.held)
|
823 |
locationMap["virtualQty"] += max(0, row.availability - row.reserverd - row.held)
|
| 790 |
locationMap["minTransferDelay"] = min(locationMap["minTransferDelay"], row.transferDelayInHours/24)
|
824 |
locationMap["minTransferDelay"] = min(locationMap["minTransferDelay"], row.transferDelayInHours / 24)
|
| 791 |
locationMap["maxTransferDelay"] = max(locationMap["maxTransferDelay"], row.transferDelayInHours/24)
|
825 |
locationMap["maxTransferDelay"] = max(locationMap["maxTransferDelay"], row.transferDelayInHours / 24)
|
| 792 |
else:
|
826 |
else:
|
| 793 |
locationMap["physicalQty"] += max(0, row.availability - row.reserverd - row.held)
|
827 |
locationMap["physicalQty"] += max(0, row.availability - row.reserverd - row.held)
|
| 794 |
locationMap["minTransferDelay"] = 0
|
828 |
locationMap["minTransferDelay"] = 0
|
| 795 |
for location, locationMap in locationsMap.iteritems():
|
829 |
for location, locationMap in locationsMap.iteritems():
|
| 796 |
if locationMap["virtualQty"] > 0 or locationMap["physicalQty"] > 0:
|
830 |
if locationMap["virtualQty"] > 0 or locationMap["physicalQty"] > 0:
|
| Line 799... |
Line 833... |
| 799 |
itemLocationAvailability.location_id = location
|
833 |
itemLocationAvailability.location_id = location
|
| 800 |
itemLocationAvailability.max_transfer_delay = locationMap["maxTransferDelay"]
|
834 |
itemLocationAvailability.max_transfer_delay = locationMap["maxTransferDelay"]
|
| 801 |
itemLocationAvailability.min_transfer_delay = locationMap["minTransferDelay"]
|
835 |
itemLocationAvailability.min_transfer_delay = locationMap["minTransferDelay"]
|
| 802 |
itemLocationAvailability.virtual_availability = locationMap["virtualQty"]
|
836 |
itemLocationAvailability.virtual_availability = locationMap["virtualQty"]
|
| 803 |
itemLocationAvailability.physical_availability = locationMap["physicalQty"]
|
837 |
itemLocationAvailability.physical_availability = locationMap["physicalQty"]
|
| 804 |
#Add location -1 for each item
|
838 |
# Add location -1 for each item
|
| 805 |
itemLocationAvailability = ItemLocationAvailabilityCache()
|
839 |
itemLocationAvailability = ItemLocationAvailabilityCache()
|
| 806 |
itemLocationAvailability.item_id = item_id
|
840 |
itemLocationAvailability.item_id = item_id
|
| 807 |
itemLocationAvailability.location_id = -1
|
841 |
itemLocationAvailability.location_id = -1
|
| 808 |
session.commit()
|
842 |
session.commit()
|
| 809 |
|
- |
|
| 810 |
|
- |
|
| 811 |
|
- |
|
| 812 |
|
843 |
|
| 813 |
|
844 |
|
| 814 |
def __update_item_availability_cache(item_id, source_id, item=None):
|
845 |
def __update_item_availability_cache(item_id, source_id, item=None):
|
| 815 |
"""
|
846 |
"""
|
| 816 |
Then how shoud we handle virtual because for both source virtual gonna mark
|
847 |
Then how shoud we handle virtual because for both source virtual gonna mark
|
| Line 892... |
Line 923... |
| 892 |
warehouse = warehouses[warehouse_retid]
|
923 |
warehouse = warehouses[warehouse_retid]
|
| 893 |
billingWarehouseId = warehouse.billingWarehouseId
|
924 |
billingWarehouseId = warehouse.billingWarehouseId
|
| 894 |
|
925 |
|
| 895 |
# Fetching billing warehouse of a Good billable warehouse corresponding to the virtual one
|
926 |
# Fetching billing warehouse of a Good billable warehouse corresponding to the virtual one
|
| 896 |
if not warehouse.billingWarehouseId:
|
927 |
if not warehouse.billingWarehouseId:
|
| 897 |
for w in Warehouse.query.filter_by(vendor_id = warehouse.vendor_id, inventoryType = InventoryType._VALUES_TO_NAMES[InventoryType.GOOD], state_id=warehouse.state_id).all():
|
928 |
for w in Warehouse.query.filter_by(vendor_id=warehouse.vendor_id, inventoryType=InventoryType._VALUES_TO_NAMES[InventoryType.GOOD], state_id=warehouse.state_id).all():
|
| 898 |
if w.billingWarehouseId:
|
929 |
if w.billingWarehouseId:
|
| 899 |
billingWarehouseId = w.billingWarehouseId
|
930 |
billingWarehouseId = w.billingWarehouseId
|
| 900 |
break
|
931 |
break
|
| 901 |
|
932 |
|
| 902 |
expectedDelay = item.expectedDelay
|
933 |
expectedDelay = item.expectedDelay
|
| Line 917... |
Line 948... |
| 917 |
|
948 |
|
| 918 |
if WarehouseType._NAMES_TO_VALUES[warehouse.warehouseType] == WarehouseType.THIRD_PARTY:
|
949 |
if WarehouseType._NAMES_TO_VALUES[warehouse.warehouseType] == WarehouseType.THIRD_PARTY:
|
| 919 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(warehouse.vendor_id, expectedDelay)
|
950 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(warehouse.vendor_id, expectedDelay)
|
| 920 |
|
951 |
|
| 921 |
total_availability = 0
|
952 |
total_availability = 0
|
| 922 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
953 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id=item_id).all():
|
| 923 |
if entry.warehouse_id not in ignoredWhs:
|
954 |
if entry.warehouse_id not in ignoredWhs:
|
| 924 |
if entry.warehouse_id not in ourGoodWarehouses and entry.warehouse_id not in thirdpartyWarehouses:
|
955 |
if entry.warehouse_id not in ourGoodWarehouses and entry.warehouse_id not in thirdpartyWarehouses:
|
| 925 |
continue
|
956 |
continue
|
| 926 |
if entry.warehouse_id in ourGoodWarehouses and ourGoodWarehouses[entry.warehouse_id].billingWarehouseId == billingWarehouseId:
|
957 |
if entry.warehouse_id in ourGoodWarehouses and ourGoodWarehouses[entry.warehouse_id].billingWarehouseId == billingWarehouseId:
|
| 927 |
total_availability += entry.availability - entry.reserved - entry.held
|
958 |
total_availability += entry.availability - entry.reserved - entry.held
|
| 928 |
elif entry.warehouse_id in thirdpartyWarehouses:
|
959 |
elif entry.warehouse_id in thirdpartyWarehouses:
|
| 929 |
vendorId = thirdpartyWarehouses[entry.warehouse_id].vendor_id
|
960 |
vendorId = thirdpartyWarehouses[entry.warehouse_id].vendor_id
|
| 930 |
for goodWarehouse in ourGoodWarehouses.values():
|
961 |
for goodWarehouse in ourGoodWarehouses.values():
|
| 931 |
if goodWarehouse.vendor_id==vendorId and goodWarehouse.billingWarehouseId == billingWarehouseId and warehouse.state_id==goodWarehouse.state_id:
|
962 |
if goodWarehouse.vendor_id == vendorId and goodWarehouse.billingWarehouseId == billingWarehouseId and warehouse.state_id == goodWarehouse.state_id:
|
| 932 |
total_availability += entry.availability - entry.reserved - entry.held
|
963 |
total_availability += entry.availability - entry.reserved - entry.held
|
| 933 |
break
|
964 |
break
|
| 934 |
|
965 |
|
| 935 |
item_availability_cache = ItemAvailabilityCache.get_by(itemId=item_id, sourceId=source_id)
|
966 |
item_availability_cache = ItemAvailabilityCache.get_by(itemId=item_id, sourceId=source_id)
|
| 936 |
if item_availability_cache is None:
|
967 |
if item_availability_cache is None:
|
| Line 940... |
Line 971... |
| 940 |
item_availability_cache.warehouseId = int(warehouse_retid)
|
971 |
item_availability_cache.warehouseId = int(warehouse_retid)
|
| 941 |
item_availability_cache.expectedDelay = expectedDelay
|
972 |
item_availability_cache.expectedDelay = expectedDelay
|
| 942 |
item_availability_cache.billingWarehouseId = billingWarehouseId
|
973 |
item_availability_cache.billingWarehouseId = billingWarehouseId
|
| 943 |
item_availability_cache.sellingPrice = item.sellingPrice
|
974 |
item_availability_cache.sellingPrice = item.sellingPrice
|
| 944 |
item_availability_cache.totalAvailability = total_availability
|
975 |
item_availability_cache.totalAvailability = total_availability
|
| 945 |
#item_availability_cache.location = warehouse.logisticsLocation
|
976 |
# item_availability_cache.location = warehouse.logisticsLocation
|
| 946 |
item_availability_cache.weight = 1000*item.weight if item.weight else 300
|
977 |
item_availability_cache.weight = 1000 * item.weight if item.weight else 300
|
| 947 |
session.commit()
|
978 |
session.commit()
|
| 948 |
|
979 |
|
| - |
|
980 |
|
| 949 |
def __get_warehouse_with_min_transfer_price(warehouses, ignoredWhs, item_id, item_pricing, ignoreAvailability):
|
981 |
def __get_warehouse_with_min_transfer_price(warehouses, ignoredWhs, item_id, item_pricing, ignoreAvailability):
|
| 950 |
warehouse_retid = -1
|
982 |
warehouse_retid = -1
|
| 951 |
minTransferPrice = None
|
983 |
minTransferPrice = None
|
| 952 |
total_availability = 0
|
984 |
total_availability = 0
|
| 953 |
availabilityForBillingWarehouses = {}
|
985 |
availabilityForBillingWarehouses = {}
|
| 954 |
warehousesAvailability = {}
|
986 |
warehousesAvailability = {}
|
| 955 |
availability = 0
|
987 |
availability = 0
|
| 956 |
billing_warehouse_retid = None
|
988 |
billing_warehouse_retid = None
|
| 957 |
|
989 |
|
| 958 |
if not ignoreAvailability:
|
990 |
if not ignoreAvailability:
|
| 959 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
991 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id=item_id).all():
|
| 960 |
entry.reserved = max(entry.reserved, 0)
|
992 |
entry.reserved = max(entry.reserved, 0)
|
| 961 |
entry.held = max(entry.held, 0)
|
993 |
entry.held = max(entry.held, 0)
|
| 962 |
#if entry.availability > entry.reserved:
|
994 |
# if entry.availability > entry.reserved:
|
| 963 |
warehousesAvailability[entry.warehouse_id] = [entry.availability, entry.reserved, entry.held]
|
995 |
warehousesAvailability[entry.warehouse_id] = [entry.availability, entry.reserved, entry.held]
|
| 964 |
|
996 |
|
| 965 |
if len(ignoredWhs) > 0:
|
997 |
if len(ignoredWhs) > 0:
|
| 966 |
for whid in ignoredWhs:
|
998 |
for whid in ignoredWhs:
|
| 967 |
if warehousesAvailability.has_key(whid):
|
999 |
if warehousesAvailability.has_key(whid):
|
| Line 969... |
Line 1001... |
| 969 |
warehousesAvailability[whid][1] = 0
|
1001 |
warehousesAvailability[whid][1] = 0
|
| 970 |
warehousesAvailability[whid][2] = 0
|
1002 |
warehousesAvailability[whid][2] = 0
|
| 971 |
|
1003 |
|
| 972 |
for warehouse in warehouses.values():
|
1004 |
for warehouse in warehouses.values():
|
| 973 |
if not ignoreAvailability:
|
1005 |
if not ignoreAvailability:
|
| 974 |
#TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
1006 |
# TODO Mistake no entry for this warehouse.id in warehouseswithAvailab
|
| 975 |
if warehouse.id not in warehousesAvailability:
|
1007 |
if warehouse.id not in warehousesAvailability:
|
| 976 |
continue
|
1008 |
continue
|
| 977 |
entry = warehousesAvailability[warehouse.id]
|
1009 |
entry = warehousesAvailability[warehouse.id]
|
| 978 |
if warehouse.billingWarehouseId in availabilityForBillingWarehouses:
|
1010 |
if warehouse.billingWarehouseId in availabilityForBillingWarehouses:
|
| 979 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
1011 |
if warehouse.billingWarehouseId is not None or warehouse.billingWarehouseId != 0:
|
| Line 992... |
Line 1024... |
| 992 |
if minTransferPrice is None or (transferPrice and minTransferPrice > transferPrice):
|
1024 |
if minTransferPrice is None or (transferPrice and minTransferPrice > transferPrice):
|
| 993 |
warehouse_retid = warehouse.id
|
1025 |
warehouse_retid = warehouse.id
|
| 994 |
billing_warehouse_retid = warehouse.billingWarehouseId
|
1026 |
billing_warehouse_retid = warehouse.billingWarehouseId
|
| 995 |
minTransferPrice = transferPrice
|
1027 |
minTransferPrice = transferPrice
|
| 996 |
|
1028 |
|
| 997 |
|
- |
|
| 998 |
if billing_warehouse_retid in availabilityForBillingWarehouses:
|
1029 |
if billing_warehouse_retid in availabilityForBillingWarehouses:
|
| 999 |
availability = availabilityForBillingWarehouses[billing_warehouse_retid]
|
1030 |
availability = availabilityForBillingWarehouses[billing_warehouse_retid]
|
| 1000 |
else:
|
1031 |
else:
|
| 1001 |
availability = total_availability
|
1032 |
availability = total_availability
|
| 1002 |
|
1033 |
|
| 1003 |
print "[warehouse_retid, availability]", warehouse_retid, availability
|
1034 |
print "[warehouse_retid, availability]", warehouse_retid, availability
|
| 1004 |
return [warehouse_retid, availability]
|
1035 |
return [warehouse_retid, availability]
|
| 1005 |
|
1036 |
|
| - |
|
1037 |
|
| 1006 |
def __get_warehouse_with_min_transfer_delay(warehouses, ignoredWhs, item_id, item_pricing):
|
1038 |
def __get_warehouse_with_min_transfer_delay(warehouses, ignoredWhs, item_id, item_pricing):
|
| 1007 |
minTransferDelay = None
|
1039 |
minTransferDelay = None
|
| 1008 |
minTransferDelayWarehouses = {}
|
1040 |
minTransferDelayWarehouses = {}
|
| 1009 |
total_availability = 0
|
1041 |
total_availability = 0
|
| 1010 |
|
1042 |
|
| 1011 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
1043 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id=item_id).all():
|
| 1012 |
entry.reserved = max(entry.reserved, 0)
|
1044 |
entry.reserved = max(entry.reserved, 0)
|
| 1013 |
entry.held = max(entry.held, 0)
|
1045 |
entry.held = max(entry.held, 0)
|
| 1014 |
if warehouses.has_key(entry.warehouse_id):
|
1046 |
if warehouses.has_key(entry.warehouse_id):
|
| 1015 |
warehouse = warehouses[entry.warehouse_id]
|
1047 |
warehouse = warehouses[entry.warehouse_id]
|
| 1016 |
#if entry.availability > entry.reserved:
|
1048 |
# if entry.availability > entry.reserved:
|
| 1017 |
if entry.warehouse_id not in ignoredWhs:
|
1049 |
if entry.warehouse_id not in ignoredWhs:
|
| 1018 |
total_availability += entry.availability - entry.reserved - entry.held
|
1050 |
total_availability += entry.availability - entry.reserved - entry.held
|
| 1019 |
if entry.availability - entry.reserved - entry.held <= 0:
|
1051 |
if entry.availability - entry.reserved - entry.held <= 0:
|
| 1020 |
continue
|
1052 |
continue
|
| 1021 |
transferDelay = warehouse.transferDelayInHours
|
1053 |
transferDelay = warehouse.transferDelayInHours
|
| Line 1025... |
Line 1057... |
| 1025 |
minTransferDelayWarehouses[warehouse.id] = warehouse
|
1057 |
minTransferDelayWarehouses[warehouse.id] = warehouse
|
| 1026 |
minTransferDelay = transferDelay
|
1058 |
minTransferDelay = transferDelay
|
| 1027 |
|
1059 |
|
| 1028 |
return [__get_warehouse_with_min_transfer_price(minTransferDelayWarehouses, ignoredWhs, item_id, item_pricing, False)[0], total_availability]
|
1060 |
return [__get_warehouse_with_min_transfer_price(minTransferDelayWarehouses, ignoredWhs, item_id, item_pricing, False)[0], total_availability]
|
| 1029 |
|
1061 |
|
| - |
|
1062 |
|
| 1030 |
def __get_warehouse_with_max_availability(warehouse_ids, item_id):
|
1063 |
def __get_warehouse_with_max_availability(warehouse_ids, item_id):
|
| 1031 |
warehouse_retid = -1
|
1064 |
warehouse_retid = -1
|
| 1032 |
max_availability = 0
|
1065 |
max_availability = 0
|
| 1033 |
total_availability = 0
|
1066 |
total_availability = 0
|
| 1034 |
|
1067 |
|
| 1035 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id = item_id).all():
|
1068 |
for entry in CurrentInventorySnapshot.query.filter_by(item_id=item_id).all():
|
| 1036 |
entry.reserved = max(entry.reserved, 0)
|
1069 |
entry.reserved = max(entry.reserved, 0)
|
| 1037 |
entry.held = max(entry.held, 0)
|
1070 |
entry.held = max(entry.held, 0)
|
| 1038 |
if entry.warehouse_id in warehouse_ids:
|
1071 |
if entry.warehouse_id in warehouse_ids:
|
| 1039 |
availability = entry.availability - entry.reserved
|
1072 |
availability = entry.availability - entry.reserved
|
| 1040 |
if availability > max_availability:
|
1073 |
if availability > max_availability:
|
| Line 1042... |
Line 1075... |
| 1042 |
max_availability = availability
|
1075 |
max_availability = availability
|
| 1043 |
total_availability += availability
|
1076 |
total_availability += availability
|
| 1044 |
|
1077 |
|
| 1045 |
return [warehouse_retid, total_availability]
|
1078 |
return [warehouse_retid, total_availability]
|
| 1046 |
|
1079 |
|
| - |
|
1080 |
|
| 1047 |
def __get_vendor_holiday_delay(vendor_id, expectedDelay):
|
1081 |
def __get_vendor_holiday_delay(vendor_id, expectedDelay):
|
| 1048 |
## If vendor is closed two days continuously
|
1082 |
# # If vendor is closed two days continuously
|
| 1049 |
holidayDelay = 0
|
1083 |
holidayDelay = 0
|
| 1050 |
currentDate = datetime.date.today()
|
1084 |
currentDate = datetime.date.today()
|
| 1051 |
expectedDate = currentDate + datetime.timedelta(days = expectedDelay)
|
1085 |
expectedDate = currentDate + datetime.timedelta(days=expectedDelay)
|
| 1052 |
holidays = VendorHolidays.query.filter(VendorHolidays.vendor_id == vendor_id).filter(VendorHolidays.date.between(currentDate, expectedDate)).all()
|
1086 |
holidays = VendorHolidays.query.filter(VendorHolidays.vendor_id == vendor_id).filter(VendorHolidays.date.between(currentDate, expectedDate)).all()
|
| 1053 |
if holidays:
|
1087 |
if holidays:
|
| 1054 |
holidayDelay = holidayDelay + len(holidays)
|
1088 |
holidayDelay = holidayDelay + len(holidays)
|
| 1055 |
return holidayDelay
|
1089 |
return holidayDelay
|
| 1056 |
|
1090 |
|
| - |
|
1091 |
|
| 1057 |
def get_item_pricing(item_id, vendorId):
|
1092 |
def get_item_pricing(item_id, vendorId):
|
| 1058 |
'''
|
1093 |
'''
|
| 1059 |
if vendor id is -1 then we calculate an average transfer price to be populated
|
1094 |
if vendor id is -1 then we calculate an average transfer price to be populated
|
| 1060 |
at the time of order creation. This will be later updated with actual transfer price
|
1095 |
at the time of order creation. This will be later updated with actual transfer price
|
| 1061 |
at the time of billing.
|
1096 |
at the time of billing.
|
| Line 1068... |
Line 1103... |
| 1068 |
item = __get_item_from_master(item_id)
|
1103 |
item = __get_item_from_master(item_id)
|
| 1069 |
if item.preferredVendor is not None:
|
1104 |
if item.preferredVendor is not None:
|
| 1070 |
item_pricing = VendorItemPricing.query.filter_by(item_id=item_id, vendor_id=item.preferredVendor).first()
|
1105 |
item_pricing = VendorItemPricing.query.filter_by(item_id=item_id, vendor_id=item.preferredVendor).first()
|
| 1071 |
if item_pricing:
|
1106 |
if item_pricing:
|
| 1072 |
item_pricings.append(item_pricing)
|
1107 |
item_pricings.append(item_pricing)
|
| 1073 |
else :
|
1108 |
else:
|
| 1074 |
item_pricings = VendorItemPricing.query.filter_by(item_id=item_id).all()
|
1109 |
item_pricings = VendorItemPricing.query.filter_by(item_id=item_id).all()
|
| 1075 |
if item_pricings:
|
1110 |
if item_pricings:
|
| 1076 |
for item_pricing in item_pricings:
|
1111 |
for item_pricing in item_pricings:
|
| 1077 |
tp_total += item_pricing.transfer_price
|
1112 |
tp_total += item_pricing.transfer_price
|
| 1078 |
nlc_total += item_pricing.nlc
|
1113 |
nlc_total += item_pricing.nlc
|
| Line 1099... |
Line 1134... |
| 1099 |
except MultipleResultsFound:
|
1134 |
except MultipleResultsFound:
|
| 1100 |
raise InventoryServiceException(110, "Multiple pricing information present for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
1135 |
raise InventoryServiceException(110, "Multiple pricing information present for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
| 1101 |
except NoResultFound:
|
1136 |
except NoResultFound:
|
| 1102 |
raise InventoryServiceException(111, "Missing pricing information for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
1137 |
raise InventoryServiceException(111, "Missing pricing information for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
| 1103 |
|
1138 |
|
| - |
|
1139 |
|
| 1104 |
def get_all_item_pricing(item_id):
|
1140 |
def get_all_item_pricing(item_id):
|
| 1105 |
item_pricing = VendorItemPricing.query.filter_by(item_id=item_id).all()
|
1141 |
item_pricing = VendorItemPricing.query.filter_by(item_id=item_id).all()
|
| 1106 |
return item_pricing
|
1142 |
return item_pricing
|
| - |
|
1143 |
|
| - |
|
1144 |
|
| 1107 |
def get_all_vendor_item_pricing(item_id, vendor_id):
|
1145 |
def get_all_vendor_item_pricing(item_id, vendor_id):
|
| 1108 |
query = VendorItemPricing.query
|
1146 |
query = VendorItemPricing.query
|
| 1109 |
if item_id:
|
1147 |
if item_id:
|
| 1110 |
query = query.filter_by(item_id = item_id)
|
1148 |
query = query.filter_by(item_id=item_id)
|
| 1111 |
if item_id:
|
1149 |
if item_id:
|
| 1112 |
query = query.filter_by(vendor_id = vendor_id)
|
1150 |
query = query.filter_by(vendor_id=vendor_id)
|
| 1113 |
item_pricing = query.all()
|
1151 |
item_pricing = query.all()
|
| 1114 |
return item_pricing
|
1152 |
return item_pricing
|
| - |
|
1153 |
|
| 1115 |
|
1154 |
|
| 1116 |
def get_item_mappings(item_id):
|
1155 |
def get_item_mappings(item_id):
|
| 1117 |
item_mappings = VendorItemMapping.query.filter_by(item_id=item_id).all()
|
1156 |
item_mappings = VendorItemMapping.query.filter_by(item_id=item_id).all()
|
| 1118 |
return item_mappings
|
1157 |
return item_mappings
|
| 1119 |
|
1158 |
|
| - |
|
1159 |
|
| 1120 |
def add_vendor_pricing(vendorItemPricing, sendMail = True):
|
1160 |
def add_vendor_pricing(vendorItemPricing, sendMail=True):
|
| 1121 |
if not vendorItemPricing:
|
1161 |
if not vendorItemPricing:
|
| 1122 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
1162 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
| 1123 |
vendorId = vendorItemPricing.vendorId
|
1163 |
vendorId = vendorItemPricing.vendorId
|
| 1124 |
itemId = vendorItemPricing.itemId
|
1164 |
itemId = vendorItemPricing.itemId
|
| 1125 |
|
1165 |
|
| Line 1134... |
Line 1174... |
| 1134 |
raise InventoryServiceException(101, "Item not found for itemId " + str(itemId))
|
1174 |
raise InventoryServiceException(101, "Item not found for itemId " + str(itemId))
|
| 1135 |
|
1175 |
|
| 1136 |
validate_vendor_prices(item, vendorItemPricing)
|
1176 |
validate_vendor_prices(item, vendorItemPricing)
|
| 1137 |
|
1177 |
|
| 1138 |
try:
|
1178 |
try:
|
| 1139 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item_id==itemId)).one()
|
1179 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor == vendor, VendorItemPricing.item_id == itemId)).one()
|
| 1140 |
except:
|
1180 |
except:
|
| 1141 |
ds_vendorItemPricing = VendorItemPricing()
|
1181 |
ds_vendorItemPricing = VendorItemPricing()
|
| 1142 |
ds_vendorItemPricing.vendor = vendor
|
1182 |
ds_vendorItemPricing.vendor = vendor
|
| 1143 |
ds_vendorItemPricing.item_id = itemId
|
1183 |
ds_vendorItemPricing.item_id = itemId
|
| 1144 |
|
1184 |
|
| Line 1147... |
Line 1187... |
| 1147 |
if vendorItemPricing.mop:
|
1187 |
if vendorItemPricing.mop:
|
| 1148 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
1188 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
| 1149 |
if vendorItemPricing.dealerPrice:
|
1189 |
if vendorItemPricing.dealerPrice:
|
| 1150 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
1190 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
| 1151 |
if vendorItemPricing.transferPrice:
|
1191 |
if vendorItemPricing.transferPrice:
|
| 1152 |
#if vendorItemPricing.transferPrice != ds_vendorItemPricing.transfer_price:
|
1192 |
# if vendorItemPricing.transferPrice != ds_vendorItemPricing.transfer_price:
|
| 1153 |
# client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
1193 |
# client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 1154 |
# item = client.getItem(itemId)
|
1194 |
# item = client.getItem(itemId)
|
| 1155 |
# message = "Transfer price for Item {0} {1} {2} {3} \nand Vendor:{4} is changed from {5} to {6}.".format(item.brand, item.modelName, item.modelNumber, item.color, vendor.name, ds_vendorItemPricing.transfer_price, vendorItemPricing.transferPrice)
|
1195 |
# message = "Transfer price for Item {0} {1} {2} {3} \nand Vendor:{4} is changed from {5} to {6}.".format(item.brand, item.modelName, item.modelNumber, item.color, vendor.name, ds_vendorItemPricing.transfer_price, vendorItemPricing.transferPrice)
|
| 1156 |
# subject = "Alert:Change in Transfer Price {0} {1} {2} {3} {4}".format(item.brand, item.modelName, item.modelNumber, item.color, itemId)
|
1196 |
# subject = "Alert:Change in Transfer Price {0} {1} {2} {3} {4}".format(item.brand, item.modelName, item.modelNumber, item.color, itemId)
|
| 1157 |
ds_vendorItemPricing.transfer_price = vendorItemPricing.transferPrice
|
1197 |
ds_vendorItemPricing.transfer_price = vendorItemPricing.transferPrice
|
| 1158 |
if vendorItemPricing.nlc:
|
1198 |
if vendorItemPricing.nlc:
|
| 1159 |
#if vendorItemPricing.nlc != ds_vendorItemPricing.nlc:
|
1199 |
# if vendorItemPricing.nlc != ds_vendorItemPricing.nlc:
|
| 1160 |
# client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
1200 |
# client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 1161 |
# item = client.getItem(itemId)
|
1201 |
# item = client.getItem(itemId)
|
| 1162 |
# message = message + "\nNLC for Item {0} {1} {2} {3} \nand Vendor:{4} is changed from {5} to {6}.".format(item.brand, item.modelName, item.modelNumber, item.color, vendor.name, ds_vendorItemPricing.nlc, vendorItemPricing.nlc)
|
1202 |
# message = message + "\nNLC for Item {0} {1} {2} {3} \nand Vendor:{4} is changed from {5} to {6}.".format(item.brand, item.modelName, item.modelNumber, item.color, vendor.name, ds_vendorItemPricing.nlc, vendorItemPricing.nlc)
|
| 1163 |
# subject = "Alert:Change in NLC {0} {1} {2} {3} {4}".format(item.brand, item.modelName, item.modelNumber, item.color, itemId)
|
1203 |
# subject = "Alert:Change in NLC {0} {1} {2} {3} {4}".format(item.brand, item.modelName, item.modelNumber, item.color, itemId)
|
| 1164 |
ds_vendorItemPricing.nlc = vendorItemPricing.nlc
|
1204 |
ds_vendorItemPricing.nlc = vendorItemPricing.nlc
|
| 1165 |
session.commit()
|
1205 |
session.commit()
|
| 1166 |
#client = CatalogClient("catalog_service_server_host_staging", "catalog_service_server_port").get_client()
|
1206 |
# client = CatalogClient("catalog_service_server_host_staging", "catalog_service_server_port").get_client()
|
| 1167 |
#client.updateNlcAtMarketplaces(itemId,vendorId,ds_vendorItemPricing.nlc)
|
1207 |
# client.updateNlcAtMarketplaces(itemId,vendorId,ds_vendorItemPricing.nlc)
|
| 1168 |
#if subject and sendMail:
|
1208 |
# if subject and sendMail:
|
| 1169 |
# __send_mail(subject, message)
|
1209 |
# __send_mail(subject, message)
|
| 1170 |
return
|
1210 |
return
|
| 1171 |
|
1211 |
|
| - |
|
1212 |
|
| 1172 |
def add_vendor_item_mapping(key, vendorItemMapping):
|
1213 |
def add_vendor_item_mapping(key, vendorItemMapping):
|
| 1173 |
if not vendorItemMapping:
|
1214 |
if not vendorItemMapping:
|
| 1174 |
raise InventoryServiceException(108, "Bad vendorItemMapping in request")
|
1215 |
raise InventoryServiceException(108, "Bad vendorItemMapping in request")
|
| 1175 |
vendorId = vendorItemMapping.vendorId
|
1216 |
vendorId = vendorItemMapping.vendorId
|
| 1176 |
itemId = vendorItemMapping.itemId
|
1217 |
itemId = vendorItemMapping.itemId
|
| Line 1179... |
Line 1220... |
| 1179 |
vendor = Vendor.query.filter_by(id=vendorId).one()
|
1220 |
vendor = Vendor.query.filter_by(id=vendorId).one()
|
| 1180 |
except:
|
1221 |
except:
|
| 1181 |
raise InventoryServiceException(101, "Vendor not found for vendorId " + str(vendorId))
|
1222 |
raise InventoryServiceException(101, "Vendor not found for vendorId " + str(vendorId))
|
| 1182 |
|
1223 |
|
| 1183 |
try:
|
1224 |
try:
|
| 1184 |
ds_vendorItemMapping = VendorItemMapping.query.filter(and_(VendorItemMapping.vendor==vendor, VendorItemMapping.item_id==itemId, VendorItemMapping.item_key==key)).one()
|
1225 |
ds_vendorItemMapping = VendorItemMapping.query.filter(and_(VendorItemMapping.vendor == vendor, VendorItemMapping.item_id == itemId, VendorItemMapping.item_key == key)).one()
|
| 1185 |
except:
|
1226 |
except:
|
| 1186 |
ds_vendorItemMapping = VendorItemMapping()
|
1227 |
ds_vendorItemMapping = VendorItemMapping()
|
| 1187 |
ds_vendorItemMapping.vendor = vendor
|
1228 |
ds_vendorItemMapping.vendor = vendor
|
| 1188 |
ds_vendorItemMapping.item_id = itemId
|
1229 |
ds_vendorItemMapping.item_id = itemId
|
| 1189 |
ds_vendorItemMapping.item_key = vendorItemMapping.itemKey
|
1230 |
ds_vendorItemMapping.item_key = vendorItemMapping.itemKey
|
| 1190 |
|
1231 |
|
| 1191 |
session.commit()
|
1232 |
session.commit()
|
| 1192 |
|
1233 |
|
| 1193 |
# Marking the missed inventory as not ignored as the catalog dashboard user has updated their key
|
1234 |
# Marking the missed inventory as not ignored as the catalog dashboard user has updated their key
|
| 1194 |
for missedInventoryUpdate in MissedInventoryUpdate.query.filter_by(itemKey = vendorItemMapping.itemKey).all():
|
1235 |
for missedInventoryUpdate in MissedInventoryUpdate.query.filter_by(itemKey=vendorItemMapping.itemKey).all():
|
| 1195 |
missedInventoryUpdate.isIgnored = 0
|
1236 |
missedInventoryUpdate.isIgnored = 0
|
| 1196 |
session.commit()
|
1237 |
session.commit()
|
| 1197 |
|
1238 |
|
| 1198 |
return
|
1239 |
return
|
| 1199 |
|
1240 |
|
| - |
|
1241 |
|
| 1200 |
def validate_vendor_prices(item, vendorPrices):
|
1242 |
def validate_vendor_prices(item, vendorPrices):
|
| 1201 |
if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
1243 |
if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
| 1202 |
print "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
1244 |
print "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
| 1203 |
raise InventoryServiceException(101, "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
1245 |
raise InventoryServiceException(101, "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
| 1204 |
return
|
1246 |
return
|
| 1205 |
#if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
1247 |
# if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
| 1206 |
# print "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
1248 |
# print "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
| 1207 |
# raise InventoryServiceException(101, "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
1249 |
# raise InventoryServiceException(101, "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
| 1208 |
#return
|
1250 |
# return
|
| - |
|
1251 |
|
| 1209 |
|
1252 |
|
| 1210 |
def get_all_vendors():
|
1253 |
def get_all_vendors():
|
| 1211 |
return Vendor.query.all()
|
1254 |
return Vendor.query.all()
|
| 1212 |
|
1255 |
|
| - |
|
1256 |
|
| 1213 |
def get_pending_orders_inventory(vendor_id=1):
|
1257 |
def get_pending_orders_inventory(vendor_id=1):
|
| 1214 |
"""
|
1258 |
"""
|
| 1215 |
Returns a list of inventory stock for items for which there are pending orders.
|
1259 |
Returns a list of inventory stock for items for which there are pending orders.
|
| 1216 |
"""
|
1260 |
"""
|
| 1217 |
|
1261 |
|
| 1218 |
warehouse_ids = [warehouse.id for warehouse in Warehouse.query.filter_by(vendor_id = vendor_id)]
|
1262 |
warehouse_ids = [warehouse.id for warehouse in Warehouse.query.filter_by(vendor_id=vendor_id)]
|
| 1219 |
pending_items_inventory = []
|
1263 |
pending_items_inventory = []
|
| 1220 |
if warehouse_ids:
|
1264 |
if warehouse_ids:
|
| 1221 |
pending_items_inventory = session.query(CurrentInventorySnapshot.item_id, func.sum(CurrentInventorySnapshot.availability), func.sum(CurrentInventorySnapshot.reserved)).filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).group_by(CurrentInventorySnapshot.item_id).having(func.sum(CurrentInventorySnapshot.reserved) > 0).all()
|
1265 |
pending_items_inventory = session.query(CurrentInventorySnapshot.item_id, func.sum(CurrentInventorySnapshot.availability), func.sum(CurrentInventorySnapshot.reserved)).filter(CurrentInventorySnapshot.warehouse_id.in_(warehouse_ids)).group_by(CurrentInventorySnapshot.item_id).having(func.sum(CurrentInventorySnapshot.reserved) > 0).all()
|
| 1222 |
return pending_items_inventory
|
1266 |
return pending_items_inventory
|
| 1223 |
|
1267 |
|
| - |
|
1268 |
|
| 1224 |
def get_billable_inventory_and_pending_orders():
|
1269 |
def get_billable_inventory_and_pending_orders():
|
| 1225 |
"""
|
1270 |
"""
|
| 1226 |
Returns a list of inventory Availability and Reserved Count for items which either have real inventory
|
1271 |
Returns a list of inventory Availability and Reserved Count for items which either have real inventory
|
| 1227 |
or have pending orders.
|
1272 |
or have pending orders.
|
| 1228 |
"""
|
1273 |
"""
|
| Line 1243... |
Line 1288... |
| 1243 |
def close_session():
|
1288 |
def close_session():
|
| 1244 |
if session.is_active:
|
1289 |
if session.is_active:
|
| 1245 |
print "session is active. closing it."
|
1290 |
print "session is active. closing it."
|
| 1246 |
session.close()
|
1291 |
session.close()
|
| 1247 |
|
1292 |
|
| - |
|
1293 |
|
| 1248 |
def is_alive():
|
1294 |
def is_alive():
|
| 1249 |
try:
|
1295 |
try:
|
| 1250 |
session.query(Vendor.id).limit(1).one()
|
1296 |
session.query(Vendor.id).limit(1).one()
|
| 1251 |
return True
|
1297 |
return True
|
| 1252 |
except:
|
1298 |
except:
|
| 1253 |
return False
|
1299 |
return False
|
| 1254 |
|
1300 |
|
| - |
|
1301 |
|
| 1255 |
def add_vendor(vendor):
|
1302 |
def add_vendor(vendor):
|
| 1256 |
if not vendor:
|
1303 |
if not vendor:
|
| 1257 |
raise InventoryServiceException(108, "Bad vendor")
|
1304 |
raise InventoryServiceException(108, "Bad vendor")
|
| 1258 |
if get_vendor(vendor.id):
|
1305 |
if get_vendor(vendor.id):
|
| 1259 |
#vendor is already present.
|
1306 |
# vendor is already present.
|
| 1260 |
raise InventoryServiceException(101, "Vendor already present")
|
1307 |
raise InventoryServiceException(101, "Vendor already present")
|
| 1261 |
|
1308 |
|
| 1262 |
ds_vendor = Vendor()
|
1309 |
ds_vendor = Vendor()
|
| 1263 |
ds_vendor.id = vendor.id
|
1310 |
ds_vendor.id = vendor.id
|
| 1264 |
ds_vendor.name = vendor.name
|
1311 |
ds_vendor.name = vendor.name
|
| 1265 |
session.commit()
|
1312 |
session.commit()
|
| 1266 |
return ds_vendor.id
|
1313 |
return ds_vendor.id
|
| 1267 |
|
1314 |
|
| - |
|
1315 |
|
| 1268 |
def add_warehouse_vendor_mapping(warehouse_id, VendorId):
|
1316 |
def add_warehouse_vendor_mapping(warehouse_id, VendorId):
|
| 1269 |
return True
|
1317 |
return True
|
| 1270 |
|
1318 |
|
| - |
|
1319 |
|
| 1271 |
def mark_missed_inventory_updates_as_processed(itemKey, warehouseId):
|
1320 |
def mark_missed_inventory_updates_as_processed(itemKey, warehouseId):
|
| 1272 |
MissedInventoryUpdate.query.filter_by(itemKey = itemKey, warehouseId = warehouseId).delete()
|
1321 |
MissedInventoryUpdate.query.filter_by(itemKey=itemKey, warehouseId=warehouseId).delete()
|
| 1273 |
session.commit()
|
1322 |
session.commit()
|
| 1274 |
|
1323 |
|
| - |
|
1324 |
|
| 1275 |
def get_item_keys_to_be_processed(warehouseId):
|
1325 |
def get_item_keys_to_be_processed(warehouseId):
|
| 1276 |
return [i.itemKey for i in MissedInventoryUpdate.query.filter_by(warehouseId = warehouseId, isIgnored = 0)]
|
1326 |
return [i.itemKey for i in MissedInventoryUpdate.query.filter_by(warehouseId=warehouseId, isIgnored=0)]
|
| - |
|
1327 |
|
| 1277 |
|
1328 |
|
| 1278 |
def reset_availability(itemKey, vendorId, quantity, warehouseId):
|
1329 |
def reset_availability(itemKey, vendorId, quantity, warehouseId):
|
| 1279 |
vendorItemMapping = VendorItemMapping.get_by(vendor_id = vendorId, item_key = itemKey)
|
1330 |
vendorItemMapping = VendorItemMapping.get_by(vendor_id=vendorId, item_key=itemKey)
|
| 1280 |
if vendorItemMapping:
|
1331 |
if vendorItemMapping:
|
| 1281 |
itemId = vendorItemMapping.item_id
|
1332 |
itemId = vendorItemMapping.item_id
|
| 1282 |
|
1333 |
|
| 1283 |
if skippedItems.has_key(warehouseId) and itemId in skippedItems[warehouseId]:
|
1334 |
if skippedItems.has_key(warehouseId) and itemId in skippedItems[warehouseId]:
|
| 1284 |
quantity = 0
|
1335 |
quantity = 0
|
| 1285 |
|
1336 |
|
| 1286 |
currentInventorySnapshot = CurrentInventorySnapshot.get_by(item_id = itemId, warehouse_id = warehouseId)
|
1337 |
currentInventorySnapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| 1287 |
if currentInventorySnapshot:
|
1338 |
if currentInventorySnapshot:
|
| 1288 |
currentInventorySnapshot.availability = quantity
|
1339 |
currentInventorySnapshot.availability = quantity
|
| 1289 |
clear_item_availability_cache(itemId)
|
1340 |
clear_item_availability_cache(itemId)
|
| 1290 |
else:
|
1341 |
else:
|
| 1291 |
add_inventory(itemId, warehouseId, quantity)
|
1342 |
add_inventory(itemId, warehouseId, quantity)
|
| 1292 |
|
1343 |
|
| 1293 |
else:
|
1344 |
else:
|
| 1294 |
raise InventoryServiceException(101, 'VendorMapping not found for: ' + itemKey)
|
1345 |
raise InventoryServiceException(101, 'VendorMapping not found for: ' + itemKey)
|
| 1295 |
session.commit()
|
1346 |
session.commit()
|
| 1296 |
|
1347 |
|
| - |
|
1348 |
|
| 1297 |
def reset_availability_for_warehouse(warehouseId):
|
1349 |
def reset_availability_for_warehouse(warehouseId):
|
| 1298 |
itemIds = []
|
1350 |
itemIds = []
|
| 1299 |
for currentInventorySnapshot in CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouseId).all():
|
1351 |
for currentInventorySnapshot in CurrentInventorySnapshot.query.filter_by(warehouse_id=warehouseId).all():
|
| 1300 |
currentInventorySnapshot.availability = 0
|
1352 |
currentInventorySnapshot.availability = 0
|
| 1301 |
itemIds.append(currentInventorySnapshot.item_id)
|
1353 |
itemIds.append(currentInventorySnapshot.item_id)
|
| 1302 |
clear_item_availability_cache(itemIds)
|
1354 |
clear_item_availability_cache(itemIds)
|
| 1303 |
session.commit()
|
1355 |
session.commit()
|
| 1304 |
|
1356 |
|
| - |
|
1357 |
|
| 1305 |
def get_our_warehouse_id_for_vendor(vendor_id, billing_warehouse_id):
|
1358 |
def get_our_warehouse_id_for_vendor(vendor_id, billing_warehouse_id):
|
| 1306 |
try:
|
1359 |
try:
|
| 1307 |
warehouse = Warehouse.query.filter_by(vendor_id = vendor_id, warehouseType = 'OURS', inventoryType = 'GOOD', billingWarehouseId = billing_warehouse_id).first()
|
1360 |
warehouse = Warehouse.query.filter_by(vendor_id=vendor_id, warehouseType='OURS', inventoryType='GOOD', billingWarehouseId=billing_warehouse_id).first()
|
| 1308 |
return warehouse.id
|
1361 |
return warehouse.id
|
| 1309 |
except Exception as e:
|
1362 |
except Exception as e:
|
| 1310 |
print e;
|
1363 |
print e;
|
| 1311 |
raise InventoryServiceException(101, 'No our warehouse found for vendorId: ' + str(vendor_id))
|
1364 |
raise InventoryServiceException(101, 'No our warehouse found for vendorId: ' + str(vendor_id))
|
| - |
|
1365 |
|
| 1312 |
|
1366 |
|
| 1313 |
def __send_mail(subject, message):
|
1367 |
def __send_mail(subject, message):
|
| 1314 |
try:
|
1368 |
try:
|
| 1315 |
thread = threading.Thread(target=partial(mail, mail_user, mail_password, to_addresses, subject, message))
|
1369 |
thread = threading.Thread(target=partial(mail, mail_user, mail_password, to_addresses, subject, message))
|
| 1316 |
thread.start()
|
1370 |
thread.start()
|
| 1317 |
except Exception as ex:
|
1371 |
except Exception as ex:
|
| 1318 |
print ex
|
1372 |
print ex
|
| 1319 |
|
1373 |
|
| - |
|
1374 |
|
| 1320 |
def get_shipping_locations():
|
1375 |
def get_shipping_locations():
|
| 1321 |
shippingLocationIds = {}
|
1376 |
shippingLocationIds = {}
|
| 1322 |
warehouses = Warehouse.query.all()
|
1377 |
warehouses = Warehouse.query.all()
|
| 1323 |
for warehouse in warehouses:
|
1378 |
for warehouse in warehouses:
|
| 1324 |
if warehouse.shippingWarehouseId:
|
1379 |
if warehouse.shippingWarehouseId:
|
| Line 1328... |
Line 1383... |
| 1328 |
for shippingLocationId in shippingLocationIds:
|
1383 |
for shippingLocationId in shippingLocationIds:
|
| 1329 |
shippingLocations.append(get_Warehouse(shippingLocationId))
|
1384 |
shippingLocations.append(get_Warehouse(shippingLocationId))
|
| 1330 |
|
1385 |
|
| 1331 |
return shippingLocations
|
1386 |
return shippingLocations
|
| 1332 |
|
1387 |
|
| - |
|
1388 |
|
| 1333 |
def get_inventory_snapshot(warehouseId):
|
1389 |
def get_inventory_snapshot(warehouseId):
|
| 1334 |
query = CurrentInventorySnapshot.query
|
1390 |
query = CurrentInventorySnapshot.query
|
| 1335 |
|
1391 |
|
| 1336 |
if warehouseId:
|
1392 |
if warehouseId:
|
| 1337 |
query = query.filter_by(warehouse_id = warehouseId)
|
1393 |
query = query.filter_by(warehouse_id=warehouseId)
|
| 1338 |
|
1394 |
|
| 1339 |
itemInventoryMap = {}
|
1395 |
itemInventoryMap = {}
|
| 1340 |
for row in query.all():
|
1396 |
for row in query.all():
|
| 1341 |
if not itemInventoryMap.has_key(row.item_id):
|
1397 |
if not itemInventoryMap.has_key(row.item_id):
|
| 1342 |
itemInventoryMap[row.item_id] = []
|
1398 |
itemInventoryMap[row.item_id] = []
|
| 1343 |
|
1399 |
|
| 1344 |
itemInventoryMap[row.item_id].append(row)
|
1400 |
itemInventoryMap[row.item_id].append(row)
|
| 1345 |
|
1401 |
|
| 1346 |
return itemInventoryMap
|
1402 |
return itemInventoryMap
|
| 1347 |
|
1403 |
|
| - |
|
1404 |
|
| 1348 |
def update_vendor_string(warehouseId, vendorString):
|
1405 |
def update_vendor_string(warehouseId, vendorString):
|
| 1349 |
warehouse = get_Warehouse(warehouseId)
|
1406 |
warehouse = get_Warehouse(warehouseId)
|
| 1350 |
warehouse.vendorString = vendorString
|
1407 |
warehouse.vendorString = vendorString
|
| 1351 |
session.commit()
|
1408 |
session.commit()
|
| 1352 |
|
1409 |
|
| - |
|
1410 |
|
| 1353 |
def __get_item_from_master(item_id):
|
1411 |
def __get_item_from_master(item_id):
|
| 1354 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
1412 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 1355 |
return client.getItem(item_id)
|
1413 |
return client.getItem(item_id)
|
| 1356 |
|
1414 |
|
| - |
|
1415 |
|
| 1357 |
def __check_risky_item(item_id, source_id):
|
1416 |
def __check_risky_item(item_id, source_id):
|
| 1358 |
## We should get the list of strings which will identify to the catalog servers
|
1417 |
# # We should get the list of strings which will identify to the catalog servers
|
| 1359 |
if source_id == 1:
|
1418 |
if source_id == 1:
|
| 1360 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
1419 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 1361 |
client.validateRiskyStatus(item_id)
|
1420 |
client.validateRiskyStatus(item_id)
|
| 1362 |
if source_id == 2:
|
1421 |
if source_id == 2:
|
| 1363 |
client = CatalogClient("catalog_service_server_host_hotspot", "catalog_service_server_port").get_client()
|
1422 |
client = CatalogClient("catalog_service_server_host_hotspot", "catalog_service_server_port").get_client()
|
| 1364 |
client.validateRiskyStatus(item_id)
|
1423 |
client.validateRiskyStatus(item_id)
|
| 1365 |
|
1424 |
|
| - |
|
1425 |
|
| 1366 |
def __get_item_from_source(item_id, source_id):
|
1426 |
def __get_item_from_source(item_id, source_id):
|
| 1367 |
if source_id == 1:
|
1427 |
if source_id == 1:
|
| 1368 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
1428 |
client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 1369 |
return client.getItem(item_id)
|
1429 |
return client.getItem(item_id)
|
| 1370 |
if source_id == 2:
|
1430 |
if source_id == 2:
|
| 1371 |
client = CatalogClient("catalog_service_server_host_hotspot", "catalog_service_server_port").get_client()
|
1431 |
client = CatalogClient("catalog_service_server_host_hotspot", "catalog_service_server_port").get_client()
|
| 1372 |
return client.getItem(item_id)
|
1432 |
return client.getItem(item_id)
|
| 1373 |
|
1433 |
|
| - |
|
1434 |
|
| 1374 |
def get_monitored_warehouses_for_vendors(vendorIds):
|
1435 |
def get_monitored_warehouses_for_vendors(vendorIds):
|
| 1375 |
w = []
|
1436 |
w = []
|
| 1376 |
for wh in Warehouse.query.filter_by(isAvailabilityMonitored = 1).all():
|
1437 |
for wh in Warehouse.query.filter_by(isAvailabilityMonitored=1).all():
|
| 1377 |
if wh.vendor.id in (vendorIds):
|
1438 |
if wh.vendor.id in (vendorIds):
|
| 1378 |
w.append(to_t_warehouse(wh).id)
|
1439 |
w.append(to_t_warehouse(wh).id)
|
| 1379 |
return w
|
1440 |
return w
|
| - |
|
1441 |
|
| - |
|
1442 |
|
| 1380 |
def get_ignored_warehouseids_and_itemids():
|
1443 |
def get_ignored_warehouseids_and_itemids():
|
| 1381 |
iw = []
|
1444 |
iw = []
|
| 1382 |
for i in IgnoredInventoryUpdateItems.query.all():
|
1445 |
for i in IgnoredInventoryUpdateItems.query.all():
|
| 1383 |
iw.append(to_t_itemidwarehouseid(i))
|
1446 |
iw.append(to_t_itemidwarehouseid(i))
|
| 1384 |
return iw
|
1447 |
return iw
|
| - |
|
1448 |
|
| - |
|
1449 |
|
| 1385 |
def insert_item_to_ignore_inventory_update_list(item_id,warehouse_id):
|
1450 |
def insert_item_to_ignore_inventory_update_list(item_id, warehouse_id):
|
| 1386 |
try:
|
1451 |
try:
|
| 1387 |
ds_warehouse=IgnoredInventoryUpdateItems()
|
1452 |
ds_warehouse = IgnoredInventoryUpdateItems()
|
| 1388 |
ds_warehouse.item_id=item_id
|
1453 |
ds_warehouse.item_id = item_id
|
| 1389 |
ds_warehouse.warehouse_id=warehouse_id
|
1454 |
ds_warehouse.warehouse_id = warehouse_id
|
| 1390 |
clear_item_availability_cache(item_id)
|
1455 |
clear_item_availability_cache(item_id)
|
| 1391 |
session.commit()
|
1456 |
session.commit()
|
| 1392 |
return True
|
1457 |
return True
|
| 1393 |
except:
|
1458 |
except:
|
| 1394 |
return False
|
1459 |
return False
|
| - |
|
1460 |
|
| - |
|
1461 |
|
| 1395 |
def delete_item_from_ignore_inventory_update_list(item_id,warehouse_id):
|
1462 |
def delete_item_from_ignore_inventory_update_list(item_id, warehouse_id):
|
| 1396 |
try:
|
1463 |
try:
|
| 1397 |
session.query(IgnoredInventoryUpdateItems).filter_by(item_id=item_id,warehouse_id=warehouse_id).delete()
|
1464 |
session.query(IgnoredInventoryUpdateItems).filter_by(item_id=item_id, warehouse_id=warehouse_id).delete()
|
| 1398 |
clear_item_availability_cache(item_id)
|
1465 |
clear_item_availability_cache(item_id)
|
| 1399 |
session.commit()
|
1466 |
session.commit()
|
| 1400 |
return True
|
1467 |
return True
|
| 1401 |
except:
|
1468 |
except:
|
| 1402 |
return False
|
1469 |
return False
|
| - |
|
1470 |
|
| 1403 |
|
1471 |
|
| 1404 |
def get_all_ignored_inventoryupdate_items_count():
|
1472 |
def get_all_ignored_inventoryupdate_items_count():
|
| 1405 |
return session.query(func.count(distinct(IgnoredInventoryUpdateItems.item_id))).scalar()
|
1473 |
return session.query(func.count(distinct(IgnoredInventoryUpdateItems.item_id))).scalar()
|
| 1406 |
|
1474 |
|
| - |
|
1475 |
|
| 1407 |
def get_ignored_inventoryupdate_itemids(offset=0,limit=None):
|
1476 |
def get_ignored_inventoryupdate_itemids(offset=0, limit=None):
|
| 1408 |
itemIds = session.query(distinct(IgnoredInventoryUpdateItems.item_id))
|
1477 |
itemIds = session.query(distinct(IgnoredInventoryUpdateItems.item_id))
|
| 1409 |
'''if limit is not None:
|
1478 |
'''if limit is not None:
|
| 1410 |
itemIds = itemIds.limit(limit)'''
|
1479 |
itemIds = itemIds.limit(limit)'''
|
| 1411 |
print itemIds.all()
|
1480 |
print itemIds.all()
|
| 1412 |
return [id for (id, ) in itemIds.all()]
|
1481 |
return [id for (id,) in itemIds.all()]
|
| - |
|
1482 |
|
| 1413 |
|
1483 |
|
| 1414 |
def update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel):
|
1484 |
def update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel):
|
| 1415 |
if numOfDaysStock is None or minStockLevel is None:
|
1485 |
if numOfDaysStock is None or minStockLevel is None:
|
| 1416 |
raise InventoryServiceException(108, "Bad params : numOfDaysStock = " + str(numOfDaysStock) + "minStockLevel = " + str(minStockLevel))
|
1486 |
raise InventoryServiceException(108, "Bad params : numOfDaysStock = " + str(numOfDaysStock) + "minStockLevel = " + str(minStockLevel))
|
| 1417 |
itemStockPurchaseParams = ItemStockPurchaseParams.query.filter_by(item_id = item_id).first()
|
1487 |
itemStockPurchaseParams = ItemStockPurchaseParams.query.filter_by(item_id=item_id).first()
|
| 1418 |
if itemStockPurchaseParams is None:
|
1488 |
if itemStockPurchaseParams is None:
|
| 1419 |
itemStockPurchaseParams = ItemStockPurchaseParams()
|
1489 |
itemStockPurchaseParams = ItemStockPurchaseParams()
|
| 1420 |
itemStockPurchaseParams.item_id = item_id
|
1490 |
itemStockPurchaseParams.item_id = item_id
|
| 1421 |
itemStockPurchaseParams.numOfDaysStock = numOfDaysStock
|
1491 |
itemStockPurchaseParams.numOfDaysStock = numOfDaysStock
|
| 1422 |
itemStockPurchaseParams.minStockLevel = minStockLevel
|
1492 |
itemStockPurchaseParams.minStockLevel = minStockLevel
|
| 1423 |
session.commit()
|
1493 |
session.commit()
|
| 1424 |
|
1494 |
|
| - |
|
1495 |
|
| 1425 |
def get_item_stock_purchase_params(item_id):
|
1496 |
def get_item_stock_purchase_params(item_id):
|
| 1426 |
return ItemStockPurchaseParams.query.filter_by(item_id = item_id).first()
|
1497 |
return ItemStockPurchaseParams.query.filter_by(item_id=item_id).first()
|
| - |
|
1498 |
|
| 1427 |
|
1499 |
|
| 1428 |
def add_oos_status_for_item(oosStatusMap, date):
|
1500 |
def add_oos_status_for_item(oosStatusMap, date):
|
| 1429 |
|
1501 |
|
| 1430 |
oosDate = to_py_date(date)
|
1502 |
oosDate = to_py_date(date)
|
| 1431 |
oosDate.replace(second=0, microsecond=0)
|
1503 |
oosDate.replace(second=0, microsecond=0)
|
| 1432 |
|
1504 |
|
| 1433 |
cartAdditionStartDate = oosDate - datetime.timedelta(days = 1)
|
1505 |
cartAdditionStartDate = oosDate - datetime.timedelta(days=1)
|
| 1434 |
|
1506 |
|
| 1435 |
client = TransactionClient().get_client()
|
1507 |
client = TransactionClient().get_client()
|
| 1436 |
|
1508 |
|
| 1437 |
#Gets physical orders in the last day
|
1509 |
# Gets physical orders in the last day
|
| 1438 |
orders = client.getPhysicalOrders(to_java_date(cartAdditionStartDate), to_java_date(oosDate))
|
1510 |
orders = client.getPhysicalOrders(to_java_date(cartAdditionStartDate), to_java_date(oosDate))
|
| 1439 |
rtoOrders = client.getAllOrders([20], 0, 0, 0)
|
1511 |
rtoOrders = client.getAllOrders([20], 0, 0, 0)
|
| 1440 |
orderCountByItemIdSourceId = {}
|
1512 |
orderCountByItemIdSourceId = {}
|
| 1441 |
rtoOrderCountByItemIdSourceId = {}
|
1513 |
rtoOrderCountByItemIdSourceId = {}
|
| 1442 |
|
1514 |
|
| Line 1446... |
Line 1518... |
| 1446 |
|
1518 |
|
| 1447 |
if orderCountByItemIdSourceId[order.lineitems[0].item_id].has_key(order.source):
|
1519 |
if orderCountByItemIdSourceId[order.lineitems[0].item_id].has_key(order.source):
|
| 1448 |
orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] + order.lineitems[0].quantity
|
1520 |
orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] + order.lineitems[0].quantity
|
| 1449 |
else:
|
1521 |
else:
|
| 1450 |
orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = order.lineitems[0].quantity
|
1522 |
orderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = order.lineitems[0].quantity
|
| 1451 |
|
- |
|
| 1452 |
|
1523 |
|
| 1453 |
for order in rtoOrders:
|
1524 |
for order in rtoOrders:
|
| 1454 |
if not rtoOrderCountByItemIdSourceId.has_key(order.lineitems[0].item_id):
|
1525 |
if not rtoOrderCountByItemIdSourceId.has_key(order.lineitems[0].item_id):
|
| 1455 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id] = {}
|
1526 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id] = {}
|
| 1456 |
|
1527 |
|
| 1457 |
if rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id].has_key(order.source):
|
1528 |
if rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id].has_key(order.source):
|
| 1458 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] + order.lineitems[0].quantity
|
1529 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] + order.lineitems[0].quantity
|
| 1459 |
else:
|
1530 |
else:
|
| 1460 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = order.lineitems[0].quantity
|
1531 |
rtoOrderCountByItemIdSourceId[order.lineitems[0].item_id][order.source] = order.lineitems[0].quantity
|
| 1461 |
|
1532 |
|
| 1462 |
|
- |
|
| 1463 |
for itemId, status in oosStatusMap.iteritems():
|
1533 |
for itemId, status in oosStatusMap.iteritems():
|
| 1464 |
total_order_count = 0
|
1534 |
total_order_count = 0
|
| 1465 |
total_rto_count = 0
|
1535 |
total_rto_count = 0
|
| 1466 |
for sid in (1,3,4,6,7,8):
|
1536 |
for sid in (1, 3, 4, 6, 7, 8):
|
| 1467 |
oosStatus = OOSStatus()
|
1537 |
oosStatus = OOSStatus()
|
| 1468 |
oosStatus.item_id = itemId
|
1538 |
oosStatus.item_id = itemId
|
| 1469 |
oosStatus.date = oosDate
|
1539 |
oosStatus.date = oosDate
|
| 1470 |
oosStatus.sourceId = sid
|
1540 |
oosStatus.sourceId = sid
|
| 1471 |
order_count = 0
|
1541 |
order_count = 0
|
| 1472 |
rto_count = 0
|
1542 |
rto_count = 0
|
| 1473 |
if orderCountByItemIdSourceId.has_key(itemId) and orderCountByItemIdSourceId[itemId].has_key(sid):
|
1543 |
if orderCountByItemIdSourceId.has_key(itemId) and orderCountByItemIdSourceId[itemId].has_key(sid):
|
| 1474 |
order_count = orderCountByItemIdSourceId[itemId][sid]
|
1544 |
order_count = orderCountByItemIdSourceId[itemId][sid]
|
| 1475 |
if rtoOrderCountByItemIdSourceId.has_key(itemId) and rtoOrderCountByItemIdSourceId[itemId].has_key(sid):
|
1545 |
if rtoOrderCountByItemIdSourceId.has_key(itemId) and rtoOrderCountByItemIdSourceId[itemId].has_key(sid):
|
| Line 1482... |
Line 1552... |
| 1482 |
total_order_count = total_order_count + order_count
|
1552 |
total_order_count = total_order_count + order_count
|
| 1483 |
total_rto_count = total_rto_count + rto_count
|
1553 |
total_rto_count = total_rto_count + rto_count
|
| 1484 |
oosStatus = OOSStatus()
|
1554 |
oosStatus = OOSStatus()
|
| 1485 |
oosStatus.item_id = itemId
|
1555 |
oosStatus.item_id = itemId
|
| 1486 |
oosStatus.date = oosDate
|
1556 |
oosStatus.date = oosDate
|
| 1487 |
oosStatus.sourceId = 0
|
1557 |
oosStatus.sourceId = 0
|
| 1488 |
oosStatus.num_orders = total_order_count
|
1558 |
oosStatus.num_orders = total_order_count
|
| 1489 |
oosStatus.rto_orders = total_rto_count
|
1559 |
oosStatus.rto_orders = total_rto_count
|
| 1490 |
if itemId in orderCountByItemIdSourceId and 1 in orderCountByItemIdSourceId[itemId]:
|
1560 |
if itemId in orderCountByItemIdSourceId and 1 in orderCountByItemIdSourceId[itemId]:
|
| 1491 |
order_count = orderCountByItemIdSourceId[itemId][1]
|
1561 |
order_count = orderCountByItemIdSourceId[itemId][1]
|
| 1492 |
oosStatus.is_oos = status
|
1562 |
oosStatus.is_oos = status
|
| 1493 |
if oosStatus.is_oos and order_count > 0:
|
1563 |
if oosStatus.is_oos and order_count > 0:
|
| 1494 |
oosStatus.is_oos = False
|
1564 |
oosStatus.is_oos = False
|
| 1495 |
|
1565 |
|
| 1496 |
session.commit()
|
1566 |
session.commit()
|
| 1497 |
|
1567 |
|
| 1498 |
|
- |
|
| 1499 |
itemCountMap = {}
|
1568 |
itemCountMap = {}
|
| 1500 |
oosDate = oosDate - datetime.timedelta(days = 1) - datetime.timedelta(hours = 1)
|
1569 |
oosDate = oosDate - datetime.timedelta(days=1) - datetime.timedelta(hours=1)
|
| 1501 |
lines = session.query(OOSStatus.item_id, func.sum(OOSStatus.num_orders)/func.count(OOSStatus.num_orders)).filter(OOSStatus.date >= oosDate).filter(OOSStatus.sourceId == 1).filter(OOSStatus.is_oos == 0).group_by(OOSStatus.item_id).all()
|
1570 |
lines = session.query(OOSStatus.item_id, func.sum(OOSStatus.num_orders) / func.count(OOSStatus.num_orders)).filter(OOSStatus.date >= oosDate).filter(OOSStatus.sourceId == 1).filter(OOSStatus.is_oos == 0).group_by(OOSStatus.item_id).all()
|
| 1502 |
for line in lines:
|
1571 |
for line in lines:
|
| 1503 |
item_id = line[0]
|
1572 |
item_id = line[0]
|
| 1504 |
quantity = int(math.ceil(max(1,2*line[1])))
|
1573 |
quantity = int(math.ceil(max(1, 2 * line[1])))
|
| 1505 |
itemCountMap[item_id] = quantity
|
1574 |
itemCountMap[item_id] = quantity
|
| 1506 |
cl = CatalogClient('catalog_service_server_host_prod','catalog_service_server_port').get_client()
|
1575 |
cl = CatalogClient('catalog_service_server_host_prod', 'catalog_service_server_port').get_client()
|
| 1507 |
cl.updateItemHoldInventory(itemCountMap)
|
1576 |
cl.updateItemHoldInventory(itemCountMap)
|
| - |
|
1577 |
|
| 1508 |
|
1578 |
|
| 1509 |
def get_oos_statuses_for_x_days_for_item(itemId, sourceId, days):
|
1579 |
def get_oos_statuses_for_x_days_for_item(itemId, sourceId, days):
|
| 1510 |
timestamp = datetime.datetime.now()
|
1580 |
timestamp = datetime.datetime.now()
|
| 1511 |
timestamp = timestamp - datetime.timedelta(days = days)
|
1581 |
timestamp = timestamp - datetime.timedelta(days=days)
|
| 1512 |
return OOSStatus.query.filter_by(item_id = itemId).filter_by(sourceId = sourceId).filter(OOSStatus.date > timestamp).all()
|
1582 |
return OOSStatus.query.filter_by(item_id=itemId).filter_by(sourceId=sourceId).filter(OOSStatus.date > timestamp).all()
|
| - |
|
1583 |
|
| 1513 |
|
1584 |
|
| 1514 |
def get_oos_statuses_for_x_days(sourceId, days):
|
1585 |
def get_oos_statuses_for_x_days(sourceId, days):
|
| 1515 |
timestamp = datetime.datetime.now()
|
1586 |
timestamp = datetime.datetime.now()
|
| 1516 |
timestamp = timestamp - datetime.timedelta(days = days)
|
1587 |
timestamp = timestamp - datetime.timedelta(days=days)
|
| 1517 |
if sourceId == -1:
|
1588 |
if sourceId == -1:
|
| 1518 |
return OOSStatus.query.filter(OOSStatus.date > timestamp).all()
|
1589 |
return OOSStatus.query.filter(OOSStatus.date > timestamp).all()
|
| 1519 |
else:
|
1590 |
else:
|
| 1520 |
return OOSStatus.query.filter_by(sourceId = sourceId).filter(OOSStatus.date > timestamp).all()
|
1591 |
return OOSStatus.query.filter_by(sourceId=sourceId).filter(OOSStatus.date > timestamp).all()
|
| - |
|
1592 |
|
| 1521 |
|
1593 |
|
| 1522 |
def get_non_zero_item_stock_purchase_params():
|
1594 |
def get_non_zero_item_stock_purchase_params():
|
| 1523 |
return ItemStockPurchaseParams.query.filter(or_("numOfDaysStock!=0","minStockLevel!=0"))
|
1595 |
return ItemStockPurchaseParams.query.filter(or_("numOfDaysStock!=0", "minStockLevel!=0"))
|
| - |
|
1596 |
|
| 1524 |
|
1597 |
|
| 1525 |
def get_last_n_day_sale_for_item(itemId, numberOfDays):
|
1598 |
def get_last_n_day_sale_for_item(itemId, numberOfDays):
|
| 1526 |
lastNdaySale = ""
|
1599 |
lastNdaySale = ""
|
| 1527 |
oosStatuses = get_oos_statuses_for_x_days_for_item(itemId, 0, numberOfDays)
|
1600 |
oosStatuses = get_oos_statuses_for_x_days_for_item(itemId, 0, numberOfDays)
|
| 1528 |
for oosStatus in oosStatuses:
|
1601 |
for oosStatus in oosStatuses:
|
| 1529 |
if oosStatus.is_oos == True:
|
1602 |
if oosStatus.is_oos == True:
|
| 1530 |
lastNdaySale +="X-"
|
1603 |
lastNdaySale += "X-"
|
| 1531 |
else:
|
1604 |
else:
|
| 1532 |
lastNdaySale +=str(oosStatus.num_orders) + "-"
|
1605 |
lastNdaySale += str(oosStatus.num_orders) + "-"
|
| 1533 |
return lastNdaySale[:-1]
|
1606 |
return lastNdaySale[:-1]
|
| 1534 |
|
1607 |
|
| - |
|
1608 |
|
| 1535 |
def get_warehouse_name(warehouseId):
|
1609 |
def get_warehouse_name(warehouseId):
|
| 1536 |
row = Warehouse.get_by(id = warehouseId)
|
1610 |
row = Warehouse.get_by(id=warehouseId)
|
| 1537 |
return row.displayName
|
1611 |
return row.displayName
|
| 1538 |
|
1612 |
|
| - |
|
1613 |
|
| 1539 |
def get_amazon_inventory_for_item(amazonItemId):
|
1614 |
def get_amazon_inventory_for_item(amazonItemId):
|
| 1540 |
inventory = AmazonInventorySnapshot.get_by(item_id=amazonItemId)
|
1615 |
inventory = AmazonInventorySnapshot.get_by(item_id=amazonItemId)
|
| 1541 |
return inventory
|
1616 |
return inventory
|
| 1542 |
|
1617 |
|
| - |
|
1618 |
|
| 1543 |
def get_all_amazon_inventory():
|
1619 |
def get_all_amazon_inventory():
|
| 1544 |
return session.query(AmazonInventorySnapshot).all()
|
1620 |
return session.query(AmazonInventorySnapshot).all()
|
| 1545 |
|
1621 |
|
| - |
|
1622 |
|
| 1546 |
def add_or_update_amazon_inventory_for_item(amazoninventorysnapshot,time):
|
1623 |
def add_or_update_amazon_inventory_for_item(amazoninventorysnapshot, time):
|
| 1547 |
inventory = AmazonInventorySnapshot.get_by(item_id = amazoninventorysnapshot.item_id)
|
1624 |
inventory = AmazonInventorySnapshot.get_by(item_id=amazoninventorysnapshot.item_id)
|
| 1548 |
if inventory is None:
|
1625 |
if inventory is None:
|
| 1549 |
amazon_inventory = AmazonInventorySnapshot()
|
1626 |
amazon_inventory = AmazonInventorySnapshot()
|
| 1550 |
amazon_inventory.item_id = amazoninventorysnapshot.item_id
|
1627 |
amazon_inventory.item_id = amazoninventorysnapshot.item_id
|
| 1551 |
amazon_inventory.availability = amazoninventorysnapshot.availability
|
1628 |
amazon_inventory.availability = amazoninventorysnapshot.availability
|
| 1552 |
amazon_inventory.reserved = amazoninventorysnapshot.reserved
|
1629 |
amazon_inventory.reserved = amazoninventorysnapshot.reserved
|
| Line 1558... |
Line 1635... |
| 1558 |
inventory.reserved = amazoninventorysnapshot.reserved
|
1635 |
inventory.reserved = amazoninventorysnapshot.reserved
|
| 1559 |
if not inventory.is_oos and (to_py_date(time) - inventory.lastUpdatedOnAmazon).days == 0:
|
1636 |
if not inventory.is_oos and (to_py_date(time) - inventory.lastUpdatedOnAmazon).days == 0:
|
| 1560 |
pass
|
1637 |
pass
|
| 1561 |
else:
|
1638 |
else:
|
| 1562 |
inventory.is_oos = amazoninventorysnapshot.is_oos
|
1639 |
inventory.is_oos = amazoninventorysnapshot.is_oos
|
| 1563 |
if time != 0:
|
1640 |
if time != 0:
|
| 1564 |
inventory.lastUpdatedOnAmazon = to_py_date(time)
|
1641 |
inventory.lastUpdatedOnAmazon = to_py_date(time)
|
| 1565 |
session.commit()
|
1642 |
session.commit()
|
| - |
|
1643 |
|
| 1566 |
|
1644 |
|
| 1567 |
def add_update_hold_inventory(itemId, warehouseId, holdQuantity, source):
|
1645 |
def add_update_hold_inventory(itemId, warehouseId, holdQuantity, source):
|
| 1568 |
if holdQuantity <0:
|
1646 |
if holdQuantity < 0:
|
| 1569 |
print "Negative holdQuantity : " + str(holdQuantity) + " is not allowed"
|
1647 |
print "Negative holdQuantity : " + str(holdQuantity) + " is not allowed"
|
| 1570 |
raise InventoryServiceException(108, "Negative heldQuantity is not allowed")
|
1648 |
raise InventoryServiceException(108, "Negative heldQuantity is not allowed")
|
| 1571 |
hold_inventory_detail = HoldInventoryDetail.get_by(item_id = itemId, warehouse_id=warehouseId, source = source)
|
1649 |
hold_inventory_detail = HoldInventoryDetail.get_by(item_id=itemId, warehouse_id=warehouseId, source=source)
|
| 1572 |
if hold_inventory_detail is None:
|
1650 |
if hold_inventory_detail is None:
|
| 1573 |
diffTobeAddedInCIS = holdQuantity
|
1651 |
diffTobeAddedInCIS = holdQuantity
|
| 1574 |
hold_inventory_detail = HoldInventoryDetail()
|
1652 |
hold_inventory_detail = HoldInventoryDetail()
|
| 1575 |
hold_inventory_detail.item_id = itemId
|
1653 |
hold_inventory_detail.item_id = itemId
|
| 1576 |
hold_inventory_detail.warehouse_id = warehouseId
|
1654 |
hold_inventory_detail.warehouse_id = warehouseId
|
| Line 1588... |
Line 1666... |
| 1588 |
current_inventory_snapshot.availability = 0
|
1666 |
current_inventory_snapshot.availability = 0
|
| 1589 |
current_inventory_snapshot.reserved = 0
|
1667 |
current_inventory_snapshot.reserved = 0
|
| 1590 |
current_inventory_snapshot.held = 0
|
1668 |
current_inventory_snapshot.held = 0
|
| 1591 |
current_inventory_snapshot.held = current_inventory_snapshot.held + diffTobeAddedInCIS
|
1669 |
current_inventory_snapshot.held = current_inventory_snapshot.held + diffTobeAddedInCIS
|
| 1592 |
session.commit()
|
1670 |
session.commit()
|
| 1593 |
#**Update item availability cache**#
|
1671 |
# **Update item availability cache**#
|
| 1594 |
clear_item_availability_cache(itemId)
|
1672 |
clear_item_availability_cache(itemId)
|
| - |
|
1673 |
|
| 1595 |
|
1674 |
|
| 1596 |
def add_or_update_amazon_fba_inventory(amazonfbainventorysnapshot):
|
1675 |
def add_or_update_amazon_fba_inventory(amazonfbainventorysnapshot):
|
| 1597 |
inventory = AmazonFbaInventorySnapshot.query.filter_by(item_id = amazonfbainventorysnapshot.item_id,location=amazonfbainventorysnapshot.location).first()
|
1676 |
inventory = AmazonFbaInventorySnapshot.query.filter_by(item_id=amazonfbainventorysnapshot.item_id, location=amazonfbainventorysnapshot.location).first()
|
| 1598 |
if inventory is None:
|
1677 |
if inventory is None:
|
| 1599 |
amazon_fba_inventory = AmazonFbaInventorySnapshot()
|
1678 |
amazon_fba_inventory = AmazonFbaInventorySnapshot()
|
| 1600 |
amazon_fba_inventory.item_id = amazonfbainventorysnapshot.item_id
|
1679 |
amazon_fba_inventory.item_id = amazonfbainventorysnapshot.item_id
|
| 1601 |
amazon_fba_inventory.availability = amazonfbainventorysnapshot.availability
|
1680 |
amazon_fba_inventory.availability = amazonfbainventorysnapshot.availability
|
| 1602 |
amazon_fba_inventory.location = amazonfbainventorysnapshot.location
|
1681 |
amazon_fba_inventory.location = amazonfbainventorysnapshot.location
|
| Line 1612... |
Line 1691... |
| 1612 |
inventory.inbound = amazonfbainventorysnapshot.inbound
|
1691 |
inventory.inbound = amazonfbainventorysnapshot.inbound
|
| 1613 |
inventory.unfulfillable = amazonfbainventorysnapshot.unfulfillable
|
1692 |
inventory.unfulfillable = amazonfbainventorysnapshot.unfulfillable
|
| 1614 |
|
1693 |
|
| 1615 |
|
1694 |
|
| 1616 |
def get_amazon_fba_inventory(itemId):
|
1695 |
def get_amazon_fba_inventory(itemId):
|
| 1617 |
return AmazonFbaInventorySnapshot.query.filter_by(item_id = itemId)
|
1696 |
return AmazonFbaInventorySnapshot.query.filter_by(item_id=itemId)
|
| - |
|
1697 |
|
| 1618 |
|
1698 |
|
| 1619 |
def get_all_amazon_fba_inventory():
|
1699 |
def get_all_amazon_fba_inventory():
|
| 1620 |
return AmazonFbaInventorySnapshot.query.all()
|
1700 |
return AmazonFbaInventorySnapshot.query.all()
|
| 1621 |
|
1701 |
|
| - |
|
1702 |
|
| 1622 |
def get_oursgood_warehouseids_for_location(stateId):
|
1703 |
def get_oursgood_warehouseids_for_location(stateId):
|
| 1623 |
warehouseId=[]
|
1704 |
warehouseId = []
|
| 1624 |
x= session.query(Warehouse.id).filter(Warehouse.id==Warehouse.billingWarehouseId).filter(Warehouse.warehouseType=='OURS').filter(Warehouse.state_id==stateId).all()
|
1705 |
x = session.query(Warehouse.id).filter(Warehouse.id == Warehouse.billingWarehouseId).filter(Warehouse.warehouseType == 'OURS').filter(Warehouse.state_id == stateId).all()
|
| 1625 |
for id in x:
|
1706 |
for id in x:
|
| 1626 |
warehouseId.append(id[0])
|
1707 |
warehouseId.append(id[0])
|
| 1627 |
return session.query(Warehouse.id).filter(Warehouse.inventoryType=='GOOD').filter(Warehouse.warehouseType=='OURS').filter(Warehouse.billingWarehouseId.in_(warehouseId)).all()
|
1708 |
return session.query(Warehouse.id).filter(Warehouse.inventoryType == 'GOOD').filter(Warehouse.warehouseType == 'OURS').filter(Warehouse.billingWarehouseId.in_(warehouseId)).all()
|
| 1628 |
|
1709 |
|
| - |
|
1710 |
|
| 1629 |
def get_holdinventorydetail_forItem_forWarehouseId_exceptsource(item_id,warehouse_id,source):
|
1711 |
def get_holdinventorydetail_forItem_forWarehouseId_exceptsource(item_id, warehouse_id, source):
|
| 1630 |
holddetails = HoldInventoryDetail.query.filter(HoldInventoryDetail.item_id == item_id).all()
|
1712 |
holddetails = HoldInventoryDetail.query.filter(HoldInventoryDetail.item_id == item_id).all()
|
| 1631 |
print holddetails
|
1713 |
print holddetails
|
| 1632 |
hold = 0
|
1714 |
hold = 0
|
| 1633 |
for holddetail in holddetails:
|
1715 |
for holddetail in holddetails:
|
| 1634 |
if holddetail.source !=source and holddetail.warehouse_id == warehouse_id:
|
1716 |
if holddetail.source != source and holddetail.warehouse_id == warehouse_id:
|
| 1635 |
hold = hold + holddetail.held
|
1717 |
hold = hold + holddetail.held
|
| 1636 |
return hold
|
1718 |
return hold
|
| 1637 |
|
1719 |
|
| - |
|
1720 |
|
| 1638 |
def get_snapdeal_inventory_for_item(id):
|
1721 |
def get_snapdeal_inventory_for_item(id):
|
| 1639 |
print SnapdealInventorySnapshot.get_by(item_id = id)
|
1722 |
print SnapdealInventorySnapshot.get_by(item_id=id)
|
| 1640 |
return SnapdealInventorySnapshot.get_by(item_id = id)
|
1723 |
return SnapdealInventorySnapshot.get_by(item_id=id)
|
| - |
|
1724 |
|
| 1641 |
|
1725 |
|
| 1642 |
def add_or_update_snapdeal_inventor_for_item(snapdealinventoryitem):
|
1726 |
def add_or_update_snapdeal_inventor_for_item(snapdealinventoryitem):
|
| 1643 |
snapdeal_inventory_item = SnapdealInventorySnapshot.get_by(item_id = snapdealinventoryitem.item_id)
|
1727 |
snapdeal_inventory_item = SnapdealInventorySnapshot.get_by(item_id=snapdealinventoryitem.item_id)
|
| 1644 |
if snapdeal_inventory_item is None:
|
1728 |
if snapdeal_inventory_item is None:
|
| 1645 |
snapdeal_inventory_item = SnapdealInventorySnapshot()
|
1729 |
snapdeal_inventory_item = SnapdealInventorySnapshot()
|
| 1646 |
snapdeal_inventory_item.item_id = snapdealinventoryitem.item_id
|
1730 |
snapdeal_inventory_item.item_id = snapdealinventoryitem.item_id
|
| 1647 |
snapdeal_inventory_item.availability = snapdealinventoryitem.availability
|
1731 |
snapdeal_inventory_item.availability = snapdealinventoryitem.availability
|
| 1648 |
snapdeal_inventory_item.pendingOrders = snapdealinventoryitem.pendingOrders
|
1732 |
snapdeal_inventory_item.pendingOrders = snapdealinventoryitem.pendingOrders
|
| Line 1655... |
Line 1739... |
| 1655 |
pass
|
1739 |
pass
|
| 1656 |
else:
|
1740 |
else:
|
| 1657 |
snapdeal_inventory_item.is_oos = snapdealinventoryitem.is_oos
|
1741 |
snapdeal_inventory_item.is_oos = snapdealinventoryitem.is_oos
|
| 1658 |
snapdeal_inventory_item.lastUpdatedOnSnapdeal = to_py_date(snapdealinventoryitem.lastUpdatedOnSnapdeal)
|
1742 |
snapdeal_inventory_item.lastUpdatedOnSnapdeal = to_py_date(snapdealinventoryitem.lastUpdatedOnSnapdeal)
|
| 1659 |
session.commit()
|
1743 |
session.commit()
|
| - |
|
1744 |
|
| 1660 |
|
1745 |
|
| 1661 |
def get_nlc_for_warehouse(warehouse_id,itemid):
|
1746 |
def get_nlc_for_warehouse(warehouse_id, itemid):
|
| 1662 |
warehouse = Warehouse.get_by(id=warehouse_id)
|
1747 |
warehouse = Warehouse.get_by(id=warehouse_id)
|
| 1663 |
if warehouse is None:
|
1748 |
if warehouse is None:
|
| 1664 |
return 0
|
1749 |
return 0
|
| 1665 |
vendoritempricing = VendorItemPricing.query.filter_by(item_id=itemid, vendor_id=warehouse.vendor_id).first()
|
1750 |
vendoritempricing = VendorItemPricing.query.filter_by(item_id=itemid, vendor_id=warehouse.vendor_id).first()
|
| 1666 |
'''vendoritempricing = VendorItemPricing.get_by(id=warehouse.vendor_id,item_id=itemid)'''
|
1751 |
'''vendoritempricing = VendorItemPricing.get_by(id=warehouse.vendor_id,item_id=itemid)'''
|
| 1667 |
if vendoritempricing is None:
|
1752 |
if vendoritempricing is None:
|
| 1668 |
return 0
|
1753 |
return 0
|
| 1669 |
return vendoritempricing.nlc
|
1754 |
return vendoritempricing.nlc
|
| 1670 |
|
1755 |
|
| - |
|
1756 |
|
| 1671 |
def get_snapdeal_inventory_snapshot():
|
1757 |
def get_snapdeal_inventory_snapshot():
|
| 1672 |
return SnapdealInventorySnapshot.query.all()
|
1758 |
return SnapdealInventorySnapshot.query.all()
|
| 1673 |
|
1759 |
|
| - |
|
1760 |
|
| 1674 |
def get_held_inventory_map_for_item(itemId, warehouseId):
|
1761 |
def get_held_inventory_map_for_item(itemId, warehouseId):
|
| 1675 |
heldInventoryMap = {}
|
1762 |
heldInventoryMap = {}
|
| 1676 |
holdInventories = HoldInventoryDetail.query.filter_by(item_id= itemId, warehouse_id = warehouseId).all()
|
1763 |
holdInventories = HoldInventoryDetail.query.filter_by(item_id=itemId, warehouse_id=warehouseId).all()
|
| 1677 |
for holdInventory in holdInventories:
|
1764 |
for holdInventory in holdInventories:
|
| 1678 |
heldInventoryMap[holdInventory.source] = holdInventory.held
|
1765 |
heldInventoryMap[holdInventory.source] = holdInventory.held
|
| 1679 |
return heldInventoryMap
|
1766 |
return heldInventoryMap
|
| 1680 |
|
1767 |
|
| - |
|
1768 |
|
| 1681 |
def get_hold_inventory_details(itemId, warehouseId, source):
|
1769 |
def get_hold_inventory_details(itemId, warehouseId, source):
|
| 1682 |
heldInventoryQuery = HoldInventoryDetail.query
|
1770 |
heldInventoryQuery = HoldInventoryDetail.query
|
| 1683 |
if itemId:
|
1771 |
if itemId:
|
| 1684 |
heldInventoryQuery = heldInventoryQuery.filter_by(item_id = itemId)
|
1772 |
heldInventoryQuery = heldInventoryQuery.filter_by(item_id=itemId)
|
| 1685 |
if warehouseId:
|
1773 |
if warehouseId:
|
| 1686 |
heldInventoryQuery = heldInventoryQuery.filter_by(warehouse_id = warehouseId)
|
1774 |
heldInventoryQuery = heldInventoryQuery.filter_by(warehouse_id=warehouseId)
|
| 1687 |
if source:
|
1775 |
if source:
|
| 1688 |
heldInventoryQuery = heldInventoryQuery.filter_by(source = source)
|
1776 |
heldInventoryQuery = heldInventoryQuery.filter_by(source=source)
|
| 1689 |
holdInventoryDetails = heldInventoryQuery.all()
|
1777 |
holdInventoryDetails = heldInventoryQuery.all()
|
| 1690 |
return holdInventoryDetails
|
1778 |
return holdInventoryDetails
|
| - |
|
1779 |
|
| 1691 |
|
1780 |
|
| 1692 |
def add_or_update_flipkart_inventory_snapshot(flipkartInventorySnapshot,time):
|
1781 |
def add_or_update_flipkart_inventory_snapshot(flipkartInventorySnapshot, time):
|
| 1693 |
for snapshot in flipkartInventorySnapshot:
|
1782 |
for snapshot in flipkartInventorySnapshot:
|
| 1694 |
flipkart_inventory = FlipkartInventorySnapshot.get_by(item_id = snapshot.item_id)
|
1783 |
flipkart_inventory = FlipkartInventorySnapshot.get_by(item_id=snapshot.item_id)
|
| 1695 |
if flipkart_inventory is None:
|
1784 |
if flipkart_inventory is None:
|
| 1696 |
flipkart_inventory = FlipkartInventorySnapshot()
|
1785 |
flipkart_inventory = FlipkartInventorySnapshot()
|
| 1697 |
flipkart_inventory.item_id = snapshot.item_id
|
1786 |
flipkart_inventory.item_id = snapshot.item_id
|
| 1698 |
flipkart_inventory.availability = snapshot.availability
|
1787 |
flipkart_inventory.availability = snapshot.availability
|
| 1699 |
flipkart_inventory.createdOrders = snapshot.createdOrders
|
1788 |
flipkart_inventory.createdOrders = snapshot.createdOrders
|
| Line 1708... |
Line 1797... |
| 1708 |
pass
|
1797 |
pass
|
| 1709 |
else:
|
1798 |
else:
|
| 1710 |
flipkart_inventory.is_oos = snapshot.is_oos
|
1799 |
flipkart_inventory.is_oos = snapshot.is_oos
|
| 1711 |
flipkart_inventory.lastUpdatedOnFlipkart = to_py_date(time)
|
1800 |
flipkart_inventory.lastUpdatedOnFlipkart = to_py_date(time)
|
| 1712 |
session.commit()
|
1801 |
session.commit()
|
| - |
|
1802 |
|
| 1713 |
|
1803 |
|
| 1714 |
def get_flipkart_inventory_snapshot():
|
1804 |
def get_flipkart_inventory_snapshot():
|
| 1715 |
return FlipkartInventorySnapshot.query.all()
|
1805 |
return FlipkartInventorySnapshot.query.all()
|
| - |
|
1806 |
|
| 1716 |
|
1807 |
|
| 1717 |
def get_flipkart_inventory_for_Item(itemId):
|
1808 |
def get_flipkart_inventory_for_Item(itemId):
|
| 1718 |
return FlipkartInventorySnapshot.get_by(item_id = itemId)
|
1809 |
return FlipkartInventorySnapshot.get_by(item_id=itemId)
|
| - |
|
1810 |
|
| 1719 |
|
1811 |
|
| 1720 |
def get_state_master():
|
1812 |
def get_state_master():
|
| 1721 |
stateIdNameMap = {}
|
1813 |
stateIdNameMap = {}
|
| 1722 |
statemaster = StateMaster.query.all()
|
1814 |
statemaster = StateMaster.query.all()
|
| 1723 |
for state in statemaster:
|
1815 |
for state in statemaster:
|
| 1724 |
stateIdNameMap[state.id] = to_t_state(state)
|
1816 |
stateIdNameMap[state.id] = to_t_state(state)
|
| 1725 |
return stateIdNameMap
|
1817 |
return stateIdNameMap
|
| 1726 |
|
1818 |
|
| - |
|
1819 |
|
| 1727 |
def update_snapdeal_stock_at_eod(allsnapdealstock):
|
1820 |
def update_snapdeal_stock_at_eod(allsnapdealstock):
|
| 1728 |
for stockitem in allsnapdealstock:
|
1821 |
for stockitem in allsnapdealstock:
|
| 1729 |
snapdealstockateod = SnapdealStockAtEOD()
|
1822 |
snapdealstockateod = SnapdealStockAtEOD()
|
| 1730 |
snapdealstockateod.item_id = stockitem.item_id
|
1823 |
snapdealstockateod.item_id = stockitem.item_id
|
| 1731 |
snapdealstockateod.availability = stockitem.availability
|
1824 |
snapdealstockateod.availability = stockitem.availability
|
| 1732 |
snapdealstockateod.date = to_py_date(stockitem.date)
|
1825 |
snapdealstockateod.date = to_py_date(stockitem.date)
|
| 1733 |
session.commit()
|
1826 |
session.commit()
|
| - |
|
1827 |
|
| 1734 |
|
1828 |
|
| 1735 |
def update_flipkart_stock_at_eod(allflipkartstock):
|
1829 |
def update_flipkart_stock_at_eod(allflipkartstock):
|
| 1736 |
for stockitem in allflipkartstock:
|
1830 |
for stockitem in allflipkartstock:
|
| 1737 |
snapdealstockateod = FlipkartStockAtEOD()
|
1831 |
snapdealstockateod = FlipkartStockAtEOD()
|
| 1738 |
snapdealstockateod.item_id = stockitem.item_id
|
1832 |
snapdealstockateod.item_id = stockitem.item_id
|
| 1739 |
snapdealstockateod.availability = stockitem.availability
|
1833 |
snapdealstockateod.availability = stockitem.availability
|
| 1740 |
snapdealstockateod.date = to_py_date(stockitem.date)
|
1834 |
snapdealstockateod.date = to_py_date(stockitem.date)
|
| 1741 |
session.commit()
|
1835 |
session.commit()
|
| - |
|
1836 |
|
| 1742 |
|
1837 |
|
| 1743 |
def get_wanlc_for_source(item_id,sourceId):
|
1838 |
def get_wanlc_for_source(item_id, sourceId):
|
| 1744 |
stockWanlc = StockWeightedNlcInfo.query.filter(StockWeightedNlcInfo.itemId==item_id).filter(StockWeightedNlcInfo.source==sourceId).order_by(desc(StockWeightedNlcInfo.updatedTimestamp)).limit(1).all()
|
1839 |
stockWanlc = StockWeightedNlcInfo.query.filter(StockWeightedNlcInfo.itemId == item_id).filter(StockWeightedNlcInfo.source == sourceId).order_by(desc(StockWeightedNlcInfo.updatedTimestamp)).limit(1).all()
|
| 1745 |
if stockWanlc is None or len(stockWanlc)==0:
|
1840 |
if stockWanlc is None or len(stockWanlc) == 0:
|
| 1746 |
return 0.0
|
1841 |
return 0.0
|
| 1747 |
else:
|
1842 |
else:
|
| 1748 |
return stockWanlc[0].avgWeightedNlc
|
1843 |
return stockWanlc[0].avgWeightedNlc
|
| - |
|
1844 |
|
| 1749 |
|
1845 |
|
| 1750 |
def get_all_available_amazon_inventory():
|
1846 |
def get_all_available_amazon_inventory():
|
| 1751 |
return AmazonFbaInventorySnapshot.query.filter(AmazonFbaInventorySnapshot.availability>0).all()
|
1847 |
return AmazonFbaInventorySnapshot.query.filter(AmazonFbaInventorySnapshot.availability > 0).all()
|
| - |
|
1848 |
|
| 1752 |
|
1849 |
|
| 1753 |
def add_vendor_item_pricing_in_bulk(vendorItemPricingList):
|
1850 |
def add_vendor_item_pricing_in_bulk(vendorItemPricingList):
|
| 1754 |
exceptionItems = []
|
1851 |
exceptionItems = []
|
| 1755 |
for vendorItemPricing in vendorItemPricingList:
|
1852 |
for vendorItemPricing in vendorItemPricingList:
|
| 1756 |
try:
|
1853 |
try:
|
| 1757 |
add_vendor_pricing(vendorItemPricing, False)
|
1854 |
add_vendor_pricing(vendorItemPricing, False)
|
| 1758 |
except:
|
1855 |
except:
|
| 1759 |
exceptionItems.append(vendorItemPricing.itemId)
|
1856 |
exceptionItems.append(vendorItemPricing.itemId)
|
| 1760 |
return exceptionItems
|
1857 |
return exceptionItems
|
| 1761 |
|
1858 |
|
| - |
|
1859 |
|
| 1762 |
def add_inventory_in_bulk(bulkInventoryList):
|
1860 |
def add_inventory_in_bulk(bulkInventoryList):
|
| 1763 |
for item in bulkInventoryList:
|
1861 |
for item in bulkInventoryList:
|
| 1764 |
add_inventory(item.item_id, item.warehouse_id, item.inventory, True)
|
1862 |
add_inventory(item.item_id, item.warehouse_id, item.inventory, True)
|
| 1765 |
|
- |
|
| 1766 |
|
- |
|
| 1767 |
|
1863 |
|
| 1768 |
#from shop2020.clients.TransactionClient import TransactionClient
|
1864 |
# from shop2020.clients.TransactionClient import TransactionClient
|
| 1769 |
#from shop2020.thriftpy.model.v1.order.ttypes import OrderType, OrderSource, TransactionStatus
|
1865 |
# from shop2020.thriftpy.model.v1.order.ttypes import OrderType, OrderSource, TransactionStatus
|
| 1770 |
#from shop2020.thriftpy.logistics.ttypes import LocationInfo, PickUpType
|
1866 |
# from shop2020.thriftpy.logistics.ttypes import LocationInfo, PickUpType
|
| 1771 |
#tc = TransactionClient().get_client()
|
1867 |
# tc = TransactionClient().get_client()
|
| 1772 |
#tc.changeTransactionStatus(1037182, TransactionStatus.COD_IN_PROCESS, 'Cod Payment Awaited', PickUpType.COURIER, OrderType.B2C, OrderSource.WEBSITE)
|
1868 |
# tc.changeTransactionStatus(1037182, TransactionStatus.COD_IN_PROCESS, 'Cod Payment Awaited', PickUpType.COURIER, OrderType.B2C, OrderSource.WEBSITE)
|