Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
104 ashish 1
'''
2
Created on 29-Mar-2010
3
 
4
@author: ashish
5
'''
6056 amit.gupta 6
from elixir import session
7363 rajveer 7
from shop2020.model.v1.order.impl import DataService, RedExpressUpdateService,\
8
    RechargeService
6000 mandeep.dh 9
from shop2020.model.v1.order.impl.Convertors import to_t_transaction, to_t_alert, \
10
    to_t_order, to_t_lineitem, to_t_payment_settlement, to_t_verification_agent, \
7311 kshitij.so 11
    to_t_attribute, to_t_rechargeTransaction, to_t_frc, to_t_hotspot, to_t_sourcedetail, \
7967 anupam.sin 12
    to_t_amazonorder, to_t_storeOrderDetail, to_t_storeOrderCollection, \
8488 amar.kumar 13
    to_t_hotspotServiceMatrix, to_t_ebayOrder, to_t_amazonFbaSalesSnapshot, \
8990 vikram.rag 14
    to_t_snapdealOrder, to_t_flipkartOrder
8282 kshitij.so 15
 
6000 mandeep.dh 16
from shop2020.model.v1.order.impl.DataAccessors import create_transaction, \
17
    get_transactions_for_customer, get_transaction_status, get_line_items_for_order, \
18
    get_transaction, get_transactions_for_shopping_cart_id, \
19
    change_transaction_status, get_orders_for_customer, get_orders_for_transaction, \
20
    get_order, get_returnable_orders_for_customer, \
21
    get_cancellable_orders_for_customer, get_orders_by_billing_date, get_all_orders, \
22
    change_order_status, get_alerts, add_alert, add_billing_details, close_session, \
23
    accept_order, mark_orders_as_picked_up, mark_orders_as_delivered, \
24
    mark_orders_as_rto, order_outofstock, batch_orders, update_non_delivery_reason, \
25
    enqueue_transaction_info_email, get_undelivered_orders, get_order_for_customer, \
26
    get_valid_order_count, get_cust_count_with_successful_txn, \
27
    get_valid_orders_amount_range, get_valid_orders, toggle_doa_flag, \
28
    request_pickup_number, authorize_pickup, receive_return, validate_doa, \
29
    reship_order, refund_order, get_return_orders, process_return, get_return_order, \
30
    mark_doas_as_picked_up, verify_order, is_alive, get_orders_by_shipping_date, \
31
    update_weight, change_warehouse, change_product, add_delay_reason, \
32
    reconcile_cod_collection, get_transactions_requiring_extra_processing, \
33
    mark_transaction_as_processed, get_item_wise_risky_orders_count, \
34
    accept_order_for_item, get_orders_in_batch, get_order_count, \
35
    get_ebs_settlement_summaries, mark_order_cancellation_request_received, \
36
    mark_order_cancellation_request_denied, refund_transaction, \
37
    mark_order_cancellation_request_confirmed, \
38
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id, \
39
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated, \
40
    mark_orders_as_not_available, update_shipment_address, mark_orders_as_timeout, \
41
    get_order_for_awb, mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
42
    mark_order_doa_request_received, mark_order_doa_request_authorized, \
43
    mark_order_return_request_received, mark_order_return_request_authorized, \
44
    add_invoice_number, get_reshipped_order_ids, validate_return_product, \
45
    get_orders_for_provider_for_status, save_ebs_settlement_summary, \
46
    get_ebs_settlement_date, save_payment_settlements, mark_ebs_settlement_uploaded, \
47
    get_billed_orders_for_vendor, get_settlement_for_Prepaid, \
48
    get_settlements_by_date, get_slipped_sipping_date_orders, \
49
    mark_order_as_lost_in_transit, get_cancelled_orders, mark_order_as_delivered, \
50
    mark_return_orders_as_picked_up, update_orders_as_PORaised, \
51
    get_order_distribution_by_status, get_orders_not_met_expected_delivery_date, \
52
    mark_orders_as_local_connected, mark_orders_as_destinationCityReached, \
53
    mark_orders_as_firstDeliveryAttempted, get_non_delivered_orders_by_courier, \
54
    get_orders_not_local_connected, get_doas_not_picked_up, \
55
    get_return_orders_not_picked_up, get_orders_not_picked_up, get_rto_orders, \
56
    get_order_list, get_order_ids_for_status, update_orders_as_paid_to_vendor, \
57
    update_COD_agent, get_refunded_orders_marked_paid, get_settlement_for_Cod, \
58
    get_order_list_for_vendor, update_order_only_as_paid_to_vendor, \
59
    get_all_verification_agents, get_all_attributes_for_order_id, \
60
    set_order_attribute_for_transaction, get_billed_orders, get_all_return_orders, \
61
    mark_order_as_received_at_store, get_receive_pending_orders, \
62
    get_received_at_store_orders, mark_orders_as_returned_from_store, \
6056 amit.gupta 63
    set_order_attributes, get_orders_collection_at_store, get_order_attribute_value, \
64
    change_jacket_number, mark_order_as_rto_in_transit, get_recharge_order, \
65
    get_recharge_orders, update_recharge_order_status, activate_recharge_txn, \
66
    get_user_wallet, get_user_wallet_history, get_service_providers, \
6396 amit.gupta 67
    get_service_provider_for_device, get_recharge_orders_for_transaction, \
68
    update_amount_in_wallet, get_recharge_orders_for_device, \
69
    get_recharge_orders_for_status, get_plans_for_operator, get_recharge_statistics, \
70
    validate_recharge, get_recharge_denominations, update_availability_status, \
6821 amar.kumar 71
    get_misc_charges, get_available_emi_schemes, refund_recharge_order, \
7073 anupam.sin 72
    create_recharge_transaction, get_physical_orders, get_document, retrieve_invoice, \
7125 amit.gupta 73
    change_shipping_address, get_recharge_transactions, get_recharge_transaction, \
7151 amit.gupta 74
    get_frcs, get_hotspot_store, get_circle, retrieve_hotspot_recharge_invoice, \
7190 amar.kumar 75
    get_recharge_trans, split_freebie_order, get_recharge_transactions_by_number, \
7285 rajveer 76
    update_hotspot_store_password, get_source_detail, get_all_circles, delete_frcs,\
7311 kshitij.so 77
    topup_company_wallet, get_wallet_balance_for_company, \
7343 anupam.sin 78
    add_amazon_order, update_amazon_order_status,get_amazon_order, get_amazon_orders_shipped, \
7371 anupam.sin 79
    get_amazon_orders_cancelled, get_orders_for_store, get_store_order_advance_invoice, add_frc, \
7393 anupam.sin 80
    add_series, get_store_order_detail, save_store_order_detail, get_all_edc_banks, \
7442 vikram.rag 81
    save_refund_amounts_for_store_order, get_collections_for_store,get_amazon_orders_to_acknowledge, \
7607 anupam.sin 82
    change_amazon_order_status,update_timestamp_for_amazon_order,update_source_detail_timestamp, \
83
    get_amazon_order_by_amazonorderid, get_orders_by_mobile_number, get_orders_by_amazon_id, \
7967 anupam.sin 84
    change_courier_provider, convert_store_to_normal, update_freebie_item, update_order_AWB, \
8182 amar.kumar 85
    get_hotspot_service_matrices, get_orders_by_vendor, create_ebay_order, \
86
    get_ebay_order_by_sales_rec_number, get_ebay_order_by_orderId, update_ebay_order, \
8488 amar.kumar 87
    ebay_order_exists, update_order_for_ebay, get_ebay_order, split_ebay_order, \
88
    add_or_update_amazon_fba_sales_snapshot, get_amazon_fba_sales_snapshot_for_days, \
89
    get_amazon_fba_sales_latest_snapshot_for_item, create_snapdeal_order, \
8961 vikram.rag 90
    get_snapdeal_order, snapdeal_order_exists, update_latest_fba_prices_for_item , \
9159 amar.kumar 91
    flipkart_order_exists, create_flipkart_order, get_flipkart_order, get_flipkart_order_by_subOrderId, \
9404 vikram.rag 92
    update_flipkart_order_dates_and_awb,get_order_for_airwayBillNo, \
9651 manish.sha 93
    get_orders_count_created_after_timestamp_for_source, get_min_created_timestamp_undelivered_orders_for_source, \
9801 manish.sha 94
    update_snapdeal_orders_status, update_flipkart_orders_status, bulk_add_or_update_amazon_fba_sales_snapshot
7343 anupam.sin 95
 
6000 mandeep.dh 96
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
6056 amit.gupta 97
from shop2020.model.v1.order.impl.model.DigitalTransaction import \
98
    DigitalTransaction
6000 mandeep.dh 99
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
100
    MobileRechargeOrder
101
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
7442 vikram.rag 102
    RechargeType,AmazonOrdersToAcknowledge
6000 mandeep.dh 103
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
6031 rajveer 104
import datetime
8182 amar.kumar 105
from shop2020.helpers.impl.DataAccessor import close_session
8488 amar.kumar 106
from shop2020.model.v1.user.impl.Converters import to_t_address
1405 ankur.sing 107
 
5527 anupam.sin 108
 
104 ashish 109
 
110
class OrderServiceHandler:
111
 
3187 rajveer 112
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 113
        """
104 ashish 114
        Constructor
483 rajveer 115
        """
3187 rajveer 116
        DataService.initialize(dbname, db_hostname)
104 ashish 117
 
118
    def createTransaction(self, transaction):
119
        """
120
        Parameters:
121
         - transaction
122
        """
766 rajveer 123
        try:
124
            return create_transaction(transaction)
125
        finally:
126
            close_session()
127
 
104 ashish 128
    def getTransaction(self, id):
129
        """
130
            Get transaction methods.
131
 
132
        Parameters:
133
         - id
134
        """
766 rajveer 135
        try:
136
            transaction = get_transaction(id)
137
            return to_t_transaction(transaction)
138
        finally:
139
            close_session()
140
 
483 rajveer 141
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 142
        """
143
        Parameters:
483 rajveer 144
         - customerId
104 ashish 145
         - from_date
146
         - to_date
483 rajveer 147
         - status
104 ashish 148
        """
766 rajveer 149
        try:
150
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
151
 
152
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
153
            t_transaction = []
154
            for transaction in transactions:
155
                t_transaction.append(to_t_transaction(transaction))
156
            return t_transaction
157
        finally:
158
            close_session()
483 rajveer 159
 
160
    def getTransactionsForShoppingCartId(self, shoppingCartId):
161
        """
162
        Parameters:
163
            - shoppingCartId
164
        """
766 rajveer 165
        try:
166
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
167
            t_transaction = []
168
            for transaction in transactions:
169
                t_transaction.append(to_t_transaction(transaction))
170
            return t_transaction
171
        finally:
172
            close_session()
104 ashish 173
 
483 rajveer 174
    def getTransactionStatus(self, transactionId):
104 ashish 175
        """
176
        Parameters:
483 rajveer 177
         - transactionId
178
        """
766 rajveer 179
        try:
