Subversion Repositories SmartDukaan

Rev

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