Subversion Repositories SmartDukaan

Rev

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

Rev 6780 Rev 6821
Line 12... Line 12...
12
    to_t_itemidwarehouseid
12
    to_t_itemidwarehouseid
13
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
13
from shop2020.model.v1.inventory.impl.DataService import Warehouse, \
14
    ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \
14
    ItemInventoryHistory, CurrentInventorySnapshot, VendorItemPricing, \
15
    VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \
15
    VendorItemMapping, Vendor, MissedInventoryUpdate, BadInventorySnapshot, \
16
    VendorItemProcurementDelay, VendorHolidays, ItemAvailabilityCache, \
16
    VendorItemProcurementDelay, VendorHolidays, ItemAvailabilityCache, \
17
    CurrentReservationSnapshot, IgnoredInventoryUpdateItems
17
    CurrentReservationSnapshot, IgnoredInventoryUpdateItems, \
-
 
18
    ItemStockPurchaseParams, OOSStatus
18
from shop2020.thriftpy.model.v1.inventory.ttypes import \
19
from shop2020.thriftpy.model.v1.inventory.ttypes import \
19
    InventoryServiceException, HolidayType, InventoryType, WarehouseType
20
    InventoryServiceException, HolidayType, InventoryType, WarehouseType
20
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
21
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
21
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
22
from shop2020.thriftpy.purchase.ttypes import PurchaseServiceException
22
from shop2020.utils import EmailAttachmentSender
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 to_py_date
25
from shop2020.utils.Utils import to_py_date, to_java_date
25
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
26
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
26
from sqlalchemy.sql.expression import and_, func, distinct
27
from sqlalchemy.sql.expression import and_, func, distinct
27
from sqlalchemy.sql.functions import count
28
from sqlalchemy.sql.functions import count
28
import calendar
29
import calendar
29
import datetime
30
import datetime
Line 34... Line 35...
34
mail_user = "cnc.center@shop2020.in"
35
mail_user = "cnc.center@shop2020.in"
35
mail_password = "5h0p2o2o"
36
mail_password = "5h0p2o2o"
36
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
37
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
37
                 193 : [5839] }
38
                 193 : [5839] }
38
 
39
 
39
 
-
 
-
 
40
OOS_CALCULATION_TIME = 23
40
 
41
 
41
def initialize(dbname='inventory', db_hostname="localhost"):
42
def initialize(dbname='inventory', db_hostname="localhost"):
42
    DataService.initialize(dbname, db_hostname)
43
    DataService.initialize(dbname, db_hostname)
43
    
44
    
44
def get_Warehouse(warehouse_id):
45
def get_Warehouse(warehouse_id):
Line 959... Line 960...
959
    itemIds = session.query(distinct(IgnoredInventoryUpdateItems.item_id))
960
    itemIds = session.query(distinct(IgnoredInventoryUpdateItems.item_id))
960
    '''if limit is not None:
961
    '''if limit is not None:
961
        itemIds = itemIds.limit(limit)'''
962
        itemIds = itemIds.limit(limit)'''
962
    print itemIds.all()
963
    print itemIds.all()
963
    return [id for (id, ) in itemIds.all()]
964
    return [id for (id, ) in itemIds.all()]
964
        
-
 
965
965
 
-
 
966
def update_item_stock_purchase_params(item_id, numOfDaysStock, minStockLevel):
-
 
967
    if numOfDaysStock is None or minStockLevel is None:
-
 
968
        raise InventoryServiceException(108, "Bad params : numOfDaysStock = " + str(numOfDaysStock) + "minStockLevel = " + str(minStockLevel))
-
 
969
    itemStockPurchaseParams = ItemStockPurchaseParams.query.filter_by(item_id = item_id).first()
-
 
970
    if itemStockPurchaseParams is None:
-
 
971
        itemStockPurchaseParams = ItemStockPurchaseParams()
-
 
972
    itemStockPurchaseParams.item_id = item_id
-
 
973
    itemStockPurchaseParams.numOfDaysStock = numOfDaysStock
-
 
974
    itemStockPurchaseParams.minStockLevel = minStockLevel
-
 
975
    session.commit()
-
 
976
 
-
 
977
def get_item_stock_purchase_params(item_id):
-
 
978
    return ItemStockPurchaseParams.query.filter_by(item_id = item_id).first()
-
 
979
 
-
 
980
def add_oos_status_for_item(oosStatusMap, date):
-
 
981
    
-
 
982
    oosDate = to_py_date(date)
-
 
983
    oosDate.replace(second=0, microsecond=0)
-
 
984
    
-
 
985
    cartAdditionStartDate = oosDate - datetime.timedelta(days = 1)
-
 
986
    
-
 
987
    client = TransactionClient().get_client()
-
 
988
    
-
 
989
    #Gets physical orders in the last day
-
 
990
    orders = client.getPhysicalOrders(to_java_date(cartAdditionStartDate), to_java_date(oosDate))
-
 
991
    
-
 
992
    orderCountByItemId = {}
-
 
993
    for order in orders:
-
 
994
        if orderCountByItemId.has_key(order.lineitems[0].item_id):
-
 
995
            orderCountByItemId[order.lineitems[0].item_id] = orderCountByItemId[order.lineitems[0].item_id] + 1 
-
 
996
        else:
-
 
997
            orderCountByItemId[order.lineitems[0].item_id] = 1
-
 
998
    
-
 
999
    for itemId, status in oosStatusMap.iteritems():
-
 
1000
        if OOSStatus.query.filter_by(item_id = itemId, date = oosDate).first() is None: 
-
 
1001
            oosStatus = OOSStatus()
-
 
1002
            oosStatus.item_id = itemId
-
 
1003
            oosStatus.date = oosDate
-
 
1004
            oosStatus.status = status
-
 
1005
            if status == False:
-
 
1006
                order_count = 0
-
 
1007
                if orderCountByItemId.has_key(itemId):
-
 
1008
                    order_count = orderCountByItemId[itemId]
-
 
1009
            oosStatus.num_orders = order_count
-
 
1010
            session.commit()
-
 
1011
        else:
-
 
1012
            print "OOS Status already exists for ItemID:"+str(itemId)
-
 
1013
            """raise InventoryServiceException(101, "OOS Status already exists for ItemID:"+str(itemId) + " & Date:"+oosDate)"""
-
 
1014
        
-
 
1015