180
            return get_transaction_status(transactionId)
181
        finally:
182
            close_session()
183
 
7293 anupam.sin 184
    def changeTransactionStatus(self, transactionId, status, description, pickUp, orderType, source):
483 rajveer 185
        """
186
        Parameters:
187
         - transactionId
104 ashish 188
         - status
483 rajveer 189
         - description
5387 rajveer 190
         - selfPickup
483 rajveer 191
        """
766 rajveer 192
        try:
7293 anupam.sin 193
            return change_transaction_status(transactionId, status, description, pickUp, orderType, source)
766 rajveer 194
        finally:
195
            close_session()
196
 
1528 ankur.sing 197
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 198
        """
1528 ankur.sing 199
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
200
        only user who owns the transaction can view its order details.
201
 
483 rajveer 202
        Parameters:
203
         - transactionId
1528 ankur.sing 204
         - customerId
483 rajveer 205
        """
766 rajveer 206
        try:
1528 ankur.sing 207
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 208
            return [to_t_order(order) for order in orders]    
209
        finally:
210
            close_session()
211
 
4801 anupam.sin 212
    def getAllOrders(self, statuses, from_date, to_date, warehouse_id):
483 rajveer 213
        """
214
        Parameters:
215
         - status
104 ashish 216
         - from_date
217
         - to_date
483 rajveer 218
         - warehouse_id
104 ashish 219
        """
766 rajveer 220
        try:
221
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
4801 anupam.sin 222
            orders = get_all_orders(statuses, current_from_date, current_to_date, warehouse_id)
766 rajveer 223
            return [to_t_order(order) for order in orders]
224
        finally:
225
            close_session()
4133 chandransh 226
 
8303 amar.kumar 227
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id, source):
4133 chandransh 228
        """
229
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
230
        Pass the status as null and the limit as 0 to ignore them.
231
 
232
        Parameters:
233
         - statuses
234
         - offset
235
         - limit
236
         - warehouse_id
237
        """
238
        try:
8303 amar.kumar 239
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id, source)
4133 chandransh 240
            return [to_t_order(order) for order in orders]
241
        finally:
242
            close_session()
243
 
8303 amar.kumar 244
    def getOrderCount(self, statuses, warehouseId, source):
4133 chandransh 245
        """
246
        Returns the count of orders with the given statuses assigned to the given warehouse.
247
 
248
        Parameters:
249
         - statuses
250
         - warehouseId
251
        """
252
        try:
8303 amar.kumar 253
            return get_order_count(statuses, warehouseId, source)
4133 chandransh 254
        finally:
255
            close_session()
256
 
995 varun.gupt 257
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
258
        """
259
        Parameters:
260
         - status
261
         - start_billing_date
262
         - end_billing_date
263
         - warehouse_id
264
        """
265
        try:
266
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
267
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
268
            return [to_t_order(order) for order in orders]
269
        finally:
270
            close_session()
1382 varun.gupt 271
 
3451 chandransh 272
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 273
        """
274
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 275
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
276
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 277
 
278
        Parameters:
279
         - fromShippingDate
280
         - toShippingDate
281
         - providerId
282
         - warehouseId
3451 chandransh 283
         - cod
3427 chandransh 284
        """
285
        try:
286
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 287
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 288
            return [to_t_order(order) for order in orders]
289
        finally:
290
            close_session()
291
 
1382 varun.gupt 292
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
293
        """
294
        Parameters:
295
         - customerId
296
         - limit
297
        """
298
        try:
299
            return get_returnable_orders_for_customer(customerId, limit)
300
        finally:
301
            close_session()
995 varun.gupt 302
 
1382 varun.gupt 303
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
304
        """
305
        Parameters:
306
         - customerId
307
         - limit
308
        """
309
        try:
310
            return get_cancellable_orders_for_customer(customerId, limit)
311
        finally:
312
            close_session()
313
 
483 rajveer 314
    def changeOrderStatus(self, orderId, status, description):
315
        """
316
        Parameters:
317
         - orderId
318
         - status
319
         - description
320
         - 
321
        """
766 rajveer 322
        try:
323
            return change_order_status(self, orderId, status, description)
324
        finally:
325
            close_session()
921 rajveer 326
 
3064 chandransh 327
    def verifyOrder(self, orderId):
328
        """
329
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
330
        timestamp. It is intended to be used for COD orders but can be harmlessly
331
        used for all other orders as well.
332
        Throws an exception if no such order exists.
333
 
334
        Parameters:
335
         - orderId
336
        """
337
        try:
7391 rajveer 338
            return verify_order(orderId)
3064 chandransh 339
        finally:
340
            close_session()
341
 
921 rajveer 342
    def acceptOrder(self, orderId):
343
        """
3064 chandransh 344
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
345
        given order is not a COD order, it also captures the payment if the same has
346
        not been captured.
347
        Throws an exception if no such order exists.
348
 
921 rajveer 349
        Parameters:
350
         - orderId
351
        """
352
        try:
4285 rajveer 353
            return accept_order(orderId)
921 rajveer 354
        finally:
355
            close_session()
356
 
3014 chandransh 357
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 358
        """
3014 chandransh 359
        Returns list of orders for the given customer created between the given dates and having the given statuses.
360
        Pass and empty list to ignore filtering on statuses.
361
 
104 ashish 362
        Parameters:
363
         - customerId
364
         - from_date
365
         - to_date
3014 chandransh 366
         - statuses
104 ashish 367
        """
766 rajveer 368
        try:
369
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
370
 
3014 chandransh 371
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 372
            return [to_t_order(order) for order in orders]
373
        finally:
374
            close_session()
1528 ankur.sing 375
 
376
    def getOrderForCustomer(self, orderId, customerId):
377
        """
378
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
379
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
380
 
381
        Parameters:
382
         - customerId
383
         - orderId
384
        """
385
        try:
386
            return to_t_order(get_order_for_customer(orderId, customerId))
387
        finally:
388
            close_session()
766 rajveer 389
 
483 rajveer 390
    def getOrder(self, id):
391
        """
392
        Parameters:
393
         - id
394
        """
766 rajveer 395
        try:
396
            return to_t_order(get_order(id))
397
        finally:
398
            close_session()
4999 phani.kuma 399
 
400
    def getOrderList(self, order_ids):
401
        """
402
        Parameters:
403
         - order_ids
404
        """
405
        try:
406
            orders = get_order_list(order_ids)
407
            return [to_t_order(order) for order in orders]
408
        finally:
409
            close_session()
410
 
5386 phani.kuma 411
    def getOrderListForVendor(self, order_ids, vendorId):
412
        """
413
        Parameters:
414
         - order_ids
415
         - vendorId
416
        """
417
        try:
418
            orders = get_order_list_for_vendor(order_ids, vendorId)
419
            return [to_t_order(order) for order in orders]
420
        finally:
421
            close_session()
422
 
483 rajveer 423
    def getLineItemsForOrder(self, orderId):
424
        """
425
        Parameters:
426
         - orderId
427
        """
766 rajveer 428
        try:
429
            lineitems = get_line_items_for_order(orderId)
430
            t_lineitems = []
431
            for lineitem in lineitems:
432
                t_lineitems.append(to_t_lineitem(lineitem))
433
            return t_lineitems
434
        finally:
435
            close_session()
1149 chandransh 436
 
7190 amar.kumar 437
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, freebieWarehouseId, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 438
        """
4658 mandeep.dh 439
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 440
        Also marks the order as billed and sets the billing timestamp.
441
        Return false if it doesn't find the order with the given ID.
1149 chandransh 442
 
443
        Parameters:
444
         - orderId
445
         - jacketNumber
4658 mandeep.dh 446
         - serialNumber
2783 chandransh 447
         - itemNumber
7190 amar.kumar 448
         - freebieWarehouseId
2783 chandransh 449
         - billedBy
1149 chandransh 450
        """
451
        try:
7190 amar.kumar 452
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, freebieWarehouseId, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 453
        finally:
454
            close_session()
1220 chandransh 455
 
6751 amar.kumar 456
    def addInvoiceNumber(self, orderId, invoiceNumber, color, serialNumber, itemNumber):
4579 rajveer 457
        """
458
        Add the invoice number to the order.
459
 
460
        Parameters:
461
         - orderId
462
         - invoice_number
463
        """
464
        try:
6751 amar.kumar 465
            add_invoice_number(orderId, invoiceNumber, color, serialNumber, itemNumber)
4579 rajveer 466
        finally:
467
            close_session()
468
 
1220 chandransh 469
    def batchOrders(self, warehouseId):
470
        """
471
        Create a batch of all the pending orders for the given warehouse.
472
        The returned list is orderd by created_timestamp.
473
        If there are no pending orders, an empty list is returned.
1208 chandransh 474
 
1220 chandransh 475
        Parameters:
476
         - warehouseId
477
        """
478
        try:
479
            pending_orders = batch_orders(warehouseId)
480
            return [to_t_order(order) for order in pending_orders]
481
        finally:
482
            close_session()
483
 
1208 chandransh 484
    def markOrderAsOutOfStock(self, orderId):
485
        """
486
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
487
 
488
 
489
        Parameters:
490
         - orderId
491
        """
492
        try:
493
            return order_outofstock(orderId)
494
        finally:
495
            close_session()
496
 
4910 phani.kuma 497
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod, orderIds):
759 chandransh 498
        """
3064 chandransh 499
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4910 phani.kuma 500
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 501
 
502
        Parameters:
503
         - warehouseId
504
         - providerId
3064 chandransh 505
         - cod
759 chandransh 506
        """
766 rajveer 507
        try:
4910 phani.kuma 508
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds)
766 rajveer 509
        finally:
510
            close_session()
1113 chandransh 511
 
5713 rajveer 512
    def markOrdersAsReturnedFromStore(self, providerId, orderIds, awbs):
5676 rajveer 513
        """
514
        Parameters:
515
         - providerId
516
         - orderIds
5713 rajveer 517
         - awbs
5676 rajveer 518
        """
519
        try:
5713 rajveer 520
            return mark_orders_as_returned_from_store(providerId, orderIds, awbs)
5676 rajveer 521
        finally:
522
            close_session()
523
 
524
    def setOrderAttributes(self, orderId, attributes):
525
        """
526
        sets attributes for an order
527
 
528
        Parameters:
529
         - orderId
530
         - attributes
531
        """
532
        try:
533
            return set_order_attributes(orderId, attributes)
534
        finally:
535
            close_session()
536
 
537
 
4910 phani.kuma 538
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
4410 rajveer 539
        """
4910 phani.kuma 540
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
541
        Raises an exception if we encounter report for an AWB number that we did not ship.
4410 rajveer 542
 
543
        Parameters:
544
         - providerId
4910 phani.kuma 545
         - pickupDetails
4410 rajveer 546
        """
547
        try:
4910 phani.kuma 548
            mark_orders_as_picked_up(providerId, pickupDetails)
4410 rajveer 549
        finally:
550
            close_session()
551
 
