Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
122 ashish 1
'''
2
Created on 27-Apr-2010
3
 
4
@author: ashish
5
'''
5110 mandeep.dh 6
from shop2020.config.client.ConfigClient import ConfigClient
6511 kshitij.so 7
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_category, \
8
    to_t_source_item_pricing, to_t_product_notification_request, \
6848 kshitij.so 9
    to_t_product_notification_request_count, to_t_voucher_item_mapping, to_t_insurer, \
6850 kshitij.so 10
    to_t_banner,to_t_banner_map, \
6845 amit.gupta 11
    to_t_product_notification_request_count, to_t_voucher_item_mapping, to_t_insurer
6511 kshitij.so 12
from shop2020.model.v1.catalog.impl.DataAcessors import add_item, retire_item, \
13
    change_item_status, get_item, get_all_items, get_all_items_by_status, \
5944 mandeep.dh 14
    update_item, start_item_on, close_session, retire_item_on, \
5110 mandeep.dh 15
    get_items_by_catalog_id, get_best_deals, get_best_deals_catalog_ids, \
16
    get_best_deals_count, get_best_sellers, get_latest_arrivals, \
17
    get_latest_arrivals_catalog_ids, get_latest_arrivals_count, is_active, \
18
    get_best_sellers_catalog_ids, get_best_sellers_count, put_category_object, \
5944 mandeep.dh 19
    get_category_object, mark_item_as_content_complete, generate_new_entity_id, \
20
    get_category, get_all_categories, add_category, get_item_status_description, \
6511 kshitij.so 21
    check_similar_item, change_risky_flag, get_items_for_mastersheet, \
22
    get_risky_items, get_similar_items_catalog_ids, add_product_notification, \
23
    send_product_notifications, get_all_brands_by_category, is_alive, \
24
    get_item_pricing_by_source, add_source_item_pricing, get_all_sources, \
25
    get_item_for_source, get_all_source_pricing, get_item_count_by_status, \
26
    search_items, get_search_result_count, get_product_notifications, \
27
    get_product_notification_request_count, get_all_similar_items_catalog_ids, \
28
    add_similar_item_catalog_id, delete_similar_item_catalog_id, \
29
    add_authorization_log_for_item, get_thrift_item_list, get_all_brands, \
30
    get_coming_soon, get_coming_soon_catalog_ids, get_coming_soon_count, initialize, \
7256 rajveer 31
    add_update_voucher_for_item, \
6511 kshitij.so 32
    delete_voucher_for_item, get_voucher_amount, get_all_vouchers_for_item, \
33
    is_valid_catalog_id, check_risky_item, get_vat_percentage_for_item, \
6532 amit.gupta 34
    get_vat_amount_for_item, add_tag, get_all_tags, get_all_entities_by_tag_name, \
6848 kshitij.so 35
    delete_tag, delete_entity_tag, get_all_ignored_inventoryupdate_items_list,add_banner,get_all_banners, \
36
    delete_banner,get_banner_details,get_active_banners,add_banner_map,delete_banner_map,get_banner_map_details, \
6962 rajveer 37
    get_insurance_amount, get_insurer, get_all_alive_items,get_all_insurers, get_all_entity_tags,\
7256 rajveer 38
    update_insurance_declared_amount, get_freebie_for_item, add_or_update_freebie_for_item,\
7265 rajveer 39
    get_store_pricing, update_store_pricing
5944 mandeep.dh 40
from shop2020.thriftpy.model.v1.catalog.ttypes import status
41
from shop2020.utils.Utils import log_entry, to_py_date
5110 mandeep.dh 42
import datetime
122 ashish 43
 
5944 mandeep.dh 44
class CatalogServiceHandler:
122 ashish 45
    '''
46
    classdocs
47
    '''
599 chandransh 48
 
3187 rajveer 49
    def __init__(self, dbname='catalog', db_hostname='localhost'):
122 ashish 50
        '''
51
        Constructor
52
        '''
5295 rajveer 53
        initialize(dbname, db_hostname)
599 chandransh 54
        try:
621 chandransh 55
            config_client = ConfigClient()
56
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
57
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
599 chandransh 58
        except:
621 chandransh 59
            self.latest_arrivals_limit = 50
60
            self.best_sellers_limit = 50
122 ashish 61
 
62
    #DONE
63
    def addItem(self, item):
