Subversion Repositories SmartDukaan

Rev

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