4910 phani.kuma 552
    def getOrdersNotPickedUp(self, providerId):
1113 chandransh 553
        """
554
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
555
 
556
        Parameters:
557
         - providerId
558
        """
559
        try:
4910 phani.kuma 560
            orders_not_picked_up = get_orders_not_picked_up(providerId)
1113 chandransh 561
            return [to_t_order(order) for order in orders_not_picked_up]
562
        finally:
563
            close_session()
1132 chandransh 564
 
565
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
566
        """
567
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
568
        the name of the receiver.
569
        Raises an exception if we encounter report for an AWB number that we did not ship.
570
 
571
        Parameters:
572
         - providerId
573
         - deliveredOrders
574
        """
575
        try:
576
            mark_orders_as_delivered(providerId, deliveredOrders)
577
        finally:
578
            close_session()
1135 chandransh 579
 
4712 rajveer 580
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
581
        """
582
        Attributes:
583
         - orderId
584
         - deliveryTimestamp
585
         - receiver
586
        """
587
        try:
588
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
589
        finally:
590
            close_session()
591
 
592
 
5555 rajveer 593
    def markOrderAsReceivedAtStore(self, orderId, deliveryTimestamp):
594
        """
595
        Attributes:
596
         - orderId
597
         - deliveryTimestamp
598
        """
599
        try:
600
            mark_order_as_received_at_store(orderId, to_py_date(deliveryTimestamp))
601
        finally:
602
            close_session()
603
 
604
    def getReceivePendingOrders(self, storeId):
605
        """
606
        Attributes:
607
         - storeId
608
        """
609
        try:
610
            orders = get_receive_pending_orders(storeId)
611
            return [to_t_order(order) for order in orders]
612
        finally:
613
            close_session()
614
 
615
    def getReceivedAtStoreOrders(self, storeId):
616
        """
617
        Attributes:
618
         - storeId
619
        """
620
        try:
621
            orders = get_received_at_store_orders(storeId)
622
            return [to_t_order(order) for order in orders]
623
        finally:
624
            close_session()
5713 rajveer 625
 
626
    def getOrdersCollectionAtStore(self, storeId, fromDate, toDate, onlyCod):
627
        """
628
        Parameters:
629
         - storeId
630
         - fromDate
631
         - toDate
632
         - onlyCod
633
        """
634
        try:
635
            orders = get_orders_collection_at_store(storeId, to_py_date(fromDate), to_py_date(toDate), onlyCod)
636
            return [to_t_order(order) for order in orders]
637
        finally:
638
            close_session()
639
 
4910 phani.kuma 640
    def markAsRTOrders(self, providerId, returnedOrders):
1135 chandransh 641
        """
4910 phani.kuma 642
        Mark all orders with AWBs in the given map as RTO. Also sets the delivery timestamp.
1135 chandransh 643
        Raises an exception if we encounter report for an AWB number that we did not ship.
644
 
645
        Parameters:
646
         - providerId
647
         - returnedOrders
648
        """
649
        try:
4910 phani.kuma 650
            mark_orders_as_rto(providerId, returnedOrders)
1135 chandransh 651
        finally:
652
            close_session()
1246 chandransh 653
 
4910 phani.kuma 654
    def getRTOrders(self, providerId):
655
        """
656
        Returns a list of orders that were returned by courier.
657
 
658
        Parameters:
659
         - providerId
660
        """
661
        try:
662
            rto_orders = get_rto_orders(providerId)
663
            return [to_t_order(order) for order in rto_orders]
664
        finally:
665
            close_session()
666
 
1246 chandransh 667
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
668
        """
669
        Update the status description of orders whose AWB numbers are keys of the Map.
670
 
671
        Parameters:
672
         - providerId
673
         - undelivered_orders
674
        """
675
        try:
4910 phani.kuma 676
            update_non_delivery_reason(providerId, undeliveredOrders)
677
        finally:
678
            close_session()
679
 
680
    def getNonDeliveredOrdersbyCourier(self, providerId):
681
        """
682
        Returns a list of orders that were picked up or shipped four days ago but did not get delivered.
683
 
684
        Parameters:
685
         - providerId
686
        """
687
        try:
688
            orders_not_delivered = get_non_delivered_orders_by_courier(providerId)
4581 phani.kuma 689
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 690
        finally:
691
            close_session()
1405 ankur.sing 692
 
4910 phani.kuma 693
    def markOrdersAsLocalConnected(self, providerId, local_connected_orders):
694
        """
695
        Mark all orders with AWBs in the given map as local connected. Also sets the local connected timestamp.
696
 
697
        Parameters:
698
         - providerId
699
         - local_connected_orders
700
        """
701
        try:
702
            mark_orders_as_local_connected(providerId, local_connected_orders)
703
        finally:
704
            close_session()
705
 
706
    def getOrdersNotLocalConnected(self, providerId):
707
        """
708
        Returns a list of orders that were picked up or shipped but pending local connection.
709
 
710
        Parameters:
711
         - providerId
712
        """
713
        try:
714
            orders_pending_local_connection = get_orders_not_local_connected(providerId)
715
            return [to_t_order(order) for order in orders_pending_local_connection]
716
        finally:
717
            close_session()
718
 
719
    def markOrdersAsDestinationCityReached(self, providerId, destination_city_reached_orders):
720
        """
721
        Mark all orders with AWBs in the given map as reached destination city. Also sets the reached destination timestamp.
722
 
723
        Parameters:
724
         - providerId
725
         - destination_city_reached_orders
726
        """
727
        try:
728
            mark_orders_as_destinationCityReached(providerId, destination_city_reached_orders)
729
        finally:
730
            close_session()
731
 
732
    def markOrdersAsFirstDeliveryAttempted(self, providerId, first_atdl_orders):
733
        """
734
        Mark all orders with AWBs in the given map as first delivery attempt made. Also sets the first delivery attempted timestamp.
735
 
736
        Parameters:
737
         - providerId
738
         - first_atdl_orders
739
        """
740
        try:
741
            mark_orders_as_firstDeliveryAttempted(providerId, first_atdl_orders)
742
        finally:
743
            close_session()
744
 
4783 phani.kuma 745
    def getUndeliveredOrdersExpectedDeliveryDateNotMet(self):
746
        """
747
        Returns the list of orders whose expected delivery date has passed but have not been
748
        delivered yet.
749
        Returns an empty list if no such orders exist.
750
        """
751
        try:
752
            orders_not_delivered = get_orders_not_met_expected_delivery_date()
753
            return [to_t_order(order) for order in orders_not_delivered]
754
        finally:
755
            close_session()
756
 
1405 ankur.sing 757
    def getUndeliveredOrders(self, providerId, warehouseId):
758
        """
759
        Returns the list of orders whose delivery time has passed but have not been
760
        delivered yet for the given provider and warehouse. To get a complete list of
761
        undelivered orders, pass them as -1.
762
        Returns an empty list if no such orders exist.
763
 
764
        Parameters:
765
         - providerId
766
         - warehouseId
767
        """
768
        try:
769
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
770
            return [to_t_order(order) for order in undelivered_orders]
771
        finally:
772
            close_session()
1351 varun.gupt 773
 
1398 varun.gupt 774
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 775
        """
1398 varun.gupt 776
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 777
 
778
        Parameters:
779
         - transactionId
780
        """
781
        try:
1398 varun.gupt 782
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 783
        finally:
784
            close_session()
785
 
4444 rajveer 786
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 787
        """
788
        Parameters:
4394 rajveer 789
         - type
4444 rajveer 790
         - warehouseId
4394 rajveer 791
         - status
792
         - timestamp
483 rajveer 793
        """
766 rajveer 794
        try:
4444 rajveer 795
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 796
 
797
            t_alerts = []
798
            for alert in alerts:
799
                t_alerts.append(to_t_alert(alert)) 
800
 
801
            return t_alerts
802
        finally:
803
            close_session()
4394 rajveer 804
 
4447 rajveer 805
    def addAlert(self, type, warehouseId, description):
483 rajveer 806
        """
807
        Parameters:
808
         - type
4394 rajveer 809
         - description
4447 rajveer 810
         - warehouseId
483 rajveer 811
        """
766 rajveer 812
        try:
4447 rajveer 813
            add_alert(type, warehouseId, description)
766 rajveer 814
        finally:
815
            close_session()
1596 ankur.sing 816
 
4444 rajveer 817
    def markAlertsAsSeen(self, warehouseId):
818
        """
819
        Parameters:
820
         - warehouseId
821
        """
822
        try:
823
            mark_alerts_as_seen(warehouseId)
824
        finally:
825
            close_session()
826
        pass
827
 
1596 ankur.sing 828
    def getValidOrderCount(self, ):
829
        """
830
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
831
        """
1731 ankur.sing 832
        try:
833
            return get_valid_order_count()
834
        finally:
835
            close_session()
1627 ankur.sing 836
 
837
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
838
        """
839
        Returns the number of distinct customers who have done successful transactions
840
        """
1731 ankur.sing 841
        try:
842
            return get_cust_count_with_successful_txn()
843
        finally:
844
            close_session()
1627 ankur.sing 845
 
1731 ankur.sing 846
 
847
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 848
        """
1731 ankur.sing 849
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
850
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 851
        """
1731 ankur.sing 852
        try:
853
            return get_valid_orders_amount_range()
854
        finally:
855
            close_session()
1627 ankur.sing 856
 
5874 rajveer 857
    def getValidOrders(self, limit, onlyStore):
1886 ankur.sing 858
        """
859
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
860
        If limit is passed as 0, then all valid Orders are returned.
861
 
862
        Parameters:
863
         - limit
5874 rajveer 864
         - onlyStore
1886 ankur.sing 865
        """
866
        try:
5874 rajveer 867
            return [to_t_order(order) for order in get_valid_orders(limit, onlyStore)]
1886 ankur.sing 868
        finally:
869
            close_session()
104 ashish 870
 
2536 chandransh 871
    def toggleDOAFlag(self, orderId):
104 ashish 872
        """
2536 chandransh 873
        Toggle the DOA flag of an order. This should be used to flag an order for follow-up and unflag it when the follow-up is complete.
874
        Returns the final flag status.
875
        Throws an exception if the order with the given id couldn't be found or if the order status is not DELVIERY_SUCCESS.
483 rajveer 876
 
132 ashish 877
        Parameters:
2536 chandransh 878
         - orderId
132 ashish 879
        """
2536 chandransh 880
        try:
881
            return toggle_doa_flag(orderId)
882
        finally:
883
            close_session()
483 rajveer 884
 
4454 rajveer 885
    def markOrderDoaRequestReceived(self, orderId):
886
        """
887
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
888
 
889
        Parameters:
890
         - orderId
891
        """
892
        try:
893
            return mark_order_doa_request_received(orderId)
894
        finally:
895
            close_session()
896
 
7645 anupam.sin 897
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized,  fromStore, isReship):
4454 rajveer 898
        """
899
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
900
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
901
 
902
        Parameters:
903
         - orderId
904
         - isAuthorized
905
        """