64
        """
65
        Availability and inventory attributes
66
 
67
        Parameters:
68
         - item
69
        """
70
        log_entry(self, "addItem called")
785 rajveer 71
        try:
72
            return add_item(item)
73
        finally:
74
            close_session()
6511 kshitij.so 75
 
76
 
77
    def addTag(self, displayName, catalogId):
78
        result = False
79
        try:
80
            return add_tag(displayName, catalogId)
81
        except:
82
            result = True
83
        finally:
84
            close_session()
85
            return result
6848 kshitij.so 86
 
87
    def addBanner(self, bannerName, imageName,link, priority, isActive, hasMap):
88
        result = False
89
        try:
90
            return add_banner(bannerName, imageName, link, priority, isActive, hasMap)
91
        except:
92
            result = True
93
        finally:
94
            close_session()
95
            return result
96
 
97
    def getAllBanners(self):
98
        result = []
99
        try:
100
            result = get_all_banners()
101
        except:
102
            result = False
103
        finally:
104
            close_session()
105
            return result
106
 
107
    def deleteBanner(self,name):
108
        result = True
109
        try:
110
            return delete_banner(name)
111
        except:
112
            result = False
113
        finally:
114
            close_session()
115
            return result
116
 
117
    def getBannerDetails(self, name):
118
        print "I am called"
119
        result = None
120
        try:
121
            result = get_banner_details(name)
122
            print 'result is',
123
            print result
124
            if result is not None:
125
                result = to_t_banner(result)
126
        except:
127
            print "Some error"
128
            return None
129
        finally:
130
            print "Finally here"
131
            print result
132
            close_session()
133
            return result
134
 
135
    def getActiveBanners(self):
136
        result =None
137
        banners=[]
138
        try:
139
            print "Handler"
140
            results = get_active_banners()
141
            for result in results:
142
                if result is not None:
143
                    result = to_t_banner(result)
144
                    print "After conversion",
145
                    banners.append(result)
146
 
147
        except:
148
            return None
149
        finally:
150
            print "Banners list",
151
            print banners
152
            close_session()
153
            return banners
154
 
155
    def addBannerMap(self, bannerName, mapLink, coordinates):
156
        result = True
157
        try:
158
            return add_banner_map(bannerName, mapLink, coordinates)
159
        except:
160
            result = False
161
        finally:
162
            close_session()
163
            return result
164
 
165
    def deleteBannerMap(self, name):
166
        result = True
167
        try:
168
            return delete_banner_map(name)
169
        except:
170
            result = False
171
        finally:
172
            close_session()
173
            return result
174
 
175
    def getBannerMapDetails(self,name):
176
        result =None
177
        banners=[]
178
        try:
179
            results = get_banner_map_details(name)
180
            for result in results:
181
                if result is not None:
182
                    result = to_t_banner_map(result)
183
                    banners.append(result)
184
        except:
185
            return None
186
        finally:
187
            close_session()
188
            return banners
189
 
190
 
6511 kshitij.so 191
 
192
    def getAllTags(self):
193
        result = []
194
        try:
195
            result = get_all_tags()
196
        except:
197
            result = True
198
        finally:
199
            close_session()
200
            return result
201
 
202
    def getAllEntitiesByTagName(self,displayName):
203
        result = []
204
        try:
205
            result = get_all_entities_by_tag_name(displayName)
206
        except:
207
            result = True
208
        finally:
209
            close_session()
210
            return result
211
 
212
    def deleteTag(self,displayName):
213
        result = False
214
        try:
215
            return delete_tag(displayName)
216
        except:
217
            result = True
218
        finally:
219
            close_session()
220
            return result
221
 
6518 kshitij.so 222
    def deleteEntityTag(self,displayName,catalogId):
223
        result = False
224
        try:
225
            return delete_entity_tag(displayName,catalogId)
226
        except:
227
            result = True
228
        finally:
229
            close_session()
230
            return result
231
 
635 rajveer 232
    def isActive(self, item_id):
563 chandransh 233
        """
234
        Parameters:
635 rajveer 235
         - item_id
563 chandransh 236
        """
785 rajveer 237
        try:
238
            return is_active(item_id)
239
        finally:
240
            close_session()
122 ashish 241
 
2035 rajveer 242
    def getItemStatusDescription(self, itemId):
