Subversion Repositories SmartDukaan

Rev

Rev 10913 | Rev 11015 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
122 ashish 1
'''
2
Created on 27-Apr-2010
3
 
4
@author: ashish
5
'''
5110 mandeep.dh 6
from shop2020.config.client.ConfigClient import ConfigClient
6511 kshitij.so 7
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_category, \
8
    to_t_source_item_pricing, to_t_product_notification_request, \
7438 amit.gupta 9
    to_t_banner, to_t_banner_map, to_t_product_notification_request_count, \
8579 kshitij.so 10
    to_t_voucher_item_mapping, to_t_insurer, to_t_Amazonlisted, to_t_ebay_item, \
9621 manish.sha 11
    to_t_uri_mapping, to_t_banner_list, to_t_campaign,to_t_snapdeal_item, \
9781 kshitij.so 12
    to_t_snapdeal_item_details, to_t_product_feed_submit, to_t_marketplace_items, to_t_marketplace_itemprice,\
10913 vikram.rag 13
    to_t_marketplacepercentage, to_t_flipkart_item, to_t_flipkart_item_details
14
 
6511 kshitij.so 15
from shop2020.model.v1.catalog.impl.DataAcessors import add_item, retire_item, \
16
    change_item_status, get_item, get_all_items, get_all_items_by_status, \
5944 mandeep.dh 17
    update_item, start_item_on, close_session, retire_item_on, \
5110 mandeep.dh 18
    get_items_by_catalog_id, get_best_deals, get_best_deals_catalog_ids, \
19
    get_best_deals_count, get_best_sellers, get_latest_arrivals, \
20
    get_latest_arrivals_catalog_ids, get_latest_arrivals_count, is_active, \
21
    get_best_sellers_catalog_ids, get_best_sellers_count, put_category_object, \
5944 mandeep.dh 22
    get_category_object, mark_item_as_content_complete, generate_new_entity_id, \
23
    get_category, get_all_categories, add_category, get_item_status_description, \
6511 kshitij.so 24
    check_similar_item, change_risky_flag, get_items_for_mastersheet, \
25
    get_risky_items, get_similar_items_catalog_ids, add_product_notification, \
26
    send_product_notifications, get_all_brands_by_category, is_alive, \
27
    get_item_pricing_by_source, add_source_item_pricing, get_all_sources, \
28
    get_item_for_source, get_all_source_pricing, get_item_count_by_status, \
29
    search_items, get_search_result_count, get_product_notifications, \
30
    get_product_notification_request_count, get_all_similar_items_catalog_ids, \
31
    add_similar_item_catalog_id, delete_similar_item_catalog_id, \
32
    add_authorization_log_for_item, get_thrift_item_list, get_all_brands, \
33
    get_coming_soon, get_coming_soon_catalog_ids, get_coming_soon_count, initialize, \
7438 amit.gupta 34
    add_update_voucher_for_item, delete_voucher_for_item, get_voucher_amount, \
35
    get_all_vouchers_for_item, is_valid_catalog_id, check_risky_item, \
36
    get_vat_percentage_for_item, get_vat_amount_for_item, add_tag, get_all_tags, \
37
    get_all_entities_by_tag_name, delete_tag, delete_entity_tag, \
38
    get_all_ignored_inventoryupdate_items_list, add_banner, get_all_banners, \
39
    delete_banner, get_banner_details, get_active_banners, add_banner_map, \
40
    delete_banner_map, get_banner_map_details, get_insurance_amount, get_insurer, \
41
    get_all_alive_items, get_all_insurers, get_all_entity_tags, \
42
    update_insurance_declared_amount, get_freebie_for_item, \
43
    add_or_update_freebie_for_item, get_all_amazon_listed_items, get_store_pricing, \
44
    update_store_pricing, get_amazon_item_details, update_amazon_item_details, \
45
    add_amazon_item, get_asin_items, get_all_fba_listed_items, \
46
    get_all_nonfba_listed_items, add_or_update_brand_info, get_brand_info, \
7897 amar.kumar 47
    get_items_status, update_item_inventory, update_timestamp_for_amazon_feeds, \
8182 amar.kumar 48
    get_all_parent_categories,add_page_view_event,add_cart_event, \
8379 vikram.rag 49
    insert_ebay_item, get_ebay_item, update_ebay_item, update_amazon_attributes_in_bulk, \
8579 kshitij.so 50
    get_all_items_to_list_on_fba,get_all_items_to_list_on_nonfba, \
51
    update_banner,add_banner_uri,get_uri_mapping,add_campaign,get_campaigns, \
8619 kshitij.so 52
    delete_campaign, get_all_campaigns, get_amazon_listed_items, search_amazon_items, \
8739 vikram.rag 53
    get_count_for_amazonlisted_items, get_amazon_search_result_count,update_asin, \
9242 kshitij.so 54
    add_or_update_snapdeal_item, get_snapdeal_item, get_all_snapdeal_items , get_snapdeal_items, \
55
    search_snapdeal_items , get_count_for_snapdeal_items , get_snapdeal_search_result_count, \
9621 manish.sha 56
    get_active_banners_for_mobile_site, get_preffered_insurer_for_item, get_snapdealitem_by_skuatsnapdeal, \
57
    get_product_feed_submit, add_product_feed_submit, update_product_feed_submit, \
9724 kshitij.so 58
    delete_product_feed_submit, get_all_product_feed_submit, get_snapdeal_item_detail,\
9779 kshitij.so 59
    get_marketplace_details_for_item, update_marketplace_attributes_for_item,\
9895 vikram.rag 60
    get_costing_for_marketplace, get_all_marketplace_items_for_priceupdate, update_marketplace_priceupdate_status, \
10097 kshitij.so 61
    update_item_hold_inventory, update_nlc_at_marketplaces, get_all_flipkart_items, get_flipkart_item, \
62
    add_or_update_flipkart_item, get_flipkart_item_detail, get_flipkart_items, search_flipkart_items, \
10909 vikram.rag 63
    get_count_for_flipkart_items, get_flipkart_search_result_count, get_all_fk_items, get_flipkart_item_by_sku_at_flipkart, \
10924 vikram.rag 64
    get_all_fbb_listed_items, get_all_fbb_pricing_items
10913 vikram.rag 65
 
5944 mandeep.dh 66
from shop2020.thriftpy.model.v1.catalog.ttypes import status
67
from shop2020.utils.Utils import log_entry, to_py_date
5110 mandeep.dh 68
import datetime
122 ashish 69
 
5944 mandeep.dh 70
class CatalogServiceHandler:
122 ashish 71
    '''
72
    classdocs
73
    '''
599 chandransh 74
 
3187 rajveer 75
    def __init__(self, dbname='catalog', db_hostname='localhost'):
122 ashish 76
        '''
77
        Constructor
78
        '''
5295 rajveer 79
        initialize(dbname, db_hostname)
599 chandransh 80
        try:
621 chandransh 81
            config_client = ConfigClient()
82
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
83
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
599 chandransh 84
        except:
621 chandransh 85
            self.latest_arrivals_limit = 50
