Subversion Repositories SmartDukaan

Rev

Rev 6039 | Rev 6511 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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