Subversion Repositories SmartDukaan

Rev

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

Rev 21061 Rev 22256
Line 1... Line 1...
1
from elixir import *
1
from datetime import datetime
2
from dtr.storage.MemCache import MemCache
2
from dtr.storage.MemCache import MemCache
-
 
3
from dtr.utils.utils import get_mongo_connection, SOURCE_MAP
-
 
4
from elixir import *
-
 
5
from shop2020.clients.InventoryClient import InventoryClient
3
from shop2020.model.v1.catalog.impl import DataService as CatalogDataService
6
from shop2020.model.v1.catalog.impl import DataService as CatalogDataService
-
 
7
from shop2020.model.v1.catalog.impl.DataService import Item, PrivateDeals, \
-
 
8
    BulkItemPricing, Tag_Listing
4
from shop2020.model.v1.inventory.impl import DataService as InventoryDataService
9
from shop2020.model.v1.inventory.impl import DataService as InventoryDataService
5
from shop2020.model.v1.catalog.impl.DataService import Item, PrivateDeals, BulkItemPricing
-
 
6
from shop2020.model.v1.inventory.impl.DataService import ItemAvailabilityCache
10
from shop2020.model.v1.inventory.impl.DataService import ItemAvailabilityCache
7
from dtr.utils.utils import get_mongo_connection, SOURCE_MAP
-
 
8
import optparse
11
import optparse
9
import traceback
12
import traceback
10
from datetime import datetime
-
 
11
from shop2020.clients.InventoryClient import InventoryClient
-
 
12
 
13
 