243
        """
244
        Parameters:
245
         - itemId
246
        """
247
        try:
248
            return get_item_status_description(itemId)
249
        finally:
250
            close_session()
122 ashish 251
 
252
    def retireItem(self, item_id):
253
        """
254
        Parameters:
255
        - item_id
256
        """
257
        log_entry(self, "retire item called")
785 rajveer 258
        try:
259
            return retire_item(item_id)
260
        finally:
261
            close_session()
122 ashish 262
 
263
    def startItemOn(self, item_id, timestamp):
264
        """
265
        Parameters:
266
         - item_id
267
         - timestamp
268
        """
785 rajveer 269
        try:
270
            start_item_on(item_id, timestamp)
271
        finally:
272
            close_session()
122 ashish 273
 
274
    def retireItemOn(self, item_id, timestamp):
275
        """
276
        Parameters:
277
         - item_id
278
         - timestamp
279
        """
785 rajveer 280
        try:
281
            retire_item_on(item_id, timestamp)
282
        finally:
283
            close_session()
122 ashish 284
 
285
    def changeItemStatus(self, item_id, timestamp, newstatus):
286
        """
287
        Parameters:
288
         - item_id
289
         - timestamp
290
         - newstatus
291
        """
292
        log_entry(self, "change item status called")
785 rajveer 293
        try:
294
            return change_item_status(item_id, newstatus)
295
        finally:
296
            close_session()
122 ashish 297
 
785 rajveer 298
 
122 ashish 299
    def getItem(self, item_id):
300
        """
301
        Parameters:
302
         - item_id
303
        """
304
        log_entry(self, "item requested")
785 rajveer 305
        try:
2065 ankur.sing 306
            item = to_t_item( get_item(item_id))
307
            return item
785 rajveer 308
        finally:
309
            close_session()
379 ashish 310
 
635 rajveer 311
    def getItemsByCatalogId(self, catalog_item_id):
379 ashish 312
        """
313
        Parameters:
314
        - catalog_item_id
315
        """
386 ashish 316
        log_entry(self, "item requested")
766 rajveer 317
        try:
4934 amit.gupta 318
            return get_thrift_item_list(get_items_by_catalog_id(catalog_item_id))
766 rajveer 319
        finally:
320
            close_session()
122 ashish 321
 
4934 amit.gupta 322
    def getValidItemsByCatalogId(self, catalog_item_id):
323
        """
324
        Parameters:
325
         - catalog_item_id
326
        """
327
        log_entry(self, "items requested for CatalogItem")
328
        try:
329
            return get_thrift_item_list(filter(is_valid, get_items_by_catalog_id(catalog_item_id)))
330
        finally:
331
            close_session()
332
 
5586 phani.kuma 333
    def isValidCatalogItemId(self, catalog_item_id):
334
        """
335
        Parameters:
336
         - catalog_item_id
337
        """
338
        try:
339
            return is_valid_catalog_id(catalog_item_id)
340
        finally:
341
            close_session()
342
 
122 ashish 343
    def getAllItems(self, isActive):
344
        """
345
        Parameters:
346
         - isActive
347
        """
348
        log_entry(self, "all items requested")
766 rajveer 349
        try:
350
            items = get_all_items(isActive)
351
            ret_items = []
352
            for item in items:
353
                if item:
354
                    ret_items.append(to_t_item(item))
355
            return ret_items
356
        finally:
357
            close_session()
358
 
122 ashish 359
    def getAllItemsByStatus(self, itemStatus):
360
        """
361
        Parameters:
362
         - itemStatus
363
        """
364
        log_entry(self, "all items requested")
766 rajveer 365
        try:
366
            items = get_all_items_by_status(itemStatus)
367
            ret_items = []
368
            for item in items:
369
                if item:
370
                    ret_items.append(to_t_item(item))
371
            return ret_items
372
        finally:
373
            close_session()
6821 amar.kumar 374
 
375
    def getAllAliveItems(self):
376
        """
377
        Parameters:
378
         - itemStatus
379
        """
380
        log_entry(self, "all non phased non deleted items requested")
381
        try:
382
            items = get_all_alive_items()
383
            ret_items = []
384
            for item in items:
385
                if item:
386
                    ret_items.append(to_t_item(item))
387
            return ret_items
388
        finally:
389
            close_session()
390
 
122 ashish 391
 
