Subversion Repositories SmartDukaan

Rev

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