13
parser = optparse.OptionParser()
14
parser = optparse.OptionParser()
14
parser.add_option("-H", "--host", dest="hostname",
15
parser.add_option("-H", "--host", dest="hostname",
15
                      default="localhost",
16
                      default="localhost",
16
                      type="string", help="The HOST where the DB server is running",
17
                      type="string", help="The HOST where the DB server is running",
Line 26... Line 27...
26
inventoryMap = {}
27
inventoryMap = {}
27
memCon = None
28
memCon = None
28
maxQuantity = 100
29
maxQuantity = 100
29
flaggedItems = []
30
flaggedItems = []
30
itemPricingMap = {}
31
itemPricingMap = {}
-
 
32
#listingPricing map is {<itemId>:[{tag_id:<tagId>, selling_price:<sellingPrice>, mop:<mop>}]}
-
 
33
listingPricingMap = {}
31
bulkItemsMap = {}
34
bulkItemsMap = {}
32
 
35
 
33
def get_inventory_client():
36
def get_inventory_client():
34
    ic = InventoryClient("inventory_service_server_host2","inventory_service_server_port2").get_client()
37
    ic = InventoryClient("inventory_service_server_host2","inventory_service_server_port2").get_client()
35
    return ic
38
    return ic
Line 64... Line 67...
64
def addItemIdInfo():
67
def addItemIdInfo():
65
    global bundleMap
68
    global bundleMap
66
    global itemPricingMap
69
    global itemPricingMap
67
    try:
70
    try:
68
        CatalogDataService.initialize(db_hostname=options.hostname,setup=False)
71
        CatalogDataService.initialize(db_hostname=options.hostname,setup=False)
-
 
72
        item_id_tags = session.query(Tag_Listing).all()
-
 
73
        item_id_tags_map = {}
-
 
74
        for item_id_tag in item_id_tags:
-
 
75
            if not item_id_tags_map.has_key(item_id_tag.item_id):
-
 
76
                item_id_tags_map[item_id_tag.item_id] = []
-
 
77
            item_id_tags_map.get(item_id_tag.item_id).append(item_id_tag.tag_id)
-
 
78
        
69
        totalLength = len(bundleMap.keys())
79
        totalLength = len(bundleMap.keys())
70
        fetch =100
80
        fetch =100
71
        start = 0
81
        start = 0
72
        toBreak = False
82
        toBreak = False
73
        while(True):
83
        while(True):
Line 76... Line 86...
76
            if fetch > totalLength:
86
            if fetch > totalLength:
77
                fetch = totalLength
87
                fetch = totalLength
78
                toBreak = True
88
                toBreak = True
79
                
89
                
80
            item_list = bundleMap.keys()[start:fetch]
90
            item_list = bundleMap.keys()[start:fetch]
-
 
91
            #No more normal deals only privatedeals are to be considered here
81
            items = session.query(Item,PrivateDeals).outerjoin((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.catalog_item_id.in_(item_list)).all()
92
            items = session.query(Item,PrivateDeals).join((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.catalog_item_id.in_(item_list)).all()
82
            for i in items:
93
            for i in items:
83
                d_item = i[0]
94
                d_item = i[0]
84
                d_privatedeal = i[1]
95
                d_privatedeal = i[1]
85
                tempList = bundleMap.get(d_item.catalog_item_id)
96
                tempList = bundleMap.get(d_item.catalog_item_id)
86
                sellingPrice = d_item.sellingPrice
97
#               sellingPrice = d_item.sellingPrice
87
                sellingPriceType = "Normal"
98
#               sellingPriceType = "Normal"
88
                if d_privatedeal is not None and d_privatedeal.isActive==1 and d_privatedeal.startDate < datetime.now() and d_privatedeal.endDate > datetime.now() and d_privatedeal.dealPrice >0:
99
                if d_privatedeal is not None and d_privatedeal.isActive==1 and d_privatedeal.startDate < datetime.now() and d_privatedeal.endDate > datetime.now() and d_privatedeal.dealPrice >0:
89
                    sellingPrice = d_privatedeal.dealPrice
100
                    sellingPrice = d_privatedeal.dealPrice
90
                    sellingPriceType = "Private deal price"
101
                    sellingPriceType = "Private deal price"
91
                tempList.append({'item_id':d_item.id,'color':d_item.color,'sellingPrice':sellingPrice,'sellingPriceType':sellingPriceType,'minBuyQuantity':d_item.minimumBuyQuantity,'quantityStep':d_item.quantityStep,'maxQuantity':d_item.maximumBuyQuantity})
102
                    temp = {'item_id':d_item.id,'color':d_item.color,'sellingPrice':sellingPrice,'sellingPriceType':sellingPriceType,'minBuyQuantity':d_item.minimumBuyQuantity,
-
 
103
                            'quantityStep':d_item.quantityStep,'maxQuantity':d_item.maximumBuyQuantity}
-
 
104
                    if item_id_tags_map.has_key(d_item.id):
-
 
105
                        temp['tag_ids'] = item_id_tags_map.get(d_item.id)
-
 
106
                    tempList.append(temp)
92
                itemPricingMap[d_item.id] =sellingPrice
107
                    itemPricingMap[d_item.id] =sellingPrice
-
 
108
 
93
            if toBreak:
109
            if toBreak:
94
                print "Breaking"
110
                print "Breaking"
95
                break
111
                break
96
            start = fetch
112
            start = fetch
97
            fetch = start + fetch
113
            fetch = start + fetch
Line 191... Line 207...
191
        for itemInventory in allInventory:
207
        for itemInventory in allInventory:
192
            inventoryMap[itemInventory.itemId] = itemInventory.totalAvailability
208
            inventoryMap[itemInventory.itemId] = itemInventory.totalAvailability
193
    finally:
209
    finally:
194
        session.close()
210
        session.close()
195
 
211
 
-
 
212
 
196
if __name__ == '__main__':
213
if __name__ == '__main__':
197
    populateSaholicBundles()
214
    populateSaholicBundles()
198
    addItemIdInfo()
215
    addItemIdInfo()
199
    addBulkPricingInfo()
216
    addBulkPricingInfo()
-
 
217
    #Gets tagListing
-
 
218
    
200
    fetchItemAvailablity()
219
    fetchItemAvailablity()
201
    flagNoAvailableItems()
220
    flagNoAvailableItems()
202
    if len(flaggedItems) > 0:
221
    if len(flaggedItems) > 0:
203
        print "Flagged items ",flaggedItems
222
        print "Flagged items ",flaggedItems
204
        get_inventory_client().updateItemAvailabilityForItemIds(flaggedItems)
223
        get_inventory_client().updateItemAvailabilityForItemIds(flaggedItems)