Subversion Repositories SmartDukaan

Rev

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