906
        try:
7645 anupam.sin 907
            return mark_order_doa_request_authorized(orderId, isAuthorized, fromStore, isReship)
4454 rajveer 908
        finally:
909
            close_session()
910
 
4488 rajveer 911
    def markOrderReturnRequestReceived(self, orderId):
912
        """
913
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
914
 
915
        Parameters:
916
         - orderId
917
        """
918
        try:
919
            return mark_order_return_request_received(orderId)
920
        finally:
921
            close_session()
922
 
7645 anupam.sin 923
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized, fromStore, isReship):
4488 rajveer 924
        """
925
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
926
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
927
 
928
        Parameters:
929
         - orderId
930
         - isAuthorized
931
        """
932
        try:
7645 anupam.sin 933
            return mark_order_return_request_authorized(orderId, isAuthorized, fromStore, isReship)
4488 rajveer 934
        finally:
935
            close_session()
936
 
4579 rajveer 937
    def requestPickupNumber(self, orderId, providerId):
104 ashish 938
        """
2536 chandransh 939
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 940
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
941
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 942
        For any other status, it returns false.
943
        Throws an exception if the order with the given id couldn't be found.
104 ashish 944
 
945
        Parameters:
2536 chandransh 946
         - orderId
104 ashish 947
        """
2536 chandransh 948
        try:
4579 rajveer 949
            return request_pickup_number(orderId, providerId)
2536 chandransh 950
        finally:
951
            close_session()
483 rajveer 952
 
4602 rajveer 953
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 954
        """
4452 rajveer 955
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 956
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
957
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
958
            3. Returns true
959
        If the order is any other status, it returns false.
960
        Throws an exception if the order with the given id couldn't be found.
304 ashish 961
 
962
        Parameters:
2536 chandransh 963
         - orderId
964
         - pickupNumber
304 ashish 965
        """
2536 chandransh 966
        try:
4602 rajveer 967
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 968
        finally:
969
            close_session()    
2764 chandransh 970
 
971
    def markDoasAsPickedUp(self, providerId, pickupDetails):
972
        """
973
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
974
 
975
        Parameters:
976
         - providerId
977
         - pickupDetails
978
        """
979
        try:
4910 phani.kuma 980
            mark_doas_as_picked_up(providerId, pickupDetails)
981
        finally:
982
            close_session()
983
 
984
    def getDoasNotPickedUp(self, providerId):
985
        """
986
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
987
 
988
        Parameters:
989
         - providerId
990
        """
991
        try:
992
            orders_not_picked_up = get_doas_not_picked_up(providerId)
2764 chandransh 993
            return [to_t_order(order) for order in orders_not_picked_up]
994
        finally:
995
            close_session()
4910 phani.kuma 996
 
4741 phani.kuma 997
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
998
        """
999
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
1000
 
1001
        Parameters:
1002
         - providerId
1003
         - pickupDetails
1004
        """
1005
        try:
4910 phani.kuma 1006
            mark_return_orders_as_picked_up(providerId, pickupDetails)
1007
        finally:
1008
            close_session()
1009
 
1010
    def getReturnOrdersNotPickedUp(self, providerId):
1011
        """
1012
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
1013
 
1014
        Parameters:
1015
         - providerId
1016
        """
1017
        try:
1018
            orders_not_picked_up = get_return_orders_not_picked_up(providerId)
4741 phani.kuma 1019
            return [to_t_order(order) for order in orders_not_picked_up]
1020
        finally:
1021
            close_session()
4910 phani.kuma 1022
 
4479 rajveer 1023
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 1024
        """
4452 rajveer 1025
        If the order status is DOA_PICKUP_CONFIRMED or DOA_RETURN_IN_TRANSIT, marks the order status as DOA_RECEIVED_PRESTINE and returns true.
2591 chandransh 1026
        If the order is in any other state, it returns false.
1027
        Throws an exception if the order with the given id couldn't be found.
1028
 
1029
        Parameters:
1030
         - orderId
1031
        """
1032
        try:
4479 rajveer 1033
            return receive_return(orderId, receiveCondition)
2591 chandransh 1034
        finally:
1035
            close_session()
1036
 
1037
    def validateDoa(self, orderId, isValid):
1038
        """
4452 rajveer 1039
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 1040
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 1041
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
1042
        If the order is in any other state, it returns false.
1043
        Throws an exception if the order with the given id couldn't be found.
1044
 
1045
        Parameters:
1046
         - orderId
1047
         - isValid
1048
        """
1049
        try:
1050
            return validate_doa(orderId, isValid)
1051
        finally:
1052
            close_session()
2628 chandransh 1053
 
4495 rajveer 1054
    def validateReturnProduct(self, orderId, isUsable):
1055
        """
1056
        Parameters:
1057
         - orderId
1058
         - isUsable
1059
        """
1060
        try:
1061
            return validate_return_product(orderId, isUsable)
1062
        finally:
1063
            close_session()
1064
 
2628 chandransh 1065
    def reshipOrder(self, orderId):
1066
        """
4484 rajveer 1067
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1068
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 1069
            2. Marks the current order as one of the final states RTO_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
2628 chandransh 1070
 
1071
        If the order is in DOA_CERT_VALID state, it does the following:
1072
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1073
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 1074
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 1075
 
1076
        Returns the id of the newly created order.
1077
 
1078
        Throws an exception if the order with the given id couldn't be found.
1079
 
1080
        Parameters:
1081
         - orderId
1082
        """
1083
        try:
1084
            return reship_order(orderId)
1085
        finally:
1086
            close_session()
1087
 
3226 chandransh 1088
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 1089
        """
4484 rajveer 1090
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1091
            1. Creates a refund request for batch processing.
1092
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 1093
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 1094
 
1095
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1096
            1. Creates a refund request for batch processing.
3226 chandransh 1097
            2. Cancels the reservation of the item in the warehouse.
1098
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 1099
 
3226 chandransh 1100
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1101
            1. Cancels the reservation of the item in the warehouse.
1102
            2. Marks the current order as CANCELED.
1103
 
1104
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
1105
 
2628 chandransh 1106
        Returns True if it is successful, False otherwise.
1107
 
1108
        Throws an exception if the order with the given id couldn't be found.
1109
 
1110
        Parameters:
1111
         - orderId
3226 chandransh 1112
         - refundedBy
1113
         - reason
2628 chandransh 1114
        """
1115
        try:
3226 chandransh 1116
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 1117
        finally:
1118
            close_session()
1119
 
2697 chandransh 1120
    def getReturnOrders(self, warehouseId, fromDate, toDate):
1121
        """
1122
        Get all return orders created between the from and to dates for the given warehouse.
1123
        Ignores the warehouse if it is passed as -1.
1124
 
1125
        Parameters:
1126
         - warehouseId
1127
         - fromDate
1128
         - toDate
1129
        """
1130
        try:
1131
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1132
            return get_return_orders(warehouseId, from_date, to_date)
1133
        finally:
1134
            close_session()
1135
 
5481 phani.kuma 1136
    def getAllReturnOrders(self, onlyNotProcessed, fromDate, toDate):
1137
        """
1138
        Get all return orders created between the from and to dates for the given warehouse.
1139
        Ignores the warehouse if it is passed as -1.
1140
 
1141
        Parameters:
1142
         - warehouseId
1143
         - fromDate
1144
         - toDate
1145
        """
1146
        try:
1147
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1148
            return get_all_return_orders(onlyNotProcessed, from_date, to_date)
1149
        finally:
1150
            close_session()
1151
 
2700 chandransh 1152
    def getReturnOrder(self, id):
1153
        """
1154
        Returns the ReturnOrder corresponding to the given id.
1155
        Throws an exception if the return order with the given id couldn't be found.
1156
 
1157
        Parameters:
1158
         - id
1159
        """
1160
        try:
1161
            return get_return_order(id)
1162
        finally:
1163
            close_session()
1164
 
2697 chandransh 1165
    def processReturn(self, returnOrderId):
1166
        """
1167
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
1168
 
1169
        Parameters:
1170
         - returnOrderId
1171
        """
1172
        try:
1173
            process_return(returnOrderId)
1174
        finally:
1175
            close_session()
4757 mandeep.dh 1176
 
1177
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 1178
        """
4757 mandeep.dh 1179
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
1180
        the quantities for which the PO is raised.
1181
 
2819 chandransh 1182
        Parameters:
4757 mandeep.dh 1183
         - itemIdQuantityMap
1184
         - purchaseOrderId
2819 chandransh 1185
         - warehouseId
1186
        """
1187
        try:
4757 mandeep.dh 1188
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 1189
        finally:
1190
            close_session()
4757 mandeep.dh 1191
 
3451 chandransh 1192
    def updateWeight(self, orderId, weight):
1193
        """
1194
        Set the weight of the given order to the provided value. Will attempt to update the weight of the item in the catalog as well.
1195
 
1196
        Parameters:
1197
         - orderId
1198
         - weight
1199
        """
1200
        try:
1201
            order = update_weight(orderId, weight)
1202
            return to_t_order(order)
1203
        finally:
1204
            close_session()
1205
 
3469 chandransh 1206
    def changeItem(self, orderId, itemId):
1207
        """
1208
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
1209
        Currently, it also ensures that only a different color of the given item is shipped.
1210
 
1211
        Parameters:
1212
         - orderId
1213
         - itemId
1214
        """
1215
        try:
1216
            order = change_product(orderId, itemId)
1217
            return to_t_order(order)
1218
        finally:
1219
            close_session()
7560 rajveer 1220
 
1221
    def changeCourierProvider(self, orderId, providerId):
1222
        try:
1223
            order = change_courier_provider(orderId, providerId)
1224
            return to_t_order(order)
1225
        finally:
1226
            close_session()
1227
 
3469 chandransh 1228
 
1229
    def shiftToWarehouse(self, orderId, warehouseId):
1230
        """
1231
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
1232
 
1233
        Parameters:
1234
         - orderId
1235
         - warehouseId
1236
        """
1237
        try:
1238
            order = change_warehouse(orderId, warehouseId)
1239
            return to_t_order(order)
1240
        finally:
1241
            close_session()
3553 chandransh 1242
 
4647 rajveer 1243
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 1244
        """
1245
        Adds the given delay reason to the given order.
3986 chandransh 1246
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 1247
        Raises an exception if no order with the given id can be found.
3469 chandransh 1248
 
3553 chandransh 1249
        Parameters:
1250
         - orderId
1251
         - delayReason
1252
        """
1253
        try:
4647 rajveer 1254
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 1255
        finally:
1256
            close_session()
1257
 
3956 chandransh 1258
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
1259
        """
1260
        Marks the COD orders with given AWB nos. as having been processed.
1261
        Updates the captured amount for the corresponding payment.
1262
 
1263
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
1264
        1. There is no order corresponding to an AWB number.
1265
        2. The captured amount for a payment exceeds the total payment.
1266
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
1267
 
1268
        Parameters:
1269
         - collectedAmountMap
1270
         - xferBy
1271
         - xferTxnId
1272
         - xferDate
1273
        """
