Subversion Repositories SmartDukaan

Rev

Rev 4858 | Rev 4876 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4858 Rev 4873
Line 14... Line 14...
14
    to_t_vendor_item_pricing, to_t_source
14
    to_t_vendor_item_pricing, to_t_source
15
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
15
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
16
    ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo, ItemChangeLog, \
16
    ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo, ItemChangeLog, \
17
    Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
17
    Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
18
    SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
18
    SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
19
    MissingItemKey
19
    MissedInventoryUpdate
20
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
20
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
21
    status, ItemShippingInfo
21
    status, ItemShippingInfo
22
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
22
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
-
 
23
from shop2020.utils import EmailAttachmentSender
23
from shop2020.utils.EmailAttachmentSender import mail
24
from shop2020.utils.EmailAttachmentSender import mail
24
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
25
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
25
from sqlalchemy import desc, asc
26
from sqlalchemy import desc, asc
26
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
27
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
27
from sqlalchemy.sql.expression import and_, or_, distinct, func
28
from sqlalchemy.sql.expression import and_, or_, distinct, func
28
from string import Template
29
from string import Template
29
from urllib2 import HTTPBasicAuthHandler
30
from urllib2 import HTTPBasicAuthHandler
30
import datetime
31
import datetime
31
import sys
32
import sys
32
import urllib2
33
import urllib2
33
from shop2020.utils import EmailAttachmentSender
-
 
34
 
34
 
35
def initialize():
35
def initialize():
36
    DataService.initialize()
36
    DataService.initialize()
37
 
37
 
38
def get_all_items_by_status(status, offset=0, limit=None):
38
def get_all_items_by_status(status, offset=0, limit=None):
Line 354... Line 354...
354
    for item_key, quantity in availability.iteritems():
354
    for item_key, quantity in availability.iteritems():
355
        try:
355
        try:
356
            vendor_item_mapping = VendorItemMapping.query.filter_by(vendor=vendor, item_key=item_key).one();
356
            vendor_item_mapping = VendorItemMapping.query.filter_by(vendor=vendor, item_key=item_key).one();
357
            item = vendor_item_mapping.item
357
            item = vendor_item_mapping.item
358
        except:
358
        except:
359
            print 'Could not find item with key: ' + item_key
359
            print 'Skipping update for ' + item_key + ' quantity ' + str(quantity) + ' warehouse id: ' + str(warehouse_id)
360
            __send_mail_for_missing_key(item_key, warehouse_id)
360
            __send_mail_for_missing_key(item_key, quantity, warehouse_id)
361
            continue
361
            continue
362
        try:
362
        try:
363
            current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
363
            current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
364
            if not current_inventory_snapshot:
364
            if not current_inventory_snapshot:
365
                current_inventory_snapshot = CurrentInventorySnapshot()
365
                current_inventory_snapshot = CurrentInventorySnapshot()
Line 382... Line 382...
382
            raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
382
            raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
383
        session.commit() 
383
        session.commit() 
384
        check_risky_item(item)
384
        check_risky_item(item)
385
 
385
 
386
def __send_alert_for_negative_reserved(item, reserved, warehouse):
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)])
387
    itemName = " ".join([str(item.id), 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)
388
    EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', 'Negative reserved: ' + str(reserved) + ' for Item Id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
389
 
389
 
390
def __send_alert_for_negative_availability(item, availability, warehouse):
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)])
391
    itemName = " ".join([str(item.id), 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)
392
    EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', 'Negative availability ' + str(availability) + ' for Item id: ' + itemName + ' warehouse id: ' + str(warehouse.id), None)
393
 
393
 
394
def __send_mail_for_missing_key(item_key, warehouse_id):
394
def __send_mail_for_missing_key(item_key, quantity, warehouse_id):
-
 
395
    if not MissedInventoryUpdate.get_by(itemKey = item_key, isIgnored = 1):
-
 
396
        # One email per product key mismatch
395
    if not MissingItemKey.get_by(itemKey = item_key):
397
        if not MissedInventoryUpdate.get_by(itemKey = item_key):
396
        missingItemKey = MissingItemKey()
398
            EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', ['mandeep.dhir@shop2020.in', 'chaitnaya.vats@shop2020.in'], 'Skipped inventory update for ' + item_key + ' quantity ' + str(quantity) + ' warehouse id: ' + str(warehouse_id), None)
-
 
399
        missedInventoryUpdate = MissedInventoryUpdate()
397
        missingItemKey.itemKey = item_key
400
        missedInventoryUpdate.itemKey = item_key
398
        missingItemKey.warehouseId = warehouse_id
401
        missedInventoryUpdate.quantity = quantity
-
 
402
        missedInventoryUpdate.isIgnored = 0
-
 
403
        missedInventoryUpdate.timestamp = datetime.datetime.now()
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))
404
        missedInventoryUpdate.warehouseId = warehouse_id
400
        session.commit()
405
        session.commit()
401
 
406
 
402
def add_inventory(itemId, warehouseId, quantity):
407
def add_inventory(itemId, warehouseId, quantity):
403
    current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
408
    current_inventory_snapshot = CurrentInventorySnapshot.get_by(item_id=itemId, warehouse_id=warehouseId)
404
    if not current_inventory_snapshot:
409
    if not current_inventory_snapshot: