Subversion Repositories SmartDukaan

Rev

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