Subversion Repositories SmartDukaan

Rev

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