Subversion Repositories SmartDukaan

Rev

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