1274
        try:
1275
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
1276
        finally:
1277
            close_session()
4008 mandeep.dh 1278
 
1279
    def getTransactionsRequiringExtraProcessing(self, category):
1280
        """
1281
        Returns the list of transactions that require some extra processing and
1282
        which belong to a particular category. This is currently used by CRM
1283
        application.
1284
        """
1285
        try:
1286
            return get_transactions_requiring_extra_processing(category)
1287
        finally:
1288
            close_session()
1289
 
1290
    def markTransactionAsProcessed(self, transactionId, category):
1291
        """
1292
        Marks a particular transaction as processed for a particular category.
1293
        It essentially deletes the transaction if it is processed for a particular
1294
        category. This is currently used by CRM application.
1295
        """
1296
        try:
1297
            return mark_transaction_as_processed(transactionId, category)
1298
        finally:
1299
            close_session()
4018 chandransh 1300
 
1301
    def getItemWiseRiskyOrdersCount(self, ):
1302
        """
1303
        Returns a map containing the number of risky orders keyed by item id. A risky order
1304
        is defined as one whose shipping date is about to expire.
1305
        """
1306
        try:
1307
            return get_item_wise_risky_orders_count()
1308
        finally:
1309
            close_session()
3956 chandransh 1310
 
4247 rajveer 1311
    def markOrderCancellationRequestReceived(self, orderId):
1312
        """
1313
        Mark order as cancellation request received. If customer sends request of cancellation of
1314
        a particular order, this method will be called. It will just change status of the order
1315
        depending on its current status. It also records the previous status, so that we can move
1316
        back to that status if cancellation request is denied.
1317
 
1318
        Parameters:
1319
         - orderId
1320
        """
1321
        try:
1322
            return mark_order_cancellation_request_received(orderId)
1323
        finally:
1324
            close_session()
1325
 
1326
 
4662 rajveer 1327
    def markOrderAsLostInTransit(self, orderId):
1328
        """
1329
        Parameters:
1330
         - orderId
1331
        """
1332
        try:
1333
            return mark_order_as_lost_in_transit(orderId)
1334
        finally:
1335
            close_session()
1336
 
4258 rajveer 1337
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1338
        """
4258 rajveer 1339
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1340
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1341
 
1342
        Parameters:
4258 rajveer 1343
         - transactionId
4247 rajveer 1344
        """
1345
        try:
4259 anupam.sin 1346
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1347
        finally:
1348
            close_session()
4259 anupam.sin 1349
 
1350
    def refundTransaction(self, transactionId, refundedBy, reason):
1351
        """
1352
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1353
        need to be cancelled
1354
 
1355
        Parameters:
1356
         - transactionId
1357
        """
1358
        try:
1359
            return refund_transaction(transactionId, refundedBy, reason)
1360
        finally:
1361
            close_session()
4247 rajveer 1362
 
1363
    def markOrderCancellationRequestDenied(self, orderId):
1364
        """
1365
        If we decide to not to cancel order, we will move the order ro previous status.
1366
 
1367
        Parameters:
1368
         - orderId
1369
        """
1370
        try:
1371
            return mark_order_cancellation_request_denied(orderId)
1372
        finally:
1373
            close_session()
1374
 
1375
    def markOrderCancellationRequestConfirmed(self, orderId):
1376
        """
1377
        If we decide to to cancel order, CRM will call this method to move the status of order to
1378
        cancellation request confirmed. After this OM will be able to cancel the order.
1379
 
1380
        Parameters:
1381
         - orderId
1382
        """
1383
        try:
1384
            return mark_order_cancellation_request_confirmed(orderId)
1385
        finally:
1386
            close_session()
1387
 
4324 mandeep.dh 1388
    def updateShipmentAddress(self, orderId, addressId):
1389
        """
1390
        Updates shipment address of an order. Delivery and shipping date estimates
1391
        etc. are also updated here.
1392
 
1393
        Throws TransactionServiceException in case address change is not
1394
        possible due to certain reasons such as new pincode in address is
1395
        not serviceable etc.
1396
 
1397
        Parameters:
1398
         - orderId
1399
         - addressId
1400
        """
1401
        try:
1402
            update_shipment_address(orderId, addressId)
1403
        finally:
1404
            close_session()
1405
 
4285 rajveer 1406
    def acceptOrdersForItemId(self, itemId, inventory):
1407
        """
1408
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1409
        given order is not a COD order, it also captures the payment if the same has not been captured.
1410
 
1411
        Parameters:
1412
         - itemId
1413
         - inventory
1414
        """
1415
        try:
1416
            return accept_orders_for_item_id(itemId, inventory)
1417
        finally:
1418
            close_session()
1419
 
4303 rajveer 1420
 
1421
 
4369 rajveer 1422
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1423
        """
1424
        Parameters:
1425
         - vendorId
1426
         - itemId
1427
         - quantity
1428
         - estimate
4369 rajveer 1429
         - isReminder
4303 rajveer 1430
        """
1431
        try:
4369 rajveer 1432
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1433
        finally:
1434
            close_session()
1435
 
4369 rajveer 1436
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1437
        """
1438
        Parameters:
1439
         - vendorId
1440
         - itemId
1441
         - quantity
1442
         - estimate
4369 rajveer 1443
         - isReminder
4303 rajveer 1444
        """
1445
        try:
4369 rajveer 1446
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1447
        finally:
1448
            close_session()
1449
 
4369 rajveer 1450
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1451
        """
1452
        Parameters:
1453
         - vendorId
1454
         - itemId
1455
         - quantity
1456
         - estimate
4369 rajveer 1457
         - isReminder
4303 rajveer 1458
        """
1459
        try:
4369 rajveer 1460
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1461
        finally:
1462
            close_session()
1463
 
1464
 
4369 rajveer 1465
    def markOrdersAsTimeout(self, vendorId):
1466
        """
1467
        Parameters:
1468
         - vendorId
1469
        """
1470
        try:
1471
            return mark_orders_as_timeout(vendorId)
1472
        finally:
1473
            close_session()
4386 anupam.sin 1474
 
1475
    def getOrderForAwb(self, awb):
1476
        """
1477
        Parameters:
1478
         - AirwayBill Number
1479
        """
1480
        try:
1481
            return to_t_order(get_order_for_awb(awb))
1482
        finally:
1483
            close_session()
4369 rajveer 1484
 
4910 phani.kuma 1485
    def getOrdersForProviderForStatus(self, provider_id, order_status_list):
4506 phani.kuma 1486
        """
1487
        Parameters:
1488
         - provider id
1489
         - order status
1490
        """
1491
        try:
4910 phani.kuma 1492
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status_list)
4506 phani.kuma 1493
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1494
        finally:
1495
            close_session()
4600 varun.gupt 1496
 
1497
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1498
        '''
1499
        Parameters:
1500
         - vendorId
1501
         - billingDateFrom
1502
         - billingDateTo
1503
        '''
1504
        try:
1505
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1506
        finally:
1507
            close_session()
1508
 
4607 rajveer 1509
    def getSlippedSippingDateOrders(self):
1510
        try:
1511
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1512
        finally:
1513
            close_session()
1514
 
4709 rajveer 1515
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1516
        try:
1517
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1518
        finally:
1519
            close_session()
1520
 
4600 varun.gupt 1521
    def getEBSSettlementSummaries(self):
1522
        try:
1523
            return get_ebs_settlement_summaries()
1524
        finally:
1525
            close_session()
4369 rajveer 1526
 
4600 varun.gupt 1527
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1528
        try:
1529
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1530
        finally:
1531
            close_session()
1532
 
5386 phani.kuma 1533
    def getSettlementForPrepaid(self, referenceId, isRefund):
4600 varun.gupt 1534
        '''
1535
        Parameters:
5189 varun.gupt 1536
         - referenceId
1537
         - isRefund
4600 varun.gupt 1538
        '''
1539
        try:
5386 phani.kuma 1540
            return to_t_payment_settlement(get_settlement_for_Prepaid(referenceId, isRefund))
4600 varun.gupt 1541
        finally:
1542
            close_session()
5386 phani.kuma 1543
 
1544
    def getSettlementForCod(self, orderId, isRefund):
1545
        '''
1546
        Parameters:
1547
         - orderId
1548
         - isRefund
1549
        '''
1550
        try:
1551
            return to_t_payment_settlement(get_settlement_for_Cod(orderId, isRefund))
1552
        finally:
1553
            close_session()
1554
 
4600 varun.gupt 1555
    def getEBSSettlementDate(self, settlementId):
1556
        try:
1557
            return to_java_date(get_ebs_settlement_date(settlementId))
1558
        finally:
1559
            close_session()
1560
 
4905 varun.gupt 1561
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection):
4600 varun.gupt 1562
        try:
4905 varun.gupt 1563
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection)
4600 varun.gupt 1564
        finally:
1565
            close_session()
1566
 
1567
    def markEBSSettlementUploaded(self, settlementId):
1568
        try:
1569
            mark_ebs_settlement_uploaded(settlementId)
1570
        finally:
1571
            close_session()
1572
 
4715 varun.gupt 1573
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1574
        try:
1575
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1576
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1577
        finally:
1578
            close_session()
1579
 
1580
    def getReshippedOrderIds(self, orderIds):
1581
        try:
1582
            return get_reshipped_order_ids(orderIds)
1583
        finally:
1584
            close_session()
1585
 
5481 phani.kuma 1586
    def getBilledOrders(self, vendorId, onlyVendorNotPaid, billingDateFrom, billingDateTo):
4875 varun.gupt 1587
        try:
5481 phani.kuma 1588
            from_date, to_date = get_fdate_tdate(billingDateFrom, billingDateTo)
1589
            return [to_t_order(order) for order in get_billed_orders(vendorId, onlyVendorNotPaid, from_date, to_date)]
4875 varun.gupt 1590
        finally:
1591
            close_session()
1592
 
5062 varun.gupt 1593
    def getStatusDistributionOfOrders(self, startDate, endDate):
1594
        try:
5067 varun.gupt 1595
            distribution = {}
1596
 
1597
            for status, count in get_order_distribution_by_status(to_py_date(startDate), to_py_date(endDate)):
1598
                distribution[status] = count
1599
 
1600
            return distribution
5062 varun.gupt 1601
        finally:
1602
            close_session()
1603
 
5067 varun.gupt 1604
    def getOrderIdsForStatus(self, status, startDatetime, endDatetime):
1605
        try:
1606
            orders = get_order_ids_for_status(status, to_py_date(startDatetime), to_py_date(endDatetime))
1607
            return [order.id for order in orders]
1608
        finally:
1609
            close_session()
1610
 
5099 varun.gupt 1611
    def updateOrderAsPaidToVendor(self, orderId):
1612
        try:
1613
            update_orders_as_paid_to_vendor(orderId)
1614
        finally:
1615
            close_session()
1616
 
5348 anupam.sin 1617
    def updateCODAgent(self, agentEmailId, orderId):
