Subversion Repositories SmartDukaan

Rev

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