3348 varun.gupt 392
    def getAllBrandsByCategory(self, categoryId):
393
        """
394
        Parameters:
395
         - categoryId
396
        """
397
        try:
398
            return get_all_brands_by_category(categoryId)
399
        finally:
400
            close_session()
401
 
4957 phani.kuma 402
    def getAllBrands(self):
403
        try:
404
            return get_all_brands()
405
        finally:
406
            close_session()
5944 mandeep.dh 407
 
3849 chandransh 408
    def getAllItemsInRange(self, offset, limit):
409
        """
410
        Gets at most 'limit' items starting at the given offset. Returns an empty list if there are no more items at the given offset.
411
 
412
        Parameters:
413
         - offset
414
         - limit
415
        """
416
        try:
417
            items = get_all_items(False, offset, limit)
418
            return [to_t_item(item) for item in items]
419
        finally:
420
            close_session()
379 ashish 421
 
3849 chandransh 422
    def getAllItemsByStatusInRange(self, itemStatus, offset, limit):
423
        """
424
        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.
425
 
426
        Parameters:
427
         - itemStatus
428
         - offset
429
         - limit
430
        """
431
        log_entry(self, "all items requested")
432
        try:
433
            items = get_all_items_by_status(itemStatus, offset, limit)
434
            return [to_t_item(item) for item in items]
435
        finally:
436
            close_session()
437
 
438
    def getItemCountByStatus(self, useStatus, itemStatus):
439
        """
440
        Gets a count of all items by status
441
 
442
        Parameters:
443
         - useStatus
444
         - itemStatus
445
        """
446
        try:
447
            return get_item_count_by_status(useStatus, itemStatus)
448
        finally:
449
            close_session()
450
 
2080 rajveer 451
    def markItemAsContentComplete(self, entityId, category, brand, modelName, modelNumber):
452
        """
453
        Parameters:
454
         - entityId
455
         - category
456
         - brand
457
         - modelName
458
         - modelNumber
459
        """
460
        try:
461
            return mark_item_as_content_complete(entityId, category, brand, modelName, modelNumber)
462
        finally:
463
            close_session()
766 rajveer 464
 
122 ashish 465
    def updateItem(self, item):
466
        """
467
        Parameters:
468
         - item
469
        """
470
        log_entry(self, "addItem called")
766 rajveer 471
        try:
472
            return update_item(item)
473
        finally:
474
            close_session()
475
 
626 chandransh 476
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
766 rajveer 477
        try:
478
            if total_items is None:
479
                total_items = self.best_sellers_limit
480
            stop_index = start_index + total_items
481
            return get_best_sellers(start_index, stop_index, category)
482
        finally:
483
            close_session()
484
 
1926 rajveer 485
    def getBestSellersCatalogIds(self, start_index, total_items, brand, category=-1):
548 rajveer 486
        """
487
        Parameters:
488
         - beginIndex
489
         - totalItems
490
        """
766 rajveer 491
        try:
492
            if total_items is None:
493
                total_items = self.best_sellers_limit
494
            stop_index = start_index + total_items
1926 rajveer 495
            return get_best_sellers_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 496
        finally:
497
            close_session()
498
 
591 chandransh 499
    def getBestSellersCount(self, ):
766 rajveer 500
        try:
2093 chandransh 501
            return get_best_sellers_count()
766 rajveer 502
        finally:
503
            close_session()
504
 
591 chandransh 505
    def getBestDeals(self,):
766 rajveer 506
        try:
507
            return get_best_deals()
508
        finally:
509
            close_session()
510
 
1926 rajveer 511
    def getBestDealsCatalogIds(self, start_index, total_items, brand,category=-1):
548 rajveer 512
        """
513
        Parameters:
514
         - beginIndex
515
         - totalItems
516
        """
766 rajveer 517
        try:
518
            stop_index = start_index + total_items
1926 rajveer 519
            return get_best_deals_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 520
        finally:
521
            close_session()
522
 
591 chandransh 523
    def getBestDealsCount(self, ):
766 rajveer 524
        try:
525
            return get_best_deals_count()
526
        finally:
527
            close_session()
528
 
5217 amit.gupta 529
    def getComingSoon(self,):
530
        try:
531
            return get_coming_soon()
532
        finally:
533
            close_session()
534
 
535
    def getComingSoonCatalogIds(self, start_index, total_items, brand,category=-1):
536
        """
537
        Parameters:
538
         - beginIndex
539
         - totalItems
540
        """
541
        try:
542
            stop_index = start_index + total_items
543
            return get_coming_soon_catalog_ids(start_index, stop_index, brand, category)
544
        finally:
545
            close_session()
546
 
547
    def getComingSoonCount(self, ):
548
        try:
549
            return get_coming_soon_count()
550
        finally:
551
            close_session()
552
 
591 chandransh 553
    def getLatestArrivals(self,):
766 rajveer 554
        try:
555
            return get_latest_arrivals(self.latest_arrivals_limit)
556
        finally:
557
            close_session()
2975 chandransh 558
 
559
    def getLatestArrivalsCatalogIds(self, beginIndex, totalItems, brand, categories):
548 rajveer 560
        """
2975 chandransh 561
        Returns the list of catalog ids of latest arrivals in the given categories of the given brand.
562
        To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
563
 
548 rajveer 564
        Parameters:
565
         - beginIndex
566
         - totalItems
2975 chandransh 567
         - brand
568
         - categories
548 rajveer 569
        """
766 rajveer 570
        try:
2975 chandransh 571
            if beginIndex > self.latest_arrivals_limit:
766 rajveer 572
                return []
2975 chandransh 573
            stopIndex = beginIndex + totalItems
574
            if stopIndex > self.latest_arrivals_limit:
575
                stopIndex = self.latest_arrivals_limit
576
            return get_latest_arrivals_catalog_ids(beginIndex, stopIndex, brand, categories)
766 rajveer 577
        finally:
578
            close_session()
579
 
591 chandransh 580
    def getLatestArrivalsCount(self, ):
766 rajveer 581
        try:
582
            return get_latest_arrivals_count(self.latest_arrivals_limit)
583
        finally:
584
            close_session()
591 chandransh 585
 
1155 rajveer 586
    def generateNewEntityID(self, ):
587
        try:
588
            return generate_new_entity_id()
589
        finally:
590
            close_session()
591
 
635 rajveer 592
    def putCategoryObject(self, object):
593
        """
594
        Parameters:
595
         - object
596
        """
766 rajveer 597
        try:
598
            return put_category_object(object)
599
        finally:
600
            close_session()
601
 
635 rajveer 602
    def getCategoryObject(self, ):
766 rajveer 603
        try:
604
            return get_category_object()
605
        finally:
606
            close_session()
1970 rajveer 607
 
608
    def addCategory(self, category):
609
        """
610
        Parameters:
611
         - category
612
        """
613
        try:
614
            return add_category(category)
615
        finally:
616
            close_session()
617
 
618
    def getCategory(self, id):
619
        """
620
        Parameters:
621
         - id
622
        """
623
        try:
624
            return to_t_category(get_category(id))
625
        finally:
626
            close_session()
627
 
628
    def getAllCategories(self, ):
629
        try:
630
            categories = get_all_categories()
631
            return [to_t_category(category) for category in categories]
632
        finally:
633
            close_session()
4432 rajveer 634
 
4423 phani.kuma 635
    def getAllSimilarItems(self, itemId):
636
        """
637
        Returns list of similar items.
638
 
639
        Parameters:
640
         - itemId
641
        """
4432 rajveer 642
        try:
643
            return get_all_similar_items_catalog_ids(itemId)
644
        finally:
645
            close_session()
646
 
4423 phani.kuma 647
    def addSimilarItem(self, itemId, catalogItemId):
648
        """
649
        add similar item.
650
 
651
        Parameters:
652
         - itemId, catalogItemId
653
        """
654
        try:
655
            return add_similar_item_catalog_id(itemId, catalogItemId)
656
        finally:
657
            close_session()
658
 
659
    def deleteSimilarItem(self, itemId, catalogItemId):
660
        """
661
        delete similar items.
662
 
663
        Parameters:
664
         - itemId, catalogItemIds
665
        """
666
        try:
667
            return delete_similar_item_catalog_id(itemId, catalogItemId)
668
        finally:
669
            close_session()
4762 phani.kuma 670
 
5504 phani.kuma 671
    def getAllItemVouchers(self, itemId):
672
        """
673
        Returns list of vouchers.
674
 
675
        Parameters:
676
         - itemId
677
        """
678
        try:
