| Line 2... |
Line 2... |
| 2 |
Created on 23-Mar-2010
|
2 |
Created on 23-Mar-2010
|
| 3 |
|
3 |
|
| 4 |
@author: ashish
|
4 |
@author: ashish
|
| 5 |
'''
|
5 |
'''
|
| 6 |
from elixir import *
|
6 |
from elixir import *
|
| - |
|
7 |
from pydoc import Helper
|
| - |
|
8 |
from shop2020.clients.HelperClient import HelperClient
|
| - |
|
9 |
from shop2020.clients.TransactionClient import TransactionClient
|
| - |
|
10 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 7 |
from shop2020.model.v1.catalog.impl import DataService
|
11 |
from shop2020.model.v1.catalog.impl import DataService
|
| 8 |
from shop2020.model.v1.catalog.impl.DataService import Item, \
|
12 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
| 9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
- |
|
| 10 |
ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
|
- |
|
| 11 |
VendorItemMapping, Vendor, SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog
|
- |
|
| 12 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
- |
|
| 13 |
InventoryServiceException, status, ItemShippingInfo
|
- |
|
| 14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
|
13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, \
|
| 15 |
to_t_vendor_item_pricing, to_t_source
|
14 |
to_t_vendor_item_pricing, to_t_source
|
| - |
|
15 |
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
|
| - |
|
16 |
ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo, ItemChangeLog, \
|
| - |
|
17 |
Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
|
| - |
|
18 |
SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
|
| 16 |
import datetime
|
19 |
MissingItemKey
|
| - |
|
20 |
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
|
| 17 |
import sys
|
21 |
status, ItemShippingInfo
|
| - |
|
22 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
| - |
|
23 |
from shop2020.utils.EmailAttachmentSender import mail
|
| 18 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
24 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
| 19 |
from sqlalchemy import desc, asc
|
25 |
from sqlalchemy import desc, asc
|
| 20 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
26 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
| 21 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
- |
|
| 22 |
from sqlalchemy.sql.expression import and_, or_, distinct, func
|
27 |
from sqlalchemy.sql.expression import and_, or_, distinct, func
|
| 23 |
from string import Template
|
28 |
from string import Template
|
| 24 |
from shop2020.clients.HelperClient import HelperClient
|
- |
|
| 25 |
import urllib2
|
- |
|
| 26 |
from urllib2 import HTTPBasicAuthHandler
|
29 |
from urllib2 import HTTPBasicAuthHandler
|
| 27 |
from shop2020.config.client.ConfigClient import ConfigClient
|
30 |
import datetime
|
| 28 |
from shop2020.utils.EmailAttachmentSender import mail
|
31 |
import sys
|
| 29 |
from shop2020.clients.TransactionClient import TransactionClient
|
32 |
import urllib2
|
| 30 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
- |
|
| 31 |
|
33 |
|
| 32 |
def initialize():
|
34 |
def initialize():
|
| 33 |
DataService.initialize()
|
35 |
DataService.initialize()
|
| 34 |
|
36 |
|
| 35 |
def get_all_items_by_status(status, offset=0, limit=None):
|
37 |
def get_all_items_by_status(status, offset=0, limit=None):
|
| Line 364... |
Line 366... |
| 364 |
for item_key, quantity in availability.iteritems():
|
366 |
for item_key, quantity in availability.iteritems():
|
| 365 |
try:
|
367 |
try:
|
| 366 |
vendor_item_mapping = VendorItemMapping.query.filter_by(vendor=vendor, item_key=item_key).one();
|
368 |
vendor_item_mapping = VendorItemMapping.query.filter_by(vendor=vendor, item_key=item_key).one();
|
| 367 |
item = vendor_item_mapping.item
|
369 |
item = vendor_item_mapping.item
|
| 368 |
except:
|
370 |
except:
|
| - |
|
371 |
print 'Could not find item with key: ' + item_key
|
| - |
|
372 |
__send_mail_for_missing_key(item_key, warehouse_id)
|
| 369 |
continue
|
373 |
continue
|
| 370 |
try:
|
374 |
try:
|
| 371 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
|
375 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
|
| 372 |
if not current_inventory_snapshot:
|
376 |
if not current_inventory_snapshot:
|
| 373 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
377 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| 374 |
current_inventory_snapshot.item = item
|
378 |
current_inventory_snapshot.item = item
|
| Line 387... |
Line 391... |
| 387 |
except:
|
391 |
except:
|
| 388 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
392 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 389 |
session.commit()
|
393 |
session.commit()
|
| 390 |
check_risky_item(item)
|
394 |
check_risky_item(item)
|
| 391 |
|
395 |
|
| - |
|
396 |
def __send_mail_for_missing_key(item_key, warehouse_id):
|
| - |
|
397 |
if not MissingItemKey.get_by(itemKey = item_key):
|
| - |
|
398 |
missingItemKey = MissingItemKey()
|
| - |
|
399 |
missingItemKey.itemKey = item_key
|
| - |
|
400 |
missingItemKey.warehouseId = warehouse_id
|
| - |
|
401 |
helperClient = HelperClient().get_client()
|
| - |
|
402 |
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')
|
| - |
|
403 |
session.commit()
|
| - |
|
404 |
|
| 392 |
def add_inventory(itemId, warehouseId, quantity):
|
405 |
def add_inventory(itemId, warehouseId, quantity):
|
| 393 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
406 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
|
| 394 |
if not current_inventory_snapshot:
|
407 |
if not current_inventory_snapshot:
|
| 395 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
408 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
| 396 |
current_inventory_snapshot.item_id = itemId
|
409 |
current_inventory_snapshot.item_id = itemId
|