Subversion Repositories SmartDukaan

Rev

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