679
            vouchers = get_all_vouchers_for_item(itemId)
680
            return [to_t_voucher_item_mapping(voucher) for voucher in vouchers]
681
        finally:
682
            close_session()
683
 
684
    def getVoucherAmount(self, itemId, voucherType):
685
        """
686
        Returns voucher amount.
687
 
688
        Parameters:
689
         - itemId, voucherType
690
        """
691
        try:
692
            return get_voucher_amount(itemId, voucherType)
693
        finally:
694
            close_session()
695
 
696
    def addupdateVoucherForItem(self, catalogItemId, voucherType, voucherAmount):
697
        """
698
        add or update voucher for item.
699
 
700
        Parameters:
701
         - catalogItemId, voucherType, voucherAmount
702
        """
703
        try:
704
            return add_update_voucher_for_item(catalogItemId, voucherType, voucherAmount)
705
        finally:
706
            close_session()
707
 
708
    def deleteVoucherForItem(self, catalogItemId, voucherType):
709
        """
710
        delete voucher for item.
711
 
712
        Parameters:
713
         - catalogItemId, voucherType
714
        """
715
        try:
716
            return delete_voucher_for_item(catalogItemId, voucherType)
717
        finally:
718
            close_session()
2116 ankur.sing 719
 
4725 phani.kuma 720
    def checkSimilarItem(self, brand, modelNumber, modelName, color):
2116 ankur.sing 721
        """
4725 phani.kuma 722
        Checks if similar item exists (with same Brand, ModelNumber, ModelName, Color)
2116 ankur.sing 723
        If yes, returns the itemId else returns 0
724
 
725
        Parameters:
726
         - brand
727
         - modelNumber
4725 phani.kuma 728
         - modelName
2116 ankur.sing 729
         - color
730
        """
731
        try:
4725 phani.kuma 732
            return check_similar_item(brand, modelNumber, modelName, color)
2116 ankur.sing 733
        finally:
734
            close_session()
735
 
2286 ankur.sing 736
    def changeItemRiskyFlag(self, itemId, risky):
737
        """
738
        Marks/Unmarks an item as risky. This flag is used for automatic marking of an item as INACTIVE in case of zero inventory.
739
 
740
        Parameters:
741
         - itemId
742
         - risky
743
        """
744
        try:
745
            change_risky_flag(itemId, risky)
746
        finally:
747
            close_session()
2116 ankur.sing 748
 
4957 phani.kuma 749
    def getItemsForMasterSheet(self, category, brand):
2358 ankur.sing 750
        """
4957 phani.kuma 751
        Returns list of items with any status except PHASED_OUT and filtered by category, brand.
2358 ankur.sing 752
 
753
        Parameters:
4762 phani.kuma 754
         - category
4957 phani.kuma 755
         - vendor
756
         - brand
2358 ankur.sing 757
        """
758
        try:
4957 phani.kuma 759
            return [to_t_item(item) for item in get_items_for_mastersheet(category, brand)]
2358 ankur.sing 760
        finally:
761
            close_session()
762
 
763
    def getItemsByRiskyFlag(self, ):
764
        """
765
        Returns list of items marked as risky.
766
        """
767
        try:
768
            return [to_t_item(item) for item in get_risky_items()]
769
        finally:
770
            close_session()
2809 rajveer 771
 
772
    def getSimilarItemsCatalogIds(self, beginIndex, totalItems, itemId):
773
        """
774
        Returns list of catalog ids of items with same similarity index as of the given itemId
775
 
776
        Parameters:
777
         - beginIndex
778
         - totalItems
779
         - itemId
780
        """
781
        try:
782
            return get_similar_items_catalog_ids(beginIndex, beginIndex+totalItems, itemId)
783
        finally:
784
            close_session()
3079 rajveer 785
 
786
    def addProductNotification(self, itemId, email):
787
        """
788
        Add user requests for out of stock items. Once user will ask for notify me an entry will
789
 
790
        Parameters:
791
        - itemId
792
        - email
793
        """
794
        try:
795
            return add_product_notification(itemId, email)
796
        finally:
797
            close_session()
2358 ankur.sing 798
 
3086 rajveer 799
    def sendProductNotifications(self, ):
800
        """
801
        Send the product notifications to the users for items which has stock.
802
        """
803
        try:
804
            return send_product_notifications()
805
        finally:
