| Line 28... |
Line 28... |
| 28 |
from string import Template
|
28 |
from string import Template
|
| 29 |
from urllib2 import HTTPBasicAuthHandler
|
29 |
from urllib2 import HTTPBasicAuthHandler
|
| 30 |
import datetime
|
30 |
import datetime
|
| 31 |
import sys
|
31 |
import sys
|
| 32 |
import urllib2
|
32 |
import urllib2
|
| - |
|
33 |
from shop2020.utils import EmailAttachmentSender
|
| 33 |
|
34 |
|
| 34 |
def initialize():
|
35 |
def initialize():
|
| 35 |
DataService.initialize()
|
36 |
DataService.initialize()
|
| 36 |
|
37 |
|
| 37 |
def get_all_items_by_status(status, offset=0, limit=None):
|
38 |
def get_all_items_by_status(status, offset=0, limit=None):
|
| Line 373... |
Line 374... |
| 373 |
cl = TransactionClient().get_client()
|
374 |
cl = TransactionClient().get_client()
|
| 374 |
#FIXME hardcoding for warehouse id
|
375 |
#FIXME hardcoding for warehouse id
|
| 375 |
cl.addAlert(AlertType.NEW_INVENTORY_ALERT, 5, "Inventory received for item " + item.brand + " " + item.model_name + " " + item.model_number + " " + item.color)
|
376 |
cl.addAlert(AlertType.NEW_INVENTORY_ALERT, 5, "Inventory received for item " + item.brand + " " + item.model_name + " " + item.model_number + " " + item.color)
|
| 376 |
except:
|
377 |
except:
|
| 377 |
print "Not able to raise alert for incoming inventory"
|
378 |
print "Not able to raise alert for incoming inventory"
|
| - |
|
379 |
if current_inventory_snapshot.availibility < 0:
|
| - |
|
380 |
__send_alert_for_negative_availability(item, current_inventory_snapshot.availibility, warehouse)
|
| 378 |
except:
|
381 |
except:
|
| 379 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
382 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 380 |
session.commit()
|
383 |
session.commit()
|
| 381 |
check_risky_item(item)
|
384 |
check_risky_item(item)
|
| 382 |
|
385 |
|
| - |
|
386 |
def __send_alert_for_negative_reserved(item, reserved, warehouse):
|
| - |
|
387 |
itemName = " ".join([str(item.brand), str(item.model_name), str(item.model_number), str(item.color)])
|
| - |
|
388 |
EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', 'Negative Reserved count for ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
| - |
|
389 |
|
| - |
|
390 |
def __send_alert_for_negative_availability(item, availability, warehouse):
|
| - |
|
391 |
itemName = " ".join([str(item.brand), str(item.model_name), str(item.model_number), str(item.color)])
|
| - |
|
392 |
EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', 'Negative Availability count for ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
|
| - |
|
393 |
|
| 383 |
def __send_mail_for_missing_key(item_key, warehouse_id):
|
394 |
def __send_mail_for_missing_key(item_key, warehouse_id):
|
| 384 |
if not MissingItemKey.get_by(itemKey = item_key):
|
395 |
if not MissingItemKey.get_by(itemKey = item_key):
|
| 385 |
missingItemKey = MissingItemKey()
|
396 |
missingItemKey = MissingItemKey()
|
| 386 |
missingItemKey.itemKey = item_key
|
397 |
missingItemKey.itemKey = item_key
|
| 387 |
missingItemKey.warehouseId = warehouse_id
|
398 |
missingItemKey.warehouseId = warehouse_id
|
| 388 |
helperClient = HelperClient().get_client()
|
- |
|
| 389 |
helperClient.saveUserEmailForSending('mandeep.dhir@shop2020.in', 'inventory@shop2020.in', 'Item-key not found while inventory sync', item_key + ' warehouse id: ' + str(warehouse_id), None, 'inventory')
|
399 |
EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', 'Item-key not found while inventory sync', item_key + ' warehouse id: ' + str(warehouse_id))
|
| 390 |
session.commit()
|
400 |
session.commit()
|
| 391 |
|
401 |
|
| 392 |
def add_inventory(itemId, warehouseId, quantity):
|
402 |
def add_inventory(itemId, warehouseId, quantity):
|
| 393 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
403 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| 394 |
if not current_inventory_snapshot:
|
404 |
if not current_inventory_snapshot:
|
| Line 398... |
Line 408... |
| 398 |
current_inventory_snapshot.availibility = 0
|
408 |
current_inventory_snapshot.availibility = 0
|
| 399 |
current_inventory_snapshot.reserved = 0
|
409 |
current_inventory_snapshot.reserved = 0
|
| 400 |
# added the difference in the current inventory
|
410 |
# added the difference in the current inventory
|
| 401 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
|
411 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
|
| 402 |
session.commit()
|
412 |
session.commit()
|
| - |
|
413 |
if current_inventory_snapshot.availibility < 0:
|
| - |
|
414 |
__send_alert_for_negative_availability(get_item(itemId), current_inventory_snapshot.availibility, get_Warehouse(warehouseId))
|
| 403 |
check_risky_item(get_item(itemId))
|
415 |
check_risky_item(get_item(itemId))
|
| 404 |
|
416 |
|
| 405 |
'''
|
417 |
'''
|
| 406 |
def get_item_inventoy(item_id):
|
418 |
def get_item_inventoy(item_id):
|
| 407 |
|
419 |
|
| Line 610... |
Line 622... |
| 610 |
##FIXME In case of our own warehouse reduce availability also
|
622 |
##FIXME In case of our own warehouse reduce availability also
|
| 611 |
if warehouse_id == 7:
|
623 |
if warehouse_id == 7:
|
| 612 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility - quantity
|
624 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility - quantity
|
| 613 |
session.commit()
|
625 |
session.commit()
|
| 614 |
check_risky_item(item)
|
626 |
check_risky_item(item)
|
| - |
|
627 |
if current_inventory_snapshot.reserved < 0:
|
| - |
|
628 |
__send_alert_for_negative_reserved(get_item(item_id), current_inventory_snapshot.reserved, get_Warehouse(warehouse_id))
|
| 615 |
return True
|
629 |
return True
|
| 616 |
except:
|
630 |
except:
|
| 617 |
print "Unexpected error:", sys.exc_info()[0]
|
631 |
print "Unexpected error:", sys.exc_info()[0]
|
| 618 |
return False
|
632 |
return False
|
| 619 |
|
633 |
|