Subversion Repositories SmartDukaan

Rev

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