Subversion Repositories SmartDukaan

Rev

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