86
            self.best_sellers_limit = 50
122 ashish 87
 
88
    #DONE
89
    def addItem(self, item):
90
        """
91
        Availability and inventory attributes
92
 
93
        Parameters:
94
         - item
95
        """
96
        log_entry(self, "addItem called")
785 rajveer 97
        try:
98
            return add_item(item)
99
        finally:
100
            close_session()
6511 kshitij.so 101
 
102
 
103
    def addTag(self, displayName, catalogId):
104
        result = False
105
        try:
106
            return add_tag(displayName, catalogId)
107
        except:
108
            result = True
109
        finally:
110
            close_session()
111
            return result
6848 kshitij.so 112
 
8590 kshitij.so 113
    def addBanner(self, bannerCongregate):
6848 kshitij.so 114
        try:
10097 kshitij.so 115
            return add_banner(bannerCongregate)
6848 kshitij.so 116
        finally:
117
            close_session()
118
 
119
    def getAllBanners(self):
8579 kshitij.so 120
        bannerList=[]
6848 kshitij.so 121
        try:
8579 kshitij.so 122
            for banner in get_all_banners():
123
                bannerList.append(to_t_banner(banner))
6848 kshitij.so 124
        finally:
125
            close_session()
8579 kshitij.so 126
            return bannerList
6848 kshitij.so 127
 
9155 kshitij.so 128
    def deleteBanner(self,name,bannerType):
6848 kshitij.so 129
        try:
9155 kshitij.so 130
            return delete_banner(name,bannerType)
6848 kshitij.so 131
        finally:
132
            close_session()
133
 
9155 kshitij.so 134
    def getBannerDetails(self,name,bannerType):
6848 kshitij.so 135
        result = None
136
        try:
9155 kshitij.so 137
            result = get_banner_details(name,bannerType)
6848 kshitij.so 138
            if result is not None:
139
                result = to_t_banner(result)
140
        finally:
141
            close_session()
142
            return result
143
 
144
    def getActiveBanners(self):
10097 kshitij.so 145
        active_banners = {}
6848 kshitij.so 146
        try:
8579 kshitij.so 147
            active_banners = get_active_banners()
6848 kshitij.so 148
        finally:
149
            close_session()
8579 kshitij.so 150
            return active_banners
151
 
152
    def addBannerMap(self, bannerMaps):
6848 kshitij.so 153
        try:
8579 kshitij.so 154
            return add_banner_map(bannerMaps)
6848 kshitij.so 155
        finally:
156
            close_session()
157
 
158
    def deleteBannerMap(self, name):
159
        try:
160
            return delete_banner_map(name)
161
        finally:
162
            close_session()
163
 
9155 kshitij.so 164
    def getBannerMapDetails(self,name,bannerType):
6848 kshitij.so 165
        banners=[]
166
        try:
9155 kshitij.so 167
            for result in get_banner_map_details(name,bannerType):
6848 kshitij.so 168
                if result is not None:
8579 kshitij.so 169
                    banners.append(to_t_banner_map(result))
6848 kshitij.so 170
        finally:
171
            close_session()
172
            return banners
8579 kshitij.so 173
    def updateBanner(self,banner):
174
        try:
175
            return update_banner(banner)
176
        finally:
177
            close_session()
178
 
179
    def addBannerUri(self,bannerUriMappings):
180
        try:
181
            add_banner_uri(bannerUriMappings)
182
        finally:
183
            close_session()
184
 
9155 kshitij.so 185
    def getUriMapping(self,bannerName,bannerType):
8579 kshitij.so 186
        uriMapping=[]
187
        try:
9155 kshitij.so 188
            for uri in get_uri_mapping(bannerName,bannerType):
8579 kshitij.so 189
                uriMapping.append(to_t_uri_mapping(uri))
190
        finally:
191
            close_session()
192
            return uriMapping
193
 
194
    def addCampaign(self,campaign):
195
        try:
196
            add_campaign(campaign)
197
        finally:
198
            close_session()
199
 
200
    def getCampaigns(self,campaignName):
201
        campaigns = []
202
        try:
203
            for campaign in get_campaigns(campaignName):
204
                campaigns.append(to_t_campaign(campaign))
205
        finally:
206
            close_session()
207
            return campaigns
208
 
209
    def deleteCampaign(self,campaignId):
210
        try:
211
            delete_campaign(campaignId)
212
        finally:
213
            close_session()
6848 kshitij.so 214
 
8579 kshitij.so 215
    def getAllCampaigns(self):
216
        campaigns = []
217
        try:
218
            for campaign in get_all_campaigns():
219
                campaigns.append(campaign[0])
220
        finally:
221
            close_session()
222
            return campaigns
6848 kshitij.so 223
 
9155 kshitij.so 224
    def getActiveBannersForMobileSite(self):
10097 kshitij.so 225
        active_banners = {}
9155 kshitij.so 226
        try:
227
            active_banners = get_active_banners_for_mobile_site()
228
            for bannerName,banners in active_banners.iteritems():
229
                active_banners[bannerName] = to_t_banner_list(banners)
230
        finally:
231
            close_session()
232
            return active_banners
233
 
6511 kshitij.so 234
 
235
    def getAllTags(self):
236
        result = []
237
        try:
238
            result = get_all_tags()
239
        except:
240
            result = True
241
        finally:
242
            close_session()
243
            return result
244
 
245
    def getAllEntitiesByTagName(self,displayName):
246
        result = []
247
        try:
248
            result = get_all_entities_by_tag_name(displayName)
249
        except:
250
            result = True
251
        finally:
252
            close_session()
253
            return result
254
 
255
    def deleteTag(self,displayName):
256
        result = False
257
        try:
258
            return delete_tag(displayName)
259
        except:
260
            result = True
261
        finally:
262
            close_session()
263
            return result
264
 
6518 kshitij.so 265
    def deleteEntityTag(self,displayName,catalogId):
266
        result = False
267
        try:
268
            return delete_entity_tag(displayName,catalogId)
269
        except:
270
            result = True
271
        finally:
272
            close_session()
273
            return result
274
 
635 rajveer 275
    def isActive(self, item_id):
563 chandransh 276
        """
277
        Parameters:
635 rajveer 278
         - item_id
563 chandransh 279
        """
785 rajveer 280
        try:
281
            return is_active(item_id)
282
        finally:
283
            close_session()
7438 amit.gupta 284
 
285
    def getItemsStatus(self, item_ids):
286
        """
287
        Parameters:
288
         - item_id
289
        """
290
        try:
291
            return get_items_status(item_ids)
292
        finally:
293
            close_session()
122 ashish 294
 
2035 rajveer 295
    def getItemStatusDescription(self, itemId):
296
        """
297
        Parameters:
298
         - itemId
299
        """
300
        try:
301
            return get_item_status_description(itemId)
302
        finally:
303
            close_session()
122 ashish 304
 
305
    def retireItem(self, item_id):
306
        """
307
        Parameters:
308
        - item_id
309
        """
310
        log_entry(self, "retire item called")
785 rajveer 311
        try:
312
            return retire_item(item_id)
313
        finally:
314
            close_session()
122 ashish 315
 
316
    def startItemOn(self, item_id, timestamp):
317
        """
318
        Parameters:
319
         - item_id
320
         - timestamp
321
        """
785 rajveer 322
        try:
323
            start_item_on(item_id, timestamp)
324
        finally:
325
            close_session()
122 ashish 326
 
327
    def retireItemOn(self, item_id, timestamp):
328
        """
329
        Parameters:
330
         - item_id
331
         - timestamp
332
        """
785 rajveer 333
        try:
334
            retire_item_on(item_id, timestamp)
335
        finally:
336
            close_session()
122 ashish 337
 
338
    def changeItemStatus(self, item_id, timestamp, newstatus):
339
        """
340
        Parameters:
341
         - item_id
342
         - timestamp
343
         - newstatus
344
        """
345
        log_entry(self, "change item status called")
785 rajveer 346
        try:
347
            return change_item_status(item_id, newstatus)
348
        finally:
349
            close_session()
122 ashish 350
 
785 rajveer 351
 
122 ashish 352
    def getItem(self, item_id):
353
        """
354
        Parameters:
355
         - item_id
356
        """
357
        log_entry(self, "item requested")
785 rajveer 358
        try:
2065 ankur.sing 359
            item = to_t_item( get_item(item_id))
360
            return item
785 rajveer 361
        finally:
362
            close_session()
379 ashish 363
 
635 rajveer 364
    def getItemsByCatalogId(self, catalog_item_id):
379 ashish 365
        """
366
        Parameters:
367
        - catalog_item_id
368
        """
386 ashish 369
        log_entry(self, "item requested")
766 rajveer 370
        try:
4934 amit.gupta 371
            return get_thrift_item_list(get_items_by_catalog_id(catalog_item_id))
766 rajveer 372
        finally:
373
            close_session()
122 ashish 374
 
4934 amit.gupta 375
    def getValidItemsByCatalogId(self, catalog_item_id):
376
        """
377
        Parameters:
378
         - catalog_item_id
379
        """
380
        log_entry(self, "items requested for CatalogItem")
381
        try:
382
            return get_thrift_item_list(filter(is_valid, get_items_by_catalog_id(catalog_item_id)))
383
        finally:
384
            close_session()
385
 
5586 phani.kuma 386
    def isValidCatalogItemId(self, catalog_item_id):
387
        """
388
        Parameters:
389
         - catalog_item_id
390
        """
391
        try:
392
            return is_valid_catalog_id(catalog_item_id)
393
        finally:
394
            close_session()
395
 
122 ashish 396
    def getAllItems(self, isActive):
397
        """
398
        Parameters:
399
         - isActive
400
        """
401
        log_entry(self, "all items requested")
766 rajveer 402
        try:
403
            items = get_all_items(isActive)
404
            ret_items = []
405
            for item in items:
406
                if item:
407
                    ret_items.append(to_t_item(item))
408
            return ret_items
409
        finally:
410
            close_session()
411
 
122 ashish 412
    def getAllItemsByStatus(self, itemStatus):
413
        """
414
        Parameters:
415
         - itemStatus
416
        """
417
        log_entry(self, "all items requested")
766 rajveer 418
        try:
419
            items = get_all_items_by_status(itemStatus)
420
            ret_items = []
421
            for item in items:
422
                if item:
423
                    ret_items.append(to_t_item(item))
424
            return ret_items
425
        finally:
426
            close_session()
6821 amar.kumar 427
 
428
    def getAllAliveItems(self):
429
        """
430
        Parameters:
431
         - itemStatus
432
        """
433
        log_entry(self, "all non phased non deleted items requested")
434
        try:
435
            items = get_all_alive_items()
436
            ret_items = []
437
            for item in items:
438
                if item:
439
                    ret_items.append(to_t_item(item))
440
            return ret_items
441
        finally:
442
            close_session()
443
 
122 ashish 444
 
3348 varun.gupt 445
    def getAllBrandsByCategory(self, categoryId):
446
        """
447
        Parameters:
448
         - categoryId
449
        """
450
        try:
451
            return get_all_brands_by_category(categoryId)
452
        finally:
453
            close_session()
454
 
4957 phani.kuma 455
    def getAllBrands(self):
456
        try:
457
            return get_all_brands()
458
        finally:
459
            close_session()
5944 mandeep.dh 460
 
3849 chandransh 461
    def getAllItemsInRange(self, offset, limit):
462
        """
463
        Gets at most 'limit' items starting at the given offset. Returns an empty list if there are no more items at the given offset.
464
 
465
        Parameters:
466
         - offset
467
         - limit
468
        """
469
        try:
470
            items = get_all_items(False, offset, limit)
471
            return [to_t_item(item) for item in items]
472
        finally:
473
            close_session()
379 ashish 474
 
3849 chandransh 475
    def getAllItemsByStatusInRange(self, itemStatus, offset, limit):
476
        """
477
        Gets at most 'limit' items starting at the given offset in the given status. Returns an empty list if there are no more items at the given offset.
478
 
479
        Parameters:
480
         - itemStatus
481
         - offset
482
         - limit
483
        """
484
        log_entry(self, "all items requested")
485
        try:
486
            items = get_all_items_by_status(itemStatus, offset, limit)
487
            return [to_t_item(item) for item in items]
488
        finally:
489
            close_session()
490
 
491
    def getItemCountByStatus(self, useStatus, itemStatus):
492
        """
493
        Gets a count of all items by status
494
 
495
        Parameters:
496
         - useStatus
497
         - itemStatus
498
        """
499
        try:
500
            return get_item_count_by_status(useStatus, itemStatus)
501
        finally:
502
            close_session()
503
 
9253 rajveer 504
    def markItemAsContentComplete(self, entityId, category, brand, modelName, modelNumber, isAndroid):
2080 rajveer 505
        """
506
        Parameters:
507
         - entityId
508
         - category
509
         - brand
510
         - modelName
511
         - modelNumber
9253 rajveer 512
         - isAndroid
2080 rajveer 513
        """
514
        try:
9253 rajveer 515
            return mark_item_as_content_complete(entityId, category, brand, modelName, modelNumber, isAndroid)
2080 rajveer 516
        finally:
517
            close_session()
766 rajveer 518
 
122 ashish 519
    def updateItem(self, item):
520
        """
521
        Parameters:
522
         - item
523
        """
524
        log_entry(self, "addItem called")
766 rajveer 525
        try:
526
            return update_item(item)
527
        finally:
528
            close_session()
529
 
626 chandransh 530
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
766 rajveer 531
        try:
532
            if total_items is None:
533
                total_items = self.best_sellers_limit
534
            stop_index = start_index + total_items
535
            return get_best_sellers(start_index, stop_index, category)
536
        finally:
537
            close_session()
538
 
1926 rajveer 539
    def getBestSellersCatalogIds(self, start_index, total_items, brand, category=-1):
548 rajveer 540
        """
541
        Parameters:
542
         - beginIndex
543
         - totalItems
544
        """
766 rajveer 545
        try:
546
            if total_items is None:
547
                total_items = self.best_sellers_limit
548
            stop_index = start_index + total_items
1926 rajveer 549
            return get_best_sellers_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 550
        finally:
551
            close_session()
552
 
591 chandransh 553
    def getBestSellersCount(self, ):
766 rajveer 554
        try:
2093 chandransh 555
            return get_best_sellers_count()
766 rajveer 556
        finally:
557
            close_session()
558
 
591 chandransh 559
    def getBestDeals(self,):
766 rajveer 560
        try:
561
            return get_best_deals()
562
        finally:
563
            close_session()
564
 
1926 rajveer 565
    def getBestDealsCatalogIds(self, start_index, total_items, brand,category=-1):
548 rajveer 566
        """
567
        Parameters:
568
         - beginIndex
569
         - totalItems
570
        """
766 rajveer 571
        try:
572
            stop_index = start_index + total_items
1926 rajveer 573
            return get_best_deals_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 574
        finally:
575
            close_session()
576
 
591 chandransh 577
    def getBestDealsCount(self, ):
766 rajveer 578
        try:
579
            return get_best_deals_count()
580
        finally:
581
            close_session()
582
 
5217 amit.gupta 583
    def getComingSoon(self,):
584
        try:
585
            return get_coming_soon()
586
        finally:
587
            close_session()
588
 
589
    def getComingSoonCatalogIds(self, start_index, total_items, brand,category=-1):
590
        """
591
        Parameters:
592
         - beginIndex
593
         - totalItems
594
        """
595
        try:
596
            stop_index = start_index + total_items
597
            return get_coming_soon_catalog_ids(start_index, stop_index, brand, category)
598
        finally:
599
            close_session()
600
 
601
    def getComingSoonCount(self, ):
602
        try:
603
            return get_coming_soon_count()
604
        finally:
605
            close_session()
606
 
591 chandransh 607
    def getLatestArrivals(self,):
766 rajveer 608
        try:
609
            return get_latest_arrivals(self.latest_arrivals_limit)
610
        finally:
611
            close_session()
2975 chandransh 612
 
613
    def getLatestArrivalsCatalogIds(self, beginIndex, totalItems, brand, categories):
548 rajveer 614
        """
2975 chandransh 615
        Returns the list of catalog ids of latest arrivals in the given categories of the given brand.
616
        To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
617
 
548 rajveer 618
        Parameters:
619
         - beginIndex
620
         - totalItems
2975 chandransh 621
         - brand
622
         - categories
548 rajveer 623
        """
766 rajveer 624
        try:
2975 chandransh 625
            if beginIndex > self.latest_arrivals_limit:
766 rajveer 626
                return []
2975 chandransh 627
            stopIndex = beginIndex + totalItems
628
            if stopIndex > self.latest_arrivals_limit:
629
                stopIndex = self.latest_arrivals_limit
630
            return get_latest_arrivals_catalog_ids(beginIndex, stopIndex, brand, categories)
766 rajveer 631
        finally:
632
            close_session()
633
 
591 chandransh 634
    def getLatestArrivalsCount(self, ):
766 rajveer 635
        try:
636
            return get_latest_arrivals_count(self.latest_arrivals_limit)
637
        finally:
638
            close_session()
591 chandransh 639
 
1155 rajveer 640
    def generateNewEntityID(self, ):
641
        try:
642
            return generate_new_entity_id()
643
        finally:
644
            close_session()
645
 
635 rajveer 646
    def putCategoryObject(self, object):
647
        """
648
        Parameters:
649
         - object
650
        """
766 rajveer 651
        try:
652
            return put_category_object(object)
653
        finally:
654
            close_session()
655
 
635 rajveer 656
    def getCategoryObject(self, ):
766 rajveer 657
        try:
658
            return get_category_object()
659
        finally:
660
            close_session()
1970 rajveer 661
 
662
    def addCategory(self, category):
663
        """
664
        Parameters:
665
         - category
666
        """
667
        try:
668
            return add_category(category)
669
        finally:
670
            close_session()
671
 
672
    def getCategory(self, id):
673
        """
674
        Parameters:
675
         - id
676
        """
677
        try:
678
            return to_t_category(get_category(id))
679
        finally:
680
            close_session()
681
 
682
    def getAllCategories(self, ):
683
        try:
684
            categories = get_all_categories()
685
            return [to_t_category(category) for category in categories]
686
        finally:
687
            close_session()
4432 rajveer 688
 
4423 phani.kuma 689
    def getAllSimilarItems(self, itemId):
690
        """
691
        Returns list of similar items.
692
 
693
        Parameters:
694
         - itemId
695
        """
4432 rajveer 696
        try:
697
            return get_all_similar_items_catalog_ids(itemId)
698
        finally:
699
            close_session()
700
 
4423 phani.kuma 701
    def addSimilarItem(self, itemId, catalogItemId):
702
        """
703
        add similar item.
704
 
705
        Parameters:
706
         - itemId, catalogItemId
707
        """
708
        try:
709
            return add_similar_item_catalog_id(itemId, catalogItemId)
710
        finally:
711
            close_session()
712
 
713
    def deleteSimilarItem(self, itemId, catalogItemId):
714
        """
715
        delete similar items.
716
 
717
        Parameters:
718
         - itemId, catalogItemIds
719
        """
720
        try:
721
            return delete_similar_item_catalog_id(itemId, catalogItemId)
722
        finally:
723
            close_session()
4762 phani.kuma 724
 
5504 phani.kuma 725
    def getAllItemVouchers(self, itemId):
726
        """
727
        Returns list of vouchers.
728
 
729
        Parameters:
730
         - itemId
731
        """
732
        try:
733
            vouchers = get_all_vouchers_for_item(itemId)
734
            return [to_t_voucher_item_mapping(voucher) for voucher in vouchers]
735
        finally:
736
            close_session()
737
 
738
    def getVoucherAmount(self, itemId, voucherType):
739
        """
740
        Returns voucher amount.
741
 
742
        Parameters:
743
         - itemId, voucherType
744
        """
745
        try:
746
            return get_voucher_amount(itemId, voucherType)
747
        finally:
748
            close_session()
749
 
750
    def addupdateVoucherForItem(self, catalogItemId, voucherType, voucherAmount):
751
        """
752
        add or update voucher for item.
753
 
754
        Parameters:
755
         - catalogItemId, voucherType, voucherAmount
756
        """
757
        try:
758
            return add_update_voucher_for_item(catalogItemId, voucherType, voucherAmount)
759
        finally:
760
            close_session()
761
 
762
    def deleteVoucherForItem(self, catalogItemId, voucherType):
763
        """
764
        delete voucher for item.
765
 
766
        Parameters:
767
         - catalogItemId, voucherType
768
        """
769
        try:
770
            return delete_voucher_for_item(catalogItemId, voucherType)
771
        finally:
772
            close_session()
2116 ankur.sing 773
 
4725 phani.kuma 774
    def checkSimilarItem(self, brand, modelNumber, modelName, color):
2116 ankur.sing 775
        """
4725 phani.kuma 776
        Checks if similar item exists (with same Brand, ModelNumber, ModelName, Color)
2116 ankur.sing 777
        If yes, returns the itemId else returns 0
778
 
779
        Parameters:
780
         - brand
781
         - modelNumber
4725 phani.kuma 782
         - modelName
2116 ankur.sing 783
         - color
784
        """
785
        try:
4725 phani.kuma 786
            return check_similar_item(brand, modelNumber, modelName, color)
2116 ankur.sing 787
        finally:
788
            close_session()
789
 
2286 ankur.sing 790
    def changeItemRiskyFlag(self, itemId, risky):
791
        """
792
        Marks/Unmarks an item as risky. This flag is used for automatic marking of an item as INACTIVE in case of zero inventory.
793
 
794
        Parameters:
795
         - itemId
796
         - risky
797
        """
798
        try:
799
            change_risky_flag(itemId, risky)
800
        finally:
801
            close_session()
2116 ankur.sing 802
 
4957 phani.kuma 803
    def getItemsForMasterSheet(self, category, brand):
2358 ankur.sing 804
        """
4957 phani.kuma 805
        Returns list of items with any status except PHASED_OUT and filtered by category, brand.
2358 ankur.sing 806
 
807
        Parameters:
4762 phani.kuma 808
         - category
4957 phani.kuma 809
         - vendor
810
         - brand
2358 ankur.sing 811
        """
812
        try:
4957 phani.kuma 813
            return [to_t_item(item) for item in get_items_for_mastersheet(category, brand)]
2358 ankur.sing 814
        finally:
815
            close_session()
816
 
817
    def getItemsByRiskyFlag(self, ):
818
        """
819
        Returns list of items marked as risky.
820
        """
821
        try:
822
            return [to_t_item(item) for item in get_risky_items()]
823
        finally:
824
            close_session()
2809 rajveer 825
 
826
    def getSimilarItemsCatalogIds(self, beginIndex, totalItems, itemId):
827
        """
828
        Returns list of catalog ids of items with same similarity index as of the given itemId
829
 
830
        Parameters:
831
         - beginIndex
832
         - totalItems
833
         - itemId
834
        """
835
        try:
836
            return get_similar_items_catalog_ids(beginIndex, beginIndex+totalItems, itemId)
837
        finally:
838
            close_session()
3079 rajveer 839
 
840
    def addProductNotification(self, itemId, email):
841
        """
842
        Add user requests for out of stock items. Once user will ask for notify me an entry will
843
 
844
        Parameters:
845
        - itemId
846
        - email
847
        """
848
        try:
849
            return add_product_notification(itemId, email)
850
        finally:
851
            close_session()
2358 ankur.sing 852
 
3086 rajveer 853
    def sendProductNotifications(self, ):
854
        """
855
        Send the product notifications to the users for items which has stock.
856
        """
857
        try:
858
            return send_product_notifications()
859
        finally:
860
            close_session()
3557 rajveer 861
 
862
 
863
    def getAllSources(self, ):
864
        """
865
        Return list of all sources
866
        """
867
        try:
868
            return get_all_sources()
869
        finally:
870
            close_session()
871
 
872
    def getItemPricingBySource(self, itemId, sourceId):
873
        """
874
        Returns the pricing information of an item. If no information is found, exception will be thrown.
3376 rajveer 875
 
3557 rajveer 876
        Parameters:
877
         - itemId
878
         - sourceId
879
        """
880
        try:
881
            return to_t_source_item_pricing(get_item_pricing_by_source(itemId, sourceId))
882
        finally:
883
            close_session()
884
 
885
    def addSourceItemPricing(self, sourceItemPricing):
886
        """
887
        Adds prices to be displayed corresponding to the item if user comes from a source.
888
 
889
        Parameters:
890
         - sourceItemPricing
891
        """
892
        try:
893
            add_source_item_pricing(sourceItemPricing)
894
        finally:
895
            close_session()
896
 
897
    def getAllSourcePricing(self, itemId):
898
        """
899
        Returns the list of source pricing information of an item.
900
        Raises an exception if item not found corresponding to itemId
901
 
902
        Parameters:
903
         - itemId
904
        """
905
        try:
906
            return [to_t_source_item_pricing(source_item_pricing) for source_item_pricing in get_all_source_pricing(itemId)]
907
#        return [to_t_item(item) for item in get_risky_items()]
908
        finally:
909
            close_session()
910
 
911
    def getItemForSource(self, item_id, sourceId):
912
        """
913
        Parameters:
914
         - item_id
915
         - sourceId
916
        """
917
        try:
918
            return to_t_item(get_item_for_source(item_id, sourceId))
919
        finally:
920
            close_session()
3872 chandransh 921
 
922
    def searchItemsInRange(self, searchTerms, offset, limit):
923
        """
924
        Searches items matching the the given terms in the catalog
3557 rajveer 925
 
3872 chandransh 926
        Parameters:
927
         - searchTerms
928
        """
929
        try:
930
            return [to_t_item(item) for item in search_items(searchTerms, offset, limit)]
931
        finally:
932
            close_session()
933
 
934
    def getSearchResultCount(self, searchTerms):
935
        """
936
        Gets the count of search results for the given search terms so that the user can go through all the pages.
937
 
938
        Parameters:
939
         - searchTerms
940
        """
941
        try:
942
            return get_search_result_count(searchTerms)
943
        finally:
944
            close_session()
945
 
4295 varun.gupt 946
    def getProductNotifications(self, startDateTime):
947
        '''
948
        Returns a list of Product Notification objects each representing user requests for notification
949
        '''
950
        try:
951
            return [to_t_product_notification_request(notification) for notification in get_product_notifications(to_py_date(startDateTime))]
952
        finally:
953
            close_session()
954
 
7897 amar.kumar 955
    def getProductNotificationRequestCount(self, startDateTime,  categoryId):
4295 varun.gupt 956
        '''
957
        Returns list of items and the counts of product notification requests
958
        '''
959
        try:
7897 amar.kumar 960
            notification_request_counts = [(notification.item, count) for notification, count in get_product_notification_request_count(to_py_date(startDateTime), categoryId)]
4295 varun.gupt 961
 
962
            return [to_t_product_notification_request_count(count) for count in notification_request_counts]
963
 
964
        finally:
965
            close_session()
966
 
3376 rajveer 967
    def isAlive(self, ):
968
        """
969
        For checking weather service is active alive or not. It also checks connectivity with database
970
        """
971
        try:
972
            return is_alive()
973
        finally:
974
            close_session()
975
 
766 rajveer 976
    def closeSession(self, ):
3376 rajveer 977
        """
978
        For closing the open session in sqlalchemy
979
        """
4332 anupam.sin 980
        close_session()
981
 
4649 phani.kuma 982
    def addAuthorizationLog(self, itemId, username, reason):
983
        """
984
        add a log to authorize table.
985
 
986
        Parameters:
987
         - itemId, username, reason
988
        """
989
        try:
990
            return add_authorization_log_for_item(itemId, username, reason)
991
        finally:
4934 amit.gupta 992
            close_session()
5110 mandeep.dh 993
 
7330 amit.gupta 994
    def getVatPercentageForItem(self, itemId, stateId, price):
6039 amit.gupta 995
        """
996
        get Vat percentage for item for item
997
        """
998
        try:
7340 amit.gupta 999
            return get_vat_percentage_for_item(itemId, stateId, price)
6039 amit.gupta 1000
        finally:
1001
            close_session()
1002
 
1003
    def getVatAmountForItem(self, itemId, price):
1004
        """
1005
        get Vat amount for item
1006
        """
1007
        try:
1008
            return get_vat_amount_for_item(itemId,price)
1009
        finally:
1010
            close_session()
1011
 
5944 mandeep.dh 1012
    def validateRiskyStatus(self, itemId):
5712 mandeep.dh 1013
        """
5944 mandeep.dh 1014
        Check wether item is risky and change status if inventory is not available for risky items
5712 mandeep.dh 1015
        """
1016
        try:
5944 mandeep.dh 1017
            return check_risky_item(itemId)
5712 mandeep.dh 1018
        finally:
1019
            close_session()
6532 amit.gupta 1020
 
1021
    def getAllIgnoredInventoryUpdateItemsList(self,offset, limit):
1022
        try:
1023
            return get_all_ignored_inventoryupdate_items_list(offset,limit)
1024
        finally:
6921 anupam.sin 1025
            close_session()
6805 anupam.sin 1026
 
6921 anupam.sin 1027
    def getInsuranceAmount(self, itemId, price, insurerId, quantity):
6805 anupam.sin 1028
        try:
6921 anupam.sin 1029
            return get_insurance_amount(itemId, price, insurerId, quantity)
6805 anupam.sin 1030
        finally:
6921 anupam.sin 1031
            close_session()
6805 anupam.sin 1032
 
1033
    def getInsurer(self, insurerId):
1034
        try:
1035
            return to_t_insurer(get_insurer(insurerId))
1036
        finally:
6838 vikram.rag 1037
            close_session()
1038
 
1039
    def getAllInsurers(self):
1040
        try:
1041
            insurers = []
1042
            all_insurers = get_all_insurers()
1043
            for insurer in all_insurers:
1044
                insurers.append(to_t_insurer(insurer))
6921 anupam.sin 1045
            return insurers
6838 vikram.rag 1046
        finally:
1047
            close_session()
9299 kshitij.so 1048
 
1049
    def getPrefferedInsurerForItem(self, itemId, insurerType):
1050
        try:
1051
            return get_preffered_insurer_for_item(itemId, insurerType)
1052
        finally:
1053
            close_session()
6962 rajveer 1054
 
1055
    def updateInsuranceDeclaredAmount(self, insurerId, amount):
1056
        try:
1057
            update_insurance_declared_amount(insurerId, amount)
1058
        finally:
1059
            close_session()
5944 mandeep.dh 1060
 
6845 amit.gupta 1061
    def getAllEntityTags(self):
1062
        try:
1063
            return get_all_entity_tags()
1064
        finally:
1065
            close_session()
1066
 
7190 amar.kumar 1067
    def getFreebieForItem(self, itemId):
1068
        try:
1069
            return get_freebie_for_item(itemId)
1070
        finally:
1071
            close_session()
1072
 
1073
    def addOrUpdateFreebieForItem(self, freebieItem):
1074
        try:
1075
            return add_or_update_freebie_for_item(freebieItem)
1076
        finally:
1077
            close_session()
7291 vikram.rag 1078
 
7272 amit.gupta 1079
    def addOrUpdateBrandInfo(self, brandInfo):
1080
        try:
1081
            return add_or_update_brand_info(brandInfo)
1082
        finally:
1083
            close_session()
1084
 
1085
    def getBrandInfo(self):
1086
        try:
1087
            return get_brand_info()
1088
        finally:
1089
            close_session()
1090
 
7256 rajveer 1091
    def getStorePricing(self, itemId):
1092
        try:
1093
            return get_store_pricing(itemId)
1094
        finally:
1095
            close_session()
1096
 
7306 rajveer 1097
    def getStorePricings(self, itemIds):
1098
        try:
1099
            return [get_store_pricing(itemId) for itemId in itemIds]
1100
        finally:
1101
            close_session()
1102
 
7382 rajveer 1103
    def updateStorePricing(self, sp, allColors):
7265 rajveer 1104
        try:
7382 rajveer 1105
            return update_store_pricing(sp, allColors)
7265 rajveer 1106
        finally:
1107
            close_session()
7190 amar.kumar 1108
 
7281 kshitij.so 1109
    def getAmazonItemDetails(self, amazonItemId):
1110
        try:
8362 kshitij.so 1111
            result = to_t_Amazonlisted(get_amazon_item_details(amazonItemId))
7281 kshitij.so 1112
        finally:
1113
            close_session()
1114
            return result
1115
 
8168 kshitij.so 1116
    def updateAmazonItemDetails(self,amazonlisted):
7281 kshitij.so 1117
        try:
8168 kshitij.so 1118
            update_amazon_item_details(amazonlisted)
7281 kshitij.so 1119
        finally:
1120
            close_session()
1121
 
1122
    def addAmazonItem(self,amazonlisted):
1123
        try:
1124
            print amazonlisted
1125
            add_amazon_item(amazonlisted)
1126
        finally:
1127
            close_session()
1128
 
7291 vikram.rag 1129
    def getAsinItems(self):
1130
        try:
1131
            items = get_asin_items()
1132
            ret_items = []
1133
            for item in items:
1134
                if item:
1135
                    ret_items.append(to_t_item(item))
1136
            return ret_items
1137
        finally:
1138
            close_session()
7281 kshitij.so 1139
 
7291 vikram.rag 1140
    def getAllFbaListedItems(self):
1141
        try:
1142
            items = get_all_fba_listed_items()
1143
            ret_items = []
1144
            for item in items:
1145
                if item:
1146
                    ret_items.append(to_t_Amazonlisted(item))
1147
            return ret_items
1148
        finally:
1149
            close_session()
1150
 
1151
    def getAllNonFbaListedItems(self):
1152
        try:
1153
            items = get_all_nonfba_listed_items()
1154
            ret_items = []
1155
            for item in items:
1156
                if item:
1157
                    ret_items.append(to_t_Amazonlisted(item))
1158
            return ret_items
1159
        finally:
1160
            close_session()
1161
 
1162
 
1163
    def getAllAmazonListedItems(self):      
1164
        try:
1165
            amazonlisteditems = []
1166
            all_listed = get_all_amazon_listed_items()
1167
            for amazonlisteditem in all_listed:
1168
                amazonlisteditems.append(to_t_Amazonlisted(amazonlisteditem))
1169
            return amazonlisteditems
1170
        finally:
8139 kshitij.so 1171
            close_session()           
7291 vikram.rag 1172
 
7460 kshitij.so 1173
    def updateItemInventory(self,itemId,holdInventory,defaultInventory):
1174
        try:
1175
            update_item_inventory(itemId,holdInventory,defaultInventory)
1176
            return True
1177
        finally:
1178
            close_session()
7291 vikram.rag 1179
 
7770 kshitij.so 1180
    def updateTimestampForAmazonFeeds(self,feedType,skuList,timestamp):
1181
        try:
1182
            return update_timestamp_for_amazon_feeds(feedType,skuList,timestamp)
1183
        finally:
1184
            close_session()
1185
 
7897 amar.kumar 1186
    def  getAllParentCategories(self):
1187
        try:
1188
            categories = get_all_parent_categories()
1189
            return [to_t_category(category) for category in categories]
1190
        finally:
1191
            close_session()
1192
 
7977 kshitij.so 1193
    def addPageViewEvent(self,pageEvent):
1194
        try:
1195
            print "csh"
1196
            add_page_view_event(pageEvent)
1197
        finally:
1198
            close_session()
1199
 
1200
    def addCartEvent(self,cartEvent):
1201
        try:
1202
            add_cart_event(cartEvent)
1203
        finally:
1204
            close_session()
8182 amar.kumar 1205
 
1206
    def addEbayItem(self, ebayItem):
1207
        try:
1208
            insert_ebay_item(ebayItem)
1209
        finally:
1210
            close_session()
1211
 
1212
    def getEbayItem(self, listingId):
1213
        try:
1214
            return to_t_ebay_item(get_ebay_item(listingId))
1215
        finally:
1216
            close_session()
7977 kshitij.so 1217
 
8182 amar.kumar 1218
    def updateEbayItem(self, ebayItem):
1219
        try:
1220
            update_ebay_item(ebayItem)
1221
        finally:
1222
            close_session()
1223
 
8168 kshitij.so 1224
    def updateAmazonAttributesInBulk(self,amazonlisted):
1225
        try:
1226
            return update_amazon_attributes_in_bulk(amazonlisted)
1227
        finally:
1228
            close_session()
8139 kshitij.so 1229
 
8379 vikram.rag 1230
    def getAllItemstoListOnFba(self):
1231
        try:
1232
            fba_items = []
1233
            for item in get_all_items_to_list_on_fba():
1234
                fba_items.append(to_t_Amazonlisted(item))
1235
            return fba_items
1236
        finally:
1237
            close_session()
1238
 
1239
    def getAllItemstoListOnNonFba(self):
1240
        try:
1241
            non_fba_items = []
1242
            for item in get_all_items_to_list_on_nonfba():
1243
                non_fba_items.append(to_t_Amazonlisted(item))
1244
            return non_fba_items
1245
        finally:
1246
            close_session()
8619 kshitij.so 1247
 
1248
    def getAmazonListedItems(self,offset,limit):
1249
        try:
1250
            amazonlisteditems = []
1251
            all_listed = get_amazon_listed_items(offset,limit)
1252
            for amazonlisteditem in all_listed:
1253
                amazonlisteditems.append(to_t_Amazonlisted(amazonlisteditem))
1254
        finally:
1255
            close_session()
1256
            return amazonlisteditems
1257
 
1258
    def searchAmazonItems(self,searchTerms,offset,limit):
1259
        try:
1260
            amazonlisteditems = []
1261
            search_result = search_amazon_items(searchTerms,offset,limit)
1262
            for amazonlisteditem in search_result:
1263
                amazonlisteditems.append(to_t_Amazonlisted(amazonlisteditem))
1264
        finally:
1265
            close_session()
1266
            return amazonlisteditems
1267
 
1268
    def getAmazonSearchResultCount(self,searchTerms):
1269
        try:
1270
            return get_amazon_search_result_count(searchTerms)
1271
        finally:
1272
            close_session()
1273
 
1274
    def getCountForAmazonlistedItems(self):
1275
        try:
1276
            return get_count_for_amazonlisted_items()
1277
        finally:
1278
            close_session()
1279
 
1280
    def updateAsin(self,amazonAsinMap):
1281
        try:
1282
            update_asin(amazonAsinMap)
1283
        finally:
1284
            close_session()
8168 kshitij.so 1285
 
8739 vikram.rag 1286
    def addOrUpdateSnapdealItem(self,snapdealitem):
1287
        try:
1288
            return add_or_update_snapdeal_item(snapdealitem)
1289
        finally:    
1290
            close_session()
1291
 
1292
    def getSnapdealItem(self,item_id):
1293
        try:
1294
            return to_t_snapdeal_item(get_snapdeal_item(item_id))
1295
        finally:
1296
            close_session()
9242 kshitij.so 1297
 
1298
    def getSnapdealItemDetails(self,item_id):
1299
        try:
9724 kshitij.so 1300
            snapdealItem, snapdealInventory = get_snapdeal_item_detail(item_id)
1301
            return to_t_snapdeal_item_details(snapdealItem, snapdealInventory)
9242 kshitij.so 1302
        finally:
1303
            close_session()
8739 vikram.rag 1304
 
1305
    def getAllSnapdealItems(self):
1306
        try:
1307
            items = get_all_snapdeal_items() 
9724 kshitij.so 1308
            return [to_t_snapdeal_item_details(item,None) for item in items]
8739 vikram.rag 1309
        finally:
9242 kshitij.so 1310
            close_session()
8739 vikram.rag 1311
 
9242 kshitij.so 1312
    def getSnapdealItems(self,offset,limit):
1313
        try:
1314
            items = get_snapdeal_items(offset,limit) 
9724 kshitij.so 1315
            return [to_t_snapdeal_item_details(item,None) for item in items]
9242 kshitij.so 1316
        finally:
1317
            close_session()
1318
 
1319
    def searchSnapdealItems(self,searchterm,offset,limit):
1320
        try:
1321
            snapdealitems = []
1322
            search_result = search_snapdeal_items(searchterm,offset,limit)
1323
            for snapdealitem in search_result:
9724 kshitij.so 1324
                snapdealitems.append(to_t_snapdeal_item_details(snapdealitem,None))
9242 kshitij.so 1325
        finally:
1326
            close_session()
1327
            return snapdealitems
1328
 
1329
    def getCountForSnapdealItems(self):
1330
        try:
1331
            return get_count_for_snapdeal_items()
1332
        finally:
1333
            close_session()
1334
 
1335
 
1336
    def getSnapdealSearchResultCount(self,searchterms):
1337
        try:
1338
            return get_snapdeal_search_result_count(searchterms)
1339
        finally:
1340
            close_session()
1341
 
9456 vikram.rag 1342
    def getSnapdealItembySkuAtSnapdeal(self,skuatsnapdeal):
1343
        try:
1344
            return to_t_snapdeal_item(get_snapdealitem_by_skuatsnapdeal(skuatsnapdeal))
1345
        finally:
9724 kshitij.so 1346
            close_session()
1347
 
1348
    def getMarketplacedetailsForItem(self,itemId,sourceId):
1349
        try:
1350
            return to_t_marketplace_items(get_marketplace_details_for_item(itemId,sourceId))
1351
        finally:
1352
            close_session()
1353
 
1354
    def updateMarketplaceAttributesForItem(self,marketplaceItem):
1355
        try:
1356
            return update_marketplace_attributes_for_item(marketplaceItem)