806
            close_session()
3557 rajveer 807
 
808
 
809
    def getAllSources(self, ):
810
        """
811
        Return list of all sources
812
        """
813
        try:
814
            return get_all_sources()
815
        finally:
816
            close_session()
817
 
818
    def getItemPricingBySource(self, itemId, sourceId):
819
        """
820
        Returns the pricing information of an item. If no information is found, exception will be thrown.
3376 rajveer 821
 
3557 rajveer 822
        Parameters:
823
         - itemId
824
         - sourceId
825
        """
826
        try:
827
            return to_t_source_item_pricing(get_item_pricing_by_source(itemId, sourceId))
828
        finally:
829
            close_session()
830
 
831
    def addSourceItemPricing(self, sourceItemPricing):
832
        """
833
        Adds prices to be displayed corresponding to the item if user comes from a source.
834
 
835
        Parameters:
836
         - sourceItemPricing
837
        """
838
        try:
839
            add_source_item_pricing(sourceItemPricing)
840
        finally:
841
            close_session()
842
 
843
    def getAllSourcePricing(self, itemId):
844
        """
845
        Returns the list of source pricing information of an item.
846
        Raises an exception if item not found corresponding to itemId
847
 
848
        Parameters:
849
         - itemId
850
        """
851
        try:
852
            return [to_t_source_item_pricing(source_item_pricing) for source_item_pricing in get_all_source_pricing(itemId)]
853
#        return [to_t_item(item) for item in get_risky_items()]
854
        finally:
855
            close_session()
856
 
857
    def getItemForSource(self, item_id, sourceId):
858
        """
859
        Parameters:
860
         - item_id
861
         - sourceId
862
        """
863
        try:
864
            return to_t_item(get_item_for_source(item_id, sourceId))
865
        finally:
866
            close_session()
3872 chandransh 867
 
868
    def searchItemsInRange(self, searchTerms, offset, limit):
869
        """
870
        Searches items matching the the given terms in the catalog
3557 rajveer 871
 
3872 chandransh 872
        Parameters:
873
         - searchTerms
874
        """
875
        try:
876
            return [to_t_item(item) for item in search_items(searchTerms, offset, limit)]
877
        finally:
878
            close_session()
879
 
880
    def getSearchResultCount(self, searchTerms):
881
        """
882
        Gets the count of search results for the given search terms so that the user can go through all the pages.
883
 
884
        Parameters:
885
         - searchTerms
886
        """
887
        try:
888
            return get_search_result_count(searchTerms)
889
        finally:
890
            close_session()
891
 
4295 varun.gupt 892
    def getProductNotifications(self, startDateTime):
893
        '''
894
        Returns a list of Product Notification objects each representing user requests for notification
895
        '''
896
        try:
897
            return [to_t_product_notification_request(notification) for notification in get_product_notifications(to_py_date(startDateTime))]
898
        finally:
899
            close_session()
900
 
901
    def getProductNotificationRequestCount(self, startDateTime):
902
        '''
903
        Returns list of items and the counts of product notification requests
904
        '''
905
        try:
906
            notification_request_counts = [(notification.item, count) for notification, count in get_product_notification_request_count(to_py_date(startDateTime))]
907
 
908
            return [to_t_product_notification_request_count(count) for count in notification_request_counts]
909
 
910
        finally:
911
            close_session()
912
 
3376 rajveer 913
    def isAlive(self, ):
914
        """
915
        For checking weather service is active alive or not. It also checks connectivity with database
916
        """
917
        try:
918
            return is_alive()
919
        finally:
920
            close_session()
921
 
766 rajveer 922
    def closeSession(self, ):
3376 rajveer 923
        """
924
        For closing the open session in sqlalchemy
925
        """
4332 anupam.sin 926
        close_session()
927
 
4649 phani.kuma 928
    def addAuthorizationLog(self, itemId, username, reason):
929
        """
930
        add a log to authorize table.
931
 
932
        Parameters:
933
         - itemId, username, reason
934
        """
935
        try:
936
            return add_authorization_log_for_item(itemId, username, reason)
937
        finally:
4934 amit.gupta 938
            close_session()
5110 mandeep.dh 939
 
6039 amit.gupta 940
    def getVatPercentageForItem(self, itemId, price):
941
        """
942
        get Vat percentage for item for item
943
        """
944
        try:
945
            return get_vat_percentage_for_item(itemId, price)
946
        finally:
947
            close_session()
948
 
949
    def getVatAmountForItem(self, itemId, price):
950
        """
951
        get Vat amount for item
952
        """
953
        try:
954
            return get_vat_amount_for_item(itemId,price)
955
        finally:
956
            close_session()
957
 
5944 mandeep.dh 958
    def validateRiskyStatus(self, itemId):
5712 mandeep.dh 959
        """
5944 mandeep.dh 960
        Check wether item is risky and change status if inventory is not available for risky items
5712 mandeep.dh 961
        """
962
        try:
5944 mandeep.dh 963
            return check_risky_item(itemId)
5712 mandeep.dh 964
        finally:
965
            close_session()
6532 amit.gupta 966
 
967
    def getAllIgnoredInventoryUpdateItemsList(self,offset, limit):
968
        try:
969
            return get_all_ignored_inventoryupdate_items_list(offset,limit)
970
        finally:
6921 anupam.sin 971
            close_session()
6805 anupam.sin 972
 
6921 anupam.sin 973
    def getInsuranceAmount(self, itemId, price, insurerId, quantity):
6805 anupam.sin 974
        try:
6921 anupam.sin 975
            return get_insurance_amount(itemId, price, insurerId, quantity)
6805 anupam.sin 976
        finally:
6921 anupam.sin 977
            close_session()
6805 anupam.sin 978
 
979
    def getInsurer(self, insurerId):
980
        try:
981
            return to_t_insurer(get_insurer(insurerId))
982
        finally:
6838 vikram.rag 983
            close_session()
984
 
985
    def getAllInsurers(self):
986
        try:
987
            insurers = []
988
            all_insurers = get_all_insurers()
989
            for insurer in all_insurers:
990
                insurers.append(to_t_insurer(insurer))
6921 anupam.sin 991
            return insurers
6838 vikram.rag 992
        finally:
993
            close_session()
6962 rajveer 994
 
995
    def updateInsuranceDeclaredAmount(self, insurerId, amount):
996
        try:
997
            update_insurance_declared_amount(insurerId, amount)
998
        finally:
999
            close_session()
5944 mandeep.dh 1000
 
6845 amit.gupta 1001
    def getAllEntityTags(self):
1002
        try:
1003
            return get_all_entity_tags()
1004
        finally:
1005
            close_session()
1006
 
7190 amar.kumar 1007
    def getFreebieForItem(self, itemId):
1008
        try:
1009
            return get_freebie_for_item(itemId)
1010
        finally:
1011
            close_session()
1012
 
1013
    def addOrUpdateFreebieForItem(self, freebieItem):
1014
        try:
1015
            return add_or_update_freebie_for_item(freebieItem)
1016
        finally:
1017
            close_session()
7256 rajveer 1018
 
7272 amit.gupta 1019
    def addOrUpdateBrandInfo(self, brandInfo):
1020
        try:
1021
            return add_or_update_brand_info(brandInfo)
1022
        finally:
1023
            close_session()
1024
 
1025
    def getBrandInfo(self):
1026
        try:
1027
            return get_brand_info()
1028
        finally:
1029
            close_session()
1030
 
7256 rajveer 1031
    def getStorePricing(self, itemId):
1032
        try:
1033
            return get_store_pricing(itemId)
1034
        finally:
1035
            close_session()
1036
 
7265 rajveer 1037
    def updateStorePricing(self, sp):
1038
        try:
1039
            return update_store_pricing(sp)
1040
        finally:
1041
            close_session()
7190 amar.kumar 1042
 
4934 amit.gupta 1043
def is_valid(item):
1044
    if item.status in [status.ACTIVE, status.PAUSED, status.PAUSED_BY_RISK]:
4936 amit.gupta 1045
        if item.startDate:
1046
            return not(datetime.datetime.now() < item.startDate or item.sellingPrice == 0)
1047
        else:
1048
            return True
6256 rajveer 1049
    elif item.status == status.COMING_SOON:
1050
        return True
1051
    else:
7190 amar.kumar 1052
        return False
1053
 
1054
if __name__ == '__main__':
1055
    items = get_all_alive_items()
1056
    ret_items = []
1057
    for item in items:
1058
        if item:
1059
            ret_items.append(to_t_item(item))
1060
    print ret_items