1618
        try:
1619
            update_COD_agent(agentEmailId, orderId)
1620
        finally:
1621
            close_session()
1622
 
5386 phani.kuma 1623
    def updateOrderOnlyAsPaidToVendor(self, orderId):
1624
        try:
1625
            update_order_only_as_paid_to_vendor(orderId)
1626
        finally:
1627
            close_session()
1628
 
5208 varun.gupt 1629
    def getRefundedOrdersMarkedPaid(self):
1630
        try:
1631
            return [to_t_order(order) for order in get_refunded_orders_marked_paid()]
1632
        finally:
1633
            close_session()
5447 anupam.sin 1634
 
1635
    def getAllVerificationAgents(self, minOrderId, maxOrderId):
1636
        try:
1637
            return [to_t_verification_agent(codAgent) for codAgent in get_all_verification_agents(minOrderId, maxOrderId)]
1638
        finally:
5527 anupam.sin 1639
            close_session()
1640
 
1641
    def getAllAttributesForOrderId(self, orderId):
1642
        try:
1643
            return [to_t_attribute(attribute) for attribute in get_all_attributes_for_order_id(orderId)]
1644
        finally:
1645
            close_session()
1646
 
1647
    def setOrderAttributeForTransaction(self, transactionId, attribute):
1648
        try:
1649
            set_order_attribute_for_transaction(transactionId, attribute)                    
1650
        finally:
1651
            close_session()
5593 mandeep.dh 1652
 
1653
    def acceptOrderForItem(self, itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
1654
        """
1655
        Accepts appropriate order for an item in a given billingWarehouse. Usually
1656
        invoked while scanning IN of items.
1657
 
1658
        Parameters:
1659
         - itemId
1660
         - quantity
1661
         - fulfilmentWarehouseId
1662
         - billingWarehouseId
1663
        """
1664
        try:
1665
            accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId)
1666
        finally:
1667
            close_session()
1668
 
5833 rajveer 1669
    def getOrderAttributeValue(self, orderId, attributeName):
1670
        """
1671
        Parameters:
1672
         - orderId
1673
         - attributeName
1674
        """
1675
        try:
6019 rajveer 1676
            return get_order_attribute_value(orderId, attributeName)
5833 rajveer 1677
        finally:
1678
            close_session()
1679
 
6019 rajveer 1680
    def changeJacketNumber(self, orderId, jacketNumber):
1681
        """
1682
        Parameters:
1683
         - orderId
1684
         - jacketNumber
1685
        """
1686
        try:
1687
            return change_jacket_number(orderId, jacketNumber)
1688
        finally:
1689
            close_session()
1690
 
1691
    def markOrderAsRtoInTransit(self, orderId):
1692
        """
1693
        Parameters:
1694
         - orderId
1695
        """
1696
        try:
1697
            return mark_order_as_rto_in_transit(orderId)
1698
        finally:
1699
            close_session()        
1700
 
6000 mandeep.dh 1701
    def createRechargeOrder(self, thriftRechargeOrder):
1702
        """
1703
        Parameters:
1704
         - thriftRechargeOrder
1705
        """
6031 rajveer 1706
        try:
1707
            if thriftRechargeOrder is None or thriftRechargeOrder.rechargeType is None:
1708
                raise TransactionServiceException(102, 'Order or the type is Null')
1709
 
1710
            rechargeOrder = None
1711
            if thriftRechargeOrder.rechargeType == RechargeType.MOBILE:
1712
                rechargeOrder = MobileRechargeOrder()
1713
            elif thriftRechargeOrder.rechargeType == RechargeType.DTH:
1714
                rechargeOrder = DTHRechargeOrder()
1715
 
1716
            if rechargeOrder is None:
1717
                raise TransactionServiceException(102, 'Unsupported recharge type')
6000 mandeep.dh 1718
 
6031 rajveer 1719
            transaction = DigitalTransaction()
1720
            transaction.createdOn = datetime.datetime.now()
6056 amit.gupta 1721
            transaction.userId = thriftRechargeOrder.userId
6031 rajveer 1722
            transaction.orders = [rechargeOrder]
1723
 
6000 mandeep.dh 1724
            rechargeOrder.from_thrift_object(thriftRechargeOrder)
1725
            session.commit()
6031 rajveer 1726
            return rechargeOrder.to_thrift_object()
6000 mandeep.dh 1727
        except:
1728
            raise TransactionServiceException(103, 'Invalid values passed')
1729
        finally:
1730
            self.closeSession()
1731
 
6031 rajveer 1732
    def getRechargeOrder(self, rechargeOrderId):
1733
        """
1734
        Parameters:
1735
         - rechargeOrderId
1736
        """
1737
        try:
6048 rajveer 1738
            return get_recharge_order(rechargeOrderId).to_thrift_object()
6031 rajveer 1739
        finally:
1740
            self.closeSession()
1741
 
1742
    def getRechargeOrders(self, userId):
1743
        """
1744
        Parameters:
1745
         - userId
1746
        """
1747
        try:
1748
            return [order.to_thrift_object() for order in get_recharge_orders(userId)]
1749
        finally:
1750
            self.closeSession()
1751
 
6000 mandeep.dh 1752
    def updateRechargeOrderStatus(self, rechargeOrderId, rechargeOrderStatus):
1753
        """
1754
        Parameters:
1755
         - rechargeOrderId
1756
         - rechargeOrderStatus
1757
        """
6031 rajveer 1758
        try:
1759
            return update_recharge_order_status(rechargeOrderId, rechargeOrderStatus)
1760
        finally:
1761
            self.closeSession()
1762
 
1763
    def activateRechargeTxn(self, rechargeOrderId):
6000 mandeep.dh 1764
        """
1765
        Parameters:
6031 rajveer 1766
         - rechargeOrderId
6000 mandeep.dh 1767
        """
6031 rajveer 1768
        try:
1769
            return True
1770
            activate_recharge_txn(rechargeOrderId)
1771
        finally:
1772
            self.closeSession()
6000 mandeep.dh 1773
 
6031 rajveer 1774
    def getUserWallet(self, userId):
6000 mandeep.dh 1775
        """
1776
        Parameters:
6031 rajveer 1777
         - userId
6000 mandeep.dh 1778
        """
6031 rajveer 1779
        try:
1780
            return get_user_wallet(userId).to_thrift_object()
1781
        finally:
1782
            self.closeSession()
6000 mandeep.dh 1783
 
6031 rajveer 1784
    def getUserWalletHistory(self, userId):
6000 mandeep.dh 1785
        """
1786
        Parameters:
6031 rajveer 1787
         - userId
6000 mandeep.dh 1788
        """
6031 rajveer 1789
        try:
1790
            return [wallet.to_thrift_object() for wallet in get_user_wallet_history(userId)]
1791
        finally:
1792
            self.closeSession()
6000 mandeep.dh 1793
 
6206 rajveer 1794
    def getServiceProviders(self, rechargeType, onlyActive):
6048 rajveer 1795
        """
1796
        Parameters:
1797
         - rechargeType
6206 rajveer 1798
         - onlyActive
6048 rajveer 1799
        """
6077 anupam.sin 1800
 
6048 rajveer 1801
        try:
6206 rajveer 1802
            return get_service_providers(rechargeType, onlyActive)
6048 rajveer 1803
        finally:
1804
            self.closeSession()
1805
 
6049 rajveer 1806
    def getServiceProviderForDevice(self, rechargeType, deviceNumber):
6048 rajveer 1807
        """
1808
        Parameters:
1809
         - deviceNumber
1810
        """
1811
        try:
6049 rajveer 1812
            return get_service_provider_for_device(rechargeType, deviceNumber)
6048 rajveer 1813
        finally:
1814
            self.closeSession()
6056 amit.gupta 1815
 
6591 anupam.sin 1816
    def validateRecharge(self, rechargeType, deviceNumber, userSelectedProviderId, clientAddress):
6269 rajveer 1817
        """
1818
        Parameters:
1819
         - deviceNumber
1820
        """
1821
        try:
6591 anupam.sin 1822
            return validate_recharge(rechargeType, deviceNumber, userSelectedProviderId, clientAddress)
6269 rajveer 1823
        finally:
1824
            self.closeSession()
1825
 
6056 amit.gupta 1826
    def getRechargeOrdersForTransaction(self, txId):
1827
        """
1828
        Parameters:
1829
         - transactionId
1830
        """
1831
        try:
1832
            return get_recharge_orders_for_transaction(txId).to_thrift_object()
1833
        finally:
1834
            self.closeSession()
6048 rajveer 1835
 
6094 rajveer 1836
    def getRechargeOrdersForDevice(self, deviceNumber):
1837
        """
1838
        Parameters:
1839
        - deviceNumber
1840
        """
1841
        try:
1842
            return [order.to_thrift_object() for order in get_recharge_orders_for_device(deviceNumber)]
1843
        finally:
1844
            self.closeSession()
1845
 
6154 rajveer 1846
    def getRechargeOrdersForStatus(self, status):
1847
        """
1848
        Parameters:
1849
        - status
1850
        """
1851
        try:
1852
            return [order.to_thrift_object() for order in get_recharge_orders_for_status(status)]
1853
        finally:
1854
            self.closeSession()
1855
 
6159 rajveer 1856
    def getPlansForOperator(self, operatorId):
1857
        """
1858
        Parameters:
1859
        - operatorId
1860
        """
1861
        try:
1862
            return [plan.to_thrift_object() for plan in get_plans_for_operator(operatorId)]
1863
        finally:
1864
            self.closeSession()
1865
 
1866
 
6094 rajveer 1867
    def addAmountToWallet(self, userId, orderId, amount):
1868
        """
1869
        Parameters:
1870
        - userId
1871
        - orderId
1872
        - amount
1873
        """
1874
        try:
8729 anupam.sin 1875
            update_amount_in_wallet(userId, amount, orderId, 0)
6094 rajveer 1876
        finally:
1877
            self.closeSession()
1878
 
6188 rajveer 1879
    def getRechargeStatistics(self):
1880
        """
1881
        Parameters:
1882
        """
1883
        try:
1884
            return get_recharge_statistics()
1885
        finally:
1886
            self.closeSession()
1887
 
6307 anupam.sin 1888
    def getRechargeDenominations(self, operatorId, circleCode, denominationType):
6289 anupam.sin 1889
        try:
1890
            returnList = []
6307 anupam.sin 1891
            rechargeDenominations = get_recharge_denominations(operatorId, circleCode, denominationType)
6289 anupam.sin 1892
            for rechargeDenomination in rechargeDenominations:
1893
                returnList.append(rechargeDenomination.to_thrift_object())
1894
            return returnList
1895
        finally:
1896
            self.closeSession() 
6188 rajveer 1897
 
6371 rajveer 1898
    def updateAvailabilityStatus(self, operatorId, circleId, isAvailable):
1899
        try:
1900
            update_availability_status(operatorId, circleId, isAvailable)
1901
        finally:
1902
            self.closeSession() 