1357
        finally:
1358
            close_session() 
9456 vikram.rag 1359
 
9621 manish.sha 1360
    def getProductFeedSubmit(self, catalog_itemId):
1361
        try:
1362
            return to_t_product_feed_submit(get_product_feed_submit(catalog_itemId))
1363
        finally:
1364
            close_session()
1365
 
1366
    def addProductFeedSubmit(self, productFeedSubmit):
1367
        try:
1368
            return add_product_feed_submit(productFeedSubmit)
1369
        finally:
1370
            close_session()
1371
 
1372
    def updateProductFeedSubmit(self, productFeedSubmit):
1373
        try:
1374
            return update_product_feed_submit(productFeedSubmit)
1375
        finally:
1376
            close_session()
1377
 
1378
    def deleteProductFeedSubmit(self, catalog_itemId):
1379
        try:
1380
            return delete_product_feed_submit(catalog_itemId)
1381
        finally:
1382
            close_session()
9779 kshitij.so 1383
 
1384
    def getCostingForMarketplace(self, source, item_id):
1385
        try:
1386
            return to_t_marketplacepercentage(get_costing_for_marketplace(source, item_id))
1387
        finally:
1388
            close_session()
9621 manish.sha 1389
 
1390
    def getAllProductFeedSubmit(self):
1391
        try:
1392
            log_entry(self, "all ProductFeedSubmit requested")
1393
            feedSubmits = get_all_product_feed_submit()
1394
            ret_feedSubmits = []
1395
            for feedSubmit in feedSubmits:
1396
                if feedSubmit:
1397
                    ret_feedSubmits.append(to_t_product_feed_submit(feedSubmit))
1398
            return ret_feedSubmits
1399
        finally:
9776 vikram.rag 1400
            close_session()
1401
 
1402
    def getMarketPlaceItemsForPriceUpdate(self,source):
1403
        try:
1404
            items = get_all_marketplace_items_for_priceupdate(source) 
1405
            return [to_t_marketplace_itemprice(item) for item in items]
1406
        finally:
1407
            close_session()
9621 manish.sha 1408
 
9816 kshitij.so 1409
    def updateMarketPlacePriceUpdateStatus(self,skulist,timestamp,source):
9776 vikram.rag 1410
        try:
9816 kshitij.so 1411
            update_marketplace_priceupdate_status(skulist,timestamp,source)
9776 vikram.rag 1412
        finally:
1413
            close_session()
9895 vikram.rag 1414
 
9861 rajveer 1415
    def updateItemHoldInventory(self,itemHoldMap):
1416
        try:
1417
            update_item_hold_inventory(itemHoldMap)
1418
        finally:
9895 vikram.rag 1419
            close_session()        
1420
 
1421
    def updateNlcAtMarketplaces(self,item_id,vendor_id,nlc):
1422
        try:
1423
            update_nlc_at_marketplaces(item_id,vendor_id,nlc)
1424
        finally:
9861 rajveer 1425
            close_session()
9945 vikram.rag 1426
 
1427
    def getAllFlipkartItems(self):
1428
        try:
1429
            return [to_t_flipkart_item(item) for item in get_all_flipkart_items()]
1430
        finally:
1431
            close_session()
9895 vikram.rag 1432
 
10097 kshitij.so 1433
    def getFlipkartItem(self,item_id):
1434
        try:
1435
            return to_t_flipkart_item(get_flipkart_item(item_id))
1436
        finally:
1437
            close_session()
1438
 
1439
    def addOrUpdateFlipkartItem(self,flipkartitem):
1440
        try:
1441
            return add_or_update_flipkart_item(flipkartitem)
1442
        finally:    
1443
            close_session()
1444
 
1445
    def getFlipkartItemDetails(self,item_id):
1446
        try:
1447
            flipkartitem, flipkartInventory = get_flipkart_item_detail(item_id)
1448
            return to_t_flipkart_item_details(flipkartitem, flipkartInventory)
1449
        finally:
1450
            close_session()
1451
 
1452
    def getFlipkartItems(self,offset,limit):
1453
        try:
1454
            items = get_flipkart_items(offset,limit) 
1455
            return [to_t_flipkart_item_details(item,None) for item in items]
1456
        finally:
1457
            close_session()
1458
 
1459
    def searchFlipkartItems(self,searchterm,offset,limit):
1460
        try:
1461
            flipkartitems = []
1462
            search_result = search_flipkart_items(searchterm,offset,limit)
1463
            for flipkartitem in search_result:
1464
                flipkartitems.append(to_t_flipkart_item_details(flipkartitem,None))
1465
        finally:
1466
            close_session()
1467
            return flipkartitems
1468
 
1469
    def getCountForFlipkartItems(self):
1470
        try:
1471
            return get_count_for_flipkart_items()
1472
        finally:
1473
            close_session()
1474
 
1475
    def getFlipkartSearchResultCount(self,searchterms):
1476
        try:
1477
            return get_flipkart_search_result_count(searchterms)
1478
        finally:
1479
            close_session()
1480
 
1481
    def getAllFkItems(self):
1482
        try:
1483
            return [to_t_flipkart_item_details(item,None) for item in get_all_fk_items()]
1484
        finally:
1485
            close_session()
1486
 
10140 vikram.rag 1487
    def getFlipkartItemBySkyAtFlipkart(self,sku):
10909 vikram.rag 1488
        return to_t_flipkart_item(get_flipkart_item_by_sku_at_flipkart(sku))
10140 vikram.rag 1489
 
10909 vikram.rag 1490
    def getAllFbbListedItems(self):
10913 vikram.rag 1491
        try:
10909 vikram.rag 1492
            items = get_all_fbb_listed_items()
1493
            ret_items = []
1494
            for item in items:
1495
                if item:
1496
                    ret_items.append(to_t_Amazonlisted(item))
1497
            return ret_items
1498
        finally:
1499
            close_session()
10924 vikram.rag 1500
 
1501
    def getAllFbbPricingItems(self):
1502
        try:
1503
            items = get_all_fbb_pricing_items()
1504
            ret_items = []
1505
            for item in items:
1506
                if item:
1507
                    ret_items.append(to_t_Amazonlisted(item))
1508
            return ret_items
1509
        finally:
1510
            close_session()
1511
 
10909 vikram.rag 1512
 
9776 vikram.rag 1513
if __name__ == '__main__':
1514
    items = get_all_alive_items()
1515
    ret_items = []
1516
    for item in items:
1517
        if item:
1518
            ret_items.append(to_t_item(item))
1519
    print ret_items
1520
 
1521
 
4934 amit.gupta 1522
def is_valid(item):
1523
    if item.status in [status.ACTIVE, status.PAUSED, status.PAUSED_BY_RISK]:
4936 amit.gupta 1524
        if item.startDate:
1525
            return not(datetime.datetime.now() < item.startDate or item.sellingPrice == 0)
1526
        else:
1527
            return True
6256 rajveer 1528
    elif item.status == status.COMING_SOON:
1529
        return True
1530
    else:
10909 vikram.rag 1531
        return False