1903
 
6396 amit.gupta 1904
    def getAvailableEmiSchemes(self):
1905
        try:
1906
            return get_available_emi_schemes()
1907
        finally:
1908
            self.closeSession()
1909
 
6389 rajveer 1910
    def getMiscCharges(self, transactionId):
1911
        try:
1912
            return get_misc_charges(transactionId)
1913
        finally:
1914
            self.closeSession()
1915
 
6507 anupam.sin 1916
    def refundRechargeOrder (self, rechargeOrderId):
1917
        try:
1918
            return refund_recharge_order(rechargeOrderId)
1919
        finally:
1920
            self.closeSession()
6821 amar.kumar 1921
 
1922
    def getPhysicalOrders(self, start_date, end_date):
1923
        try:
6832 amar.kumar 1924
            return [to_t_order(order) for order in get_physical_orders(to_py_date(start_date), to_py_date(end_date))]
6821 amar.kumar 1925
        finally:
1926
            self.closeSession()
6507 anupam.sin 1927
 
6906 rajveer 1928
    def getDocument(self, docType, docSource):
1929
        try:
1930
            return get_document(docType, docSource)
1931
        finally:
1932
            self.closeSession()
6988 rajveer 1933
 
7075 rajveer 1934
    def retrieveInvoice(self, orderId, userId):
6988 rajveer 1935
        try:
7075 rajveer 1936
            return retrieve_invoice(orderId,userId)
6988 rajveer 1937
        finally:
1938
            self.closeSession()
6906 rajveer 1939
 
7027 rajveer 1940
    def receiveUpdatesForRedExpress(self, awbNumber):
1941
        try:
7032 rajveer 1942
            return RedExpressUpdateService.get_updates_for_user(awbNumber)
7027 rajveer 1943
        finally:
1944
            self.closeSession()
1945
 
6985 anupam.sin 1946
    def changeShippingAddress(self, orderId, line1, line2, city, state, pin):
1947
        try:
1948
            return change_shipping_address(orderId, line1, line2, city, state, pin)
1949
        finally:
1950
            self.closeSession()
1951
 
7073 anupam.sin 1952
    def createRechargeTransaction(self, t_rechargeTransaction):
1953
        try:
1954
            return to_t_rechargeTransaction(create_recharge_transaction(t_rechargeTransaction))
1955
        finally:
1956
            self.closeSession()
7084 rajveer 1957
 
1958
    def getRechargeTransactions(self, storeId):
1959
        try:
1960
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_transactions(storeId)]
1961
        finally:
1962
            self.closeSession()
1963
 
7151 amit.gupta 1964
    def getRechargeTrans(self, storeId, startdate, enddate, status):
1965
        try:
1966
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_trans(storeId,startdate, enddate, status)]
1967
        finally:
1968
            self.closeSession()
7084 rajveer 1969
 
7080 anupam.sin 1970
    def getRechargeTransaction(self, rechargeId):
1971
        try:
1972
            return to_t_rechargeTransaction(get_recharge_transaction(rechargeId))
1973
        finally:
1974
            self.closeSession()
1975
 
1976
    def getFRCs(self, circleId, operatorId):
1977
        try:
1978
            return [to_t_frc(frc) for frc in get_frcs(circleId, operatorId)]
1979
        finally:
1980
            self.closeSession()
1981
 
7096 anupam.sin 1982
    def getHotspotStore(self, id, hotspotid):
1983
        try:
1984
            return to_t_hotspot(get_hotspot_store(id, hotspotid))
1985
        finally:
1986
            self.closeSession()
1987
 
1988
    def getTelecomCircle(self, id, code):
1989
        try:
1990
            return get_circle(id, code).to_thrift_object()
1991
        finally:
1992
            self.closeSession()
1993
 
7109 anupam.sin 1994
    def retrieveHotspotRechargeInvoice(self, rechargeId):
1995
        try:
1996
            return retrieve_hotspot_recharge_invoice(rechargeId)
1997
        finally:
1998
            self.closeSession()
7190 amar.kumar 1999
 
2000
    def splitFreebieOrder(self, orderId, splitReason, shippingDate):
2001
        try:
2002
            return split_freebie_order(orderId, splitReason, shippingDate)
2003
        finally:
2004
            self.closeSession()
7109 anupam.sin 2005
 
7172 anupam.sin 2006
    def getRechargeTransactionsByNumber(self, number, storeId):
7169 anupam.sin 2007
        try:
7172 anupam.sin 2008
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_transactions_by_number(number, storeId)]
7169 anupam.sin 2009
        finally:
2010
            self.closeSession()
2011
 
2012
    def updateHotspotStorePassword(self, storeId, password):
2013
        try:
2014
            return update_hotspot_store_password(storeId, password)
2015
        finally:
2016
            self.closeSession()
2017
 
7263 anupam.sin 2018
    def getSourceDetail(self, source):
2019
        try:
2020
            return to_t_sourcedetail(get_source_detail(source))
2021
        finally:
2022
            self.closeSession()
2023
 
7267 anupam.sin 2024
    def getAllCircles(self):
2025
        try:
2026
            return [circle.to_thrift_object() for circle in get_all_circles()]
2027
        finally:
2028
            self.closeSession()
7263 anupam.sin 2029
 
7267 anupam.sin 2030
    def deleteFrcs(self, frcIdsToDelete):
2031
        try:
2032
            return delete_frcs(frcIdsToDelete)
2033
        finally:
2034
            self.closeSession()
7285 rajveer 2035
 
2036
    def topupCompanyWallet(self, companyId, amount):
2037
        try:
2038
            return topup_company_wallet(companyId, amount)
2039
        finally:
2040
            self.closeSession()
2041
 
2042
    def getWalletBalanceForCompany(self, companyId):
2043
        try:
2044
            return get_wallet_balance_for_company(companyId)
2045
        finally:
2046
            self.closeSession()
7311 kshitij.so 2047
 
2048
    def addAmazonOrder(self,amazonOrder):
2049
        try:
2050
            add_amazon_order(amazonOrder)
2051
        except:
2052
            self.closeSession()
2053
 
7322 vikram.rag 2054
    def updateAmazonOrderStatus(self,orderId,status):
7311 kshitij.so 2055
        try:
7577 rajveer 2056
            return update_amazon_order_status(orderId,status)
7311 kshitij.so 2057
        finally:
2058
            self.closeSession()
7322 vikram.rag 2059
 
7683 vikram.rag 2060
    def getAmazonOrdersShipped(self):
7311 kshitij.so 2061
        try:
7683 vikram.rag 2062
            ordersShipped = get_amazon_orders_shipped()
7311 kshitij.so 2063
        finally:
2064
            self.closeSession()
2065
            return ordersShipped
2066
 
2067
    def getAmazonOrdersCancelled(self,interval):
2068
        ordersCancelled=None
2069
        try:
2070
            ordersCancelled = get_amazon_orders_cancelled(interval)
2071
        except:
2072
            ordersCancelled=None
2073
        finally:
2074
            self.closeSession()
2075
            return ordersCancelled
2076
 
7322 vikram.rag 2077
    def getAmazonOrder(self,orderId):
2078
        result = None
2079
        try:
7343 anupam.sin 2080
            result = to_t_amazonorder(get_amazon_order(orderId))
7322 vikram.rag 2081
        finally:
2082
            self.closeSession()
7542 vikram.rag 2083
            return result
2084
 
2085
    def getAmazonOrderByAmazonOrderId(self,amazonOrderId):
2086
        result = []
2087
        try:
2088
            for amazonOrder in get_amazon_order_by_amazonorderid(amazonOrderId): 
2089
                result.append(to_t_amazonorder(amazonOrder))
2090
        except:
2091
            return None
2092
        finally:
2093
            self.closeSession()
2094
            return result
7343 anupam.sin 2095
 
2096
    def getOrdersForStore(self, id, storeId, startDate, endDate, statuses):
2097
        try:
2098
            return [to_t_order(order) for order in get_orders_for_store(id, storeId, to_py_date(startDate), to_py_date(endDate), statuses)]
2099
        finally:
2100
            self.closeSession()
2101
 
7386 anupam.sin 2102
    def getStoreOrderAdvanceInvoice(self, orderId, storeId):
7343 anupam.sin 2103
        try:
7386 anupam.sin 2104
            return get_store_order_advance_invoice(orderId, storeId)
7343 anupam.sin 2105
        finally:
2106
            self.closeSession()
7363 rajveer 2107
 
2108
    def getSaholicRechargeBalance(self):
2109
        try:
2110
            return RechargeService.getBalance()
2111
        finally:
2112
            self.closeSession()
2113
 
7370 anupam.sin 2114
    def addFrc(self, circle, operatorId, denomination, maxDiscount):
2115
        try:
2116
            return add_frc(circle, operatorId, denomination, maxDiscount)
2117
        except:
2118
            return False
2119
        finally:
2120
            self.closeSession()
2121
 
7371 anupam.sin 2122
    def addSeries(self, circle, operatorId, series):
2123
        try:
2124
            return add_series(circle, operatorId, series)
2125
        except:
2126
            return "Error Occured. Try Again."
2127
        finally:
2128
            self.closeSession()
2129
 
7386 anupam.sin 2130
    def saveStoreOrderDetail(self, storeOrderDetail):
2131
        try:
2132
            return save_store_order_detail(storeOrderDetail)
2133
        except:
2134
            return False
2135
        finally:
2136
            self.closeSession()
2137
 
2138
 
2139
    def getStoreOrderDetail(self, orderId, storeId):
2140
        try:
2141
            return to_t_storeOrderDetail(get_store_order_detail(orderId, storeId))
2142
        finally:
2143
            self.closeSession()
2144
 
2145
    def getAllEdcBanks(self):
2146
        try:
2147
            return get_all_edc_banks()
2148
        finally:
2149
            self.closeSession()
7393 anupam.sin 2150
 
2151
    def saveRefundAmountsForStoreOrder(self, orderId, storeId, cashRefundAmount, cardRefundAmount):
2152
        try:
7399 anupam.sin 2153
            return save_refund_amounts_for_store_order(orderId, storeId, cashRefundAmount, cardRefundAmount)
7393 anupam.sin 2154
        finally:
2155
            self.closeSession()
7386 anupam.sin 2156
 
7427 anupam.sin 2157
    def getCollectionsForStore(self, storeId, startDate, endDate):
2158
        try:
2159
            return [to_t_storeOrderCollection(collection) for collection in get_collections_for_store(storeId, startDate, endDate)]
2160
        finally:
2161
            self.closeSession()
7442 vikram.rag 2162
 
2163
    def getAmazonOrdersToAcknowledge(self):
2164
        try:
2165
            ordersack = []
2166
            for amazonOrderId,amazonOrderCode,status,txnid,count in get_amazon_orders_to_acknowledge():
2167
                orderack = AmazonOrdersToAcknowledge()
2168
                orderack.amazonOrderId = amazonOrderId
2169
                orderack.amazonOrderItemId = amazonOrderCode
2170
                orderack.status = status
2171
                orderack.transaction_id = txnid
2172
                orderack.count = count
2173
                ordersack.append(orderack)
2174
            return ordersack    
2175
        except:
2176
            return None
2177
        finally:
2178
            self.closeSession()   
2179
 
2180
    def changeAmazonOrderStatus(self,amazonOrderCode,status):
2181
        try:
2182
            change_amazon_order_status(amazonOrderCode,status) 
2183
        finally:
7460 kshitij.so 2184
            self.closeSession()
2185
 
7741 kshitij.so 2186
    def updateTimestampForAmazonOrder(self,orderDeliveryMap):
7460 kshitij.so 2187
        try:
7741 kshitij.so 2188
            return update_timestamp_for_amazon_order(orderDeliveryMap)
7530 kshitij.so 2189
        except:
2190
            return False
7460 kshitij.so 2191
        finally:
7530 kshitij.so 2192
            self.closeSession()
2193
 
2194
    def updateSourceDetailTimestamp(self,id,lastUpdatedOn):
2195
        try:
2196
            return update_source_detail_timestamp(id,lastUpdatedOn)
2197
        except:
2198
            return False
2199
        finally:
7442 vikram.rag 2200
            self.closeSession()   
7607 anupam.sin 2201
 
2202
    def getOrdersByMobileNumber(self, mobileNumber):
2203
        try:
2204
            orders = get_orders_by_mobile_number(mobileNumber)
2205
            return [to_t_order(order) for order in orders]
2206
        finally:
2207
            self.closeSession()
7427 anupam.sin 2208
 
7645 anupam.sin 2209
    def getOrdersByAmazonOrderCode(self, amazonId):
7607 anupam.sin 2210
        try:
2211
            orders = get_orders_by_amazon_id(amazonId)
2212
            return [to_t_order(order) for order in orders]
2213
        finally:
2214
            self.closeSession()
7730 anupam.sin 2215
 
2216
    def convertStoreToNormal(self, orderId):
2217
        try:
2218
            return convert_store_to_normal(orderId)
2219
        except:
2220
            return False
2221
        finally:
2222
            self.closeSession()
7822 amar.kumar 2223
 
2224
    def updateFreebieItem(self, orderId, newFreebieItemId):
2225
        try:
2226
            return to_t_order(update_freebie_item(orderId, newFreebieItemId))
2227
        finally:
2228
            self.closeSession()
7938 manish.sha 2229
 
7967 anupam.sin 2230
    def getHotspotServiceMatrices(self):
2231
        try:
2232
            return [to_t_hotspotServiceMatrix(hotpotServiceMatrix) for hotpotServiceMatrix in get_hotspot_service_matrices()]
2233
        finally:
2234
            self.closeSession()
2235
 
7938 manish.sha 2236
    def updateOrderAWB(self, orderId, airwayBillNo):
2237
        try:
7985 manish.sha 2238
            return to_t_order(update_order_AWB(orderId, airwayBillNo))
7938 manish.sha 2239
        finally:
2240
            close_session()
8182 amar.kumar 2241
    def getOrdersByVendor(self, vendors, statuses):
2242
        try:
2243
            return [to_t_order(order) for order in get_orders_by_vendor(vendors, statuses)]
2244
        finally:
2245
            close_session()
7607 anupam.sin 2246
 
8182 amar.kumar 2247
    def createEbayOrder(self, ebayOrder):
2248
        try:
2249
            create_ebay_order(ebayOrder)
2250
        finally:
2251
            close_session()
2252
    def getEbayOrderByOrderId(self, orderId):
2253
        try:
2254
            return to_t_ebayOrder(get_ebay_order_by_orderId(orderId))
2255
        finally:
2256
            close_session()
2257
 
2258
    def getEbayOrderBySalesRecNumber(self, salesRecordNumber):
2259
        try:
2260
            return to_t_ebayOrder(get_ebay_order_by_sales_rec_number(salesRecordNumber))
2261
        finally:
2262
            close_session()
2263
 
8241 amar.kumar 2264
    def getEbayOrder(self, salesRecordNumber, listingId, paisaPayId):
8182 amar.kumar 2265
        try:
8253 amar.kumar 2266
            return [to_t_ebayOrder(order) for order in get_ebay_order(salesRecordNumber, listingId, paisaPayId)]
8182 amar.kumar 2267
        finally:
2268
            close_session()
2269
 
2270
    def updateEbayOrder(self, ebayOrder):
2271
        try:
2272
            update_ebay_order(ebayOrder)
2273
        finally:
2274
            close_session()
2275
 
2276
    def ebayOrderExists(self, salesRecNumber, ebayListingId):
2277
        try:
2278
            return ebay_order_exists(salesRecNumber, ebayListingId)
2279
        finally:
2280
            close_session()
2281
 
2282
    def updateOrderForEbay(self, order):
2283
        try:
2284
            update_order_for_ebay(order)
2285
        finally:
2286
            close_session()
2287
 
2288
    def splitEbayOrder(self, orderId, splitOrderQty, splitOrderItemId, usePowerShip):
2289
        try:
2290
            return to_t_order(split_ebay_order(orderId, splitOrderQty, splitOrderItemId, usePowerShip))
2291
        finally:
2292
            close_session()
8282 kshitij.so 2293
 
2294
    def addOrUpdateAmazonFbaSalesSnapshot(self,amazonfbasalessnapshot):
2295
        try:
2296
            add_or_update_amazon_fba_sales_snapshot(amazonfbasalessnapshot)
2297
        finally:
2298
            close_session()
2299
 
2300
    def getAmazonFbaSalesSnapshotForDays(self,days):
2301
        fbasalessnapshot = []
2302
        try:
2303
            snapshots = get_amazon_fba_sales_snapshot_for_days(days)
2304
            for snapshot in snapshots:
2305
                fbasalessnapshot.append(to_t_amazonFbaSalesSnapshot(snapshot)) 
2306
            return fbasalessnapshot
2307
        except:
2308
            return None
2309
        finally:
2310
            close_session()
2311
 
2312
    def getAmazonFbaSalesLatestSnapshotForItem(self,item_id):
2313
        try:
8363 vikram.rag 2314
            return to_t_amazonFbaSalesSnapshot(get_amazon_fba_sales_latest_snapshot_for_item(item_id))
8282 kshitij.so 2315
        except:
2316
            return None
2317
        finally:
2318
            close_session()
8532 vikram.rag 2319
 
8488 amar.kumar 2320
    def createSnapdealOrder(self, snapdeal_order):
2321
        try:
2322
            create_snapdeal_order(snapdeal_order)
2323
        finally:
2324
            close_session()
2325
 
2326
    def getSnapdealOrder(self, orderId, reference_code, suborder_id):
2327
        try:
8543 amar.kumar 2328
            return to_t_snapdealOrder(get_snapdeal_order(orderId, reference_code, suborder_id))
8488 amar.kumar 2329
        finally:
2330
            close_session()
2331
 
8802 amar.kumar 2332
    def snapdealOrderExists(self, suborder_id, referenceCode):
8488 amar.kumar 2333
        try:
8802 amar.kumar 2334
            return snapdeal_order_exists(suborder_id, referenceCode)
8488 amar.kumar 2335
        finally:
2336
            close_session()   
8532 vikram.rag 2337
 
2338
    def updateLatestFbaPricesForItem(self,fbaitemprices):
2339
        try:        
2340
            update_latest_fba_prices_for_item(fbaitemprices)
2341
        finally:
8961 vikram.rag 2342
            close_session()
2343
 
2344
    def flipkartOrderExists(self,flipkartOrderId,flipkartSubOrderId):
2345
        try:
2346
            return flipkart_order_exists(flipkartOrderId,flipkartSubOrderId)
2347
        finally:
2348
            self.closeSession()
8532 vikram.rag 2349
 
8961 vikram.rag 2350
    def createFlipkartOrder(self,flipkartOrder):
2351
        try:
2352
            create_flipkart_order(flipkartOrder)
2353
        finally:           
8990 vikram.rag 2354
            self.closeSession()
2355
 
2356
    def getFlipkartOrder(self,orderId):
2357
        try:
2358
            return to_t_flipkartOrder(get_flipkart_order(orderId))
2359
        finally:
9159 amar.kumar 2360
            self.closeSession()    
2361
 
2362
    def getFlipkartOrderByOrderItemId(self, flipkartOrderItemId):
2363
        try:
2364
            return to_t_flipkartOrder(get_flipkart_order_by_subOrderId(flipkartOrderItemId))
2365
        finally:
2366
            close_session()    
9107 vikram.rag 2367
            self.closeSession()
2368
 
2369
    def updateFlipkartOrderDatesAndAWB(self,flipkartOrderId,flipkartSubOrderId,date,awb):
2370
        try:
2371
            return update_flipkart_order_dates_and_awb(flipkartOrderId,flipkartSubOrderId,date,awb)
2372
        finally:
2373
            self.closeSession()
9338 manish.sha 2374
 
9571 vikram.rag 2375
    def getOrdersCreatedAfterTimestampForSource(self,timestamp,source):
9404 vikram.rag 2376
        try:
9571 vikram.rag 2377
            return get_orders_count_created_after_timestamp_for_source(timestamp,source)
9404 vikram.rag 2378
        finally:
2379
            self.closeSession()
2380
 
2381
 
9338 manish.sha 2382
    def getOrderForAirwayBillNo(self, airwaybillNo):
2383
        try:
2384
            return to_t_order(get_order_for_airwayBillNo(airwaybillNo))
2385
        finally:
2386
            close_session()
2387
 
9651 manish.sha 2388
    def getMinCreatedTimeStampUndeliveredOrdersForSource(self, source): 
2389
        try:
2390
            return get_min_created_timestamp_undelivered_orders_for_source(source)
2391
        finally:
2392
            close_session()
2393
 
2394
    def updateSnapdealOrdersStatus(self, delivered_orders):
2395
        try:
2396
            update_snapdeal_orders_status(delivered_orders)
2397
        finally:
2398
            close_session()
2399
 
2400
    def updateFlipkartOrdersStatus(self, delivered_orders):
2401
        try:
2402
            update_flipkart_orders_status(delivered_orders)
2403
        finally:
2404
            close_session()
9801 manish.sha 2405
 
2406
    def bulkAddOrUpdateAmazonFbaSalesSnapshot(self, amazonfbasalessnapshotlist):  
2407
        try:
2408
            bulk_add_or_update_amazon_fba_sales_snapshot(amazonfbasalessnapshotlist)
2409
        finally:
2410
            close_session()              
9651 manish.sha 2411
 
2536 chandransh 2412
    def closeSession(self, ):
2413
        close_session()
3376 rajveer 2414
 
2415
    def isAlive(self, ):
2416
        """
5447 anupam.sin 2417
        For checking whether service is alive or not. It also checks connectivity with database
3376 rajveer 2418
        """
2419
        try:
2420
            return is_alive()
2421
        finally:
6988 rajveer 2422
            close_session()