Subversion Repositories SmartDukaan

Rev

Rev 7027 | Rev 7073 | 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
7032 rajveer 7
from shop2020.model.v1.order.impl import DataService, RedExpressUpdateService
6000 mandeep.dh 8
from shop2020.model.v1.order.impl.Convertors import to_t_transaction, to_t_alert, \
9
    to_t_order, to_t_lineitem, to_t_payment_settlement, to_t_verification_agent, \
10
    to_t_attribute
11
from shop2020.model.v1.order.impl.DataAccessors import create_transaction, \
12
    get_transactions_for_customer, get_transaction_status, get_line_items_for_order, \
13
    get_transaction, get_transactions_for_shopping_cart_id, \
14
    change_transaction_status, get_orders_for_customer, get_orders_for_transaction, \
15
    get_order, get_returnable_orders_for_customer, \
16
    get_cancellable_orders_for_customer, get_orders_by_billing_date, get_all_orders, \
17
    change_order_status, get_alerts, add_alert, add_billing_details, close_session, \
18
    accept_order, mark_orders_as_picked_up, mark_orders_as_delivered, \
19
    mark_orders_as_rto, order_outofstock, batch_orders, update_non_delivery_reason, \
20
    enqueue_transaction_info_email, get_undelivered_orders, get_order_for_customer, \
21
    get_valid_order_count, get_cust_count_with_successful_txn, \
22
    get_valid_orders_amount_range, get_valid_orders, toggle_doa_flag, \
23
    request_pickup_number, authorize_pickup, receive_return, validate_doa, \
24
    reship_order, refund_order, get_return_orders, process_return, get_return_order, \
25
    mark_doas_as_picked_up, verify_order, is_alive, get_orders_by_shipping_date, \
26
    update_weight, change_warehouse, change_product, add_delay_reason, \
27
    reconcile_cod_collection, get_transactions_requiring_extra_processing, \
28
    mark_transaction_as_processed, get_item_wise_risky_orders_count, \
29
    accept_order_for_item, get_orders_in_batch, get_order_count, \
30
    get_ebs_settlement_summaries, mark_order_cancellation_request_received, \
31
    mark_order_cancellation_request_denied, refund_transaction, \
32
    mark_order_cancellation_request_confirmed, \
33
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id, \
34
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated, \
35
    mark_orders_as_not_available, update_shipment_address, mark_orders_as_timeout, \
36
    get_order_for_awb, mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
37
    mark_order_doa_request_received, mark_order_doa_request_authorized, \
38
    mark_order_return_request_received, mark_order_return_request_authorized, \
39
    add_invoice_number, get_reshipped_order_ids, validate_return_product, \
40
    get_orders_for_provider_for_status, save_ebs_settlement_summary, \
41
    get_ebs_settlement_date, save_payment_settlements, mark_ebs_settlement_uploaded, \
42
    get_billed_orders_for_vendor, get_settlement_for_Prepaid, \
43
    get_settlements_by_date, get_slipped_sipping_date_orders, \
44
    mark_order_as_lost_in_transit, get_cancelled_orders, mark_order_as_delivered, \
45
    mark_return_orders_as_picked_up, update_orders_as_PORaised, \
46
    get_order_distribution_by_status, get_orders_not_met_expected_delivery_date, \
47
    mark_orders_as_local_connected, mark_orders_as_destinationCityReached, \
48
    mark_orders_as_firstDeliveryAttempted, get_non_delivered_orders_by_courier, \
49
    get_orders_not_local_connected, get_doas_not_picked_up, \
50
    get_return_orders_not_picked_up, get_orders_not_picked_up, get_rto_orders, \
51
    get_order_list, get_order_ids_for_status, update_orders_as_paid_to_vendor, \
52
    update_COD_agent, get_refunded_orders_marked_paid, get_settlement_for_Cod, \
53
    get_order_list_for_vendor, update_order_only_as_paid_to_vendor, \
54
    get_all_verification_agents, get_all_attributes_for_order_id, \
55
    set_order_attribute_for_transaction, get_billed_orders, get_all_return_orders, \
56
    mark_order_as_received_at_store, get_receive_pending_orders, \
57
    get_received_at_store_orders, mark_orders_as_returned_from_store, \
6056 amit.gupta 58
    set_order_attributes, get_orders_collection_at_store, get_order_attribute_value, \
59
    change_jacket_number, mark_order_as_rto_in_transit, get_recharge_order, \
60
    get_recharge_orders, update_recharge_order_status, activate_recharge_txn, \
61
    get_user_wallet, get_user_wallet_history, get_service_providers, \
6396 amit.gupta 62
    get_service_provider_for_device, get_recharge_orders_for_transaction, \
63
    update_amount_in_wallet, get_recharge_orders_for_device, \
64
    get_recharge_orders_for_status, get_plans_for_operator, get_recharge_statistics, \
65
    validate_recharge, get_recharge_denominations, update_availability_status, \
6821 amar.kumar 66
    get_misc_charges, get_available_emi_schemes, refund_recharge_order, \
6988 rajveer 67
    get_physical_orders, get_document, retrieve_invoice, change_shipping_address
6000 mandeep.dh 68
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
6056 amit.gupta 69
from shop2020.model.v1.order.impl.model.DigitalTransaction import \
70
    DigitalTransaction
6000 mandeep.dh 71
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
72
    MobileRechargeOrder
73
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
74
    RechargeType
75
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
6031 rajveer 76
import datetime
1405 ankur.sing 77
 
5527 anupam.sin 78
 
104 ashish 79
 
80
class OrderServiceHandler:
81
 
3187 rajveer 82
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 83
        """
104 ashish 84
        Constructor
483 rajveer 85
        """
3187 rajveer 86
        DataService.initialize(dbname, db_hostname)
104 ashish 87
 
88
    def createTransaction(self, transaction):
89
        """
90
        Parameters:
91
         - transaction
92
        """
766 rajveer 93
        try:
94
            return create_transaction(transaction)
95
        finally:
96
            close_session()
97
 
104 ashish 98
    def getTransaction(self, id):
99
        """
100
            Get transaction methods.
101
 
102
        Parameters:
103
         - id
104
        """
766 rajveer 105
        try:
106
            transaction = get_transaction(id)
107
            return to_t_transaction(transaction)
108
        finally:
109
            close_session()
110
 
483 rajveer 111
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 112
        """
113
        Parameters:
483 rajveer 114
         - customerId
104 ashish 115
         - from_date
116
         - to_date
483 rajveer 117
         - status
104 ashish 118
        """
766 rajveer 119
        try:
120
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
121
 
122
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
123
            t_transaction = []
124
            for transaction in transactions:
125
                t_transaction.append(to_t_transaction(transaction))
126
            return t_transaction
127
        finally:
128
            close_session()
483 rajveer 129
 
130
    def getTransactionsForShoppingCartId(self, shoppingCartId):
131
        """
132
        Parameters:
133
            - shoppingCartId
134
        """
766 rajveer 135
        try:
136
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
137
            t_transaction = []
138
            for transaction in transactions:
139
                t_transaction.append(to_t_transaction(transaction))
140
            return t_transaction
141
        finally:
142
            close_session()
104 ashish 143
 
483 rajveer 144
    def getTransactionStatus(self, transactionId):
104 ashish 145
        """
146
        Parameters:
483 rajveer 147
         - transactionId
148
        """
766 rajveer 149
        try:
150
            return get_transaction_status(transactionId)
151
        finally:
152
            close_session()
153
 
5527 anupam.sin 154
    def changeTransactionStatus(self, transactionId, status, description, pickUp, orderType):
483 rajveer 155
        """
156
        Parameters:
157
         - transactionId
104 ashish 158
         - status
483 rajveer 159
         - description
5387 rajveer 160
         - selfPickup
483 rajveer 161
        """
766 rajveer 162
        try:
5527 anupam.sin 163
            return change_transaction_status(transactionId, status, description, pickUp, orderType)
766 rajveer 164
        finally:
165
            close_session()
166
 
1528 ankur.sing 167
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 168
        """
1528 ankur.sing 169
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
170
        only user who owns the transaction can view its order details.
171
 
483 rajveer 172
        Parameters:
173
         - transactionId
1528 ankur.sing 174
         - customerId
483 rajveer 175
        """
766 rajveer 176
        try:
1528 ankur.sing 177
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 178
            return [to_t_order(order) for order in orders]    
179
        finally:
180
            close_session()
181
 
4801 anupam.sin 182
    def getAllOrders(self, statuses, from_date, to_date, warehouse_id):
483 rajveer 183
        """
184
        Parameters:
185
         - status
104 ashish 186
         - from_date
187
         - to_date
483 rajveer 188
         - warehouse_id
104 ashish 189
        """
766 rajveer 190
        try:
191
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
4801 anupam.sin 192
            orders = get_all_orders(statuses, current_from_date, current_to_date, warehouse_id)
766 rajveer 193
            return [to_t_order(order) for order in orders]
194
        finally:
195
            close_session()
4133 chandransh 196
 
197
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id):
198
        """
199
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
200
        Pass the status as null and the limit as 0 to ignore them.
201
 
202
        Parameters:
203
         - statuses
204
         - offset
205
         - limit
206
         - warehouse_id
207
        """
208
        try:
209
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id)
210
            return [to_t_order(order) for order in orders]
211
        finally:
212
            close_session()
213
 
214
    def getOrderCount(self, statuses, warehouseId):
215
        """
216
        Returns the count of orders with the given statuses assigned to the given warehouse.
217
 
218
        Parameters:
219
         - statuses
220
         - warehouseId
221
        """
222
        try:
223
            return get_order_count(statuses, warehouseId)
224
        finally:
225
            close_session()
226
 
995 varun.gupt 227
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
228
        """
229
        Parameters:
230
         - status
231
         - start_billing_date
232
         - end_billing_date
233
         - warehouse_id
234
        """
235
        try:
236
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
237
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
238
            return [to_t_order(order) for order in orders]
239
        finally:
240
            close_session()
1382 varun.gupt 241
 
3451 chandransh 242
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 243
        """
244
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 245
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
246
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 247
 
248
        Parameters:
249
         - fromShippingDate
250
         - toShippingDate
251
         - providerId
252
         - warehouseId
3451 chandransh 253
         - cod
3427 chandransh 254
        """
255
        try:
256
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 257
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 258
            return [to_t_order(order) for order in orders]
259
        finally:
260
            close_session()
261
 
1382 varun.gupt 262
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
263
        """
264
        Parameters:
265
         - customerId
266
         - limit
267
        """
268
        try:
269
            return get_returnable_orders_for_customer(customerId, limit)
270
        finally:
271
            close_session()
995 varun.gupt 272
 
1382 varun.gupt 273
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
274
        """
275
        Parameters:
276
         - customerId
277
         - limit
278
        """
279
        try:
280
            return get_cancellable_orders_for_customer(customerId, limit)
281
        finally:
282
            close_session()
283
 
483 rajveer 284
    def changeOrderStatus(self, orderId, status, description):
285
        """
286
        Parameters:
287
         - orderId
288
         - status
289
         - description
290
         - 
291
        """
766 rajveer 292
        try:
293
            return change_order_status(self, orderId, status, description)
294
        finally:
295
            close_session()
921 rajveer 296
 
3064 chandransh 297
    def verifyOrder(self, orderId):
298
        """
299
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
300
        timestamp. It is intended to be used for COD orders but can be harmlessly
301
        used for all other orders as well.
302
        Throws an exception if no such order exists.
303
 
304
        Parameters:
305
         - orderId
306
        """
307
        try:
308
            return verify_order(self, orderId)
309
        finally:
310
            close_session()
311
 
921 rajveer 312
    def acceptOrder(self, orderId):
313
        """
3064 chandransh 314
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
315
        given order is not a COD order, it also captures the payment if the same has
316
        not been captured.
317
        Throws an exception if no such order exists.
318
 
921 rajveer 319
        Parameters:
320
         - orderId
321
        """
322
        try:
4285 rajveer 323
            return accept_order(orderId)
921 rajveer 324
        finally:
325
            close_session()
326
 
3014 chandransh 327
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 328
        """
3014 chandransh 329
        Returns list of orders for the given customer created between the given dates and having the given statuses.
330
        Pass and empty list to ignore filtering on statuses.
331
 
104 ashish 332
        Parameters:
333
         - customerId
334
         - from_date
335
         - to_date
3014 chandransh 336
         - statuses
104 ashish 337
        """
766 rajveer 338
        try:
339
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
340
 
3014 chandransh 341
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 342
            return [to_t_order(order) for order in orders]
343
        finally:
344
            close_session()
1528 ankur.sing 345
 
346
    def getOrderForCustomer(self, orderId, customerId):
347
        """
348
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
349
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
350
 
351
        Parameters:
352
         - customerId
353
         - orderId
354
        """
355
        try:
356
            return to_t_order(get_order_for_customer(orderId, customerId))
357
        finally:
358
            close_session()
766 rajveer 359
 
483 rajveer 360
    def getOrder(self, id):
361
        """
362
        Parameters:
363
         - id
364
        """
766 rajveer 365
        try:
366
            return to_t_order(get_order(id))
367
        finally:
368
            close_session()
4999 phani.kuma 369
 
370
    def getOrderList(self, order_ids):
371
        """
372
        Parameters:
373
         - order_ids
374
        """
375
        try:
376
            orders = get_order_list(order_ids)
377
            return [to_t_order(order) for order in orders]
378
        finally:
379
            close_session()
380
 
5386 phani.kuma 381
    def getOrderListForVendor(self, order_ids, vendorId):
382
        """
383
        Parameters:
384
         - order_ids
385
         - vendorId
386
        """
387
        try:
388
            orders = get_order_list_for_vendor(order_ids, vendorId)
389
            return [to_t_order(order) for order in orders]
390
        finally:
391
            close_session()
392
 
483 rajveer 393
    def getLineItemsForOrder(self, orderId):
394
        """
395
        Parameters:
396
         - orderId
397
        """
766 rajveer 398
        try:
399
            lineitems = get_line_items_for_order(orderId)
400
            t_lineitems = []
401
            for lineitem in lineitems:
402
                t_lineitems.append(to_t_lineitem(lineitem))
403
            return t_lineitems
404
        finally:
405
            close_session()
1149 chandransh 406
 
4763 rajveer 407
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 408
        """
4658 mandeep.dh 409
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 410
        Also marks the order as billed and sets the billing timestamp.
411
        Return false if it doesn't find the order with the given ID.
1149 chandransh 412
 
413
        Parameters:
414
         - orderId
415
         - jacketNumber
4658 mandeep.dh 416
         - serialNumber
2783 chandransh 417
         - itemNumber
418
         - billedBy
1149 chandransh 419
        """
420
        try:
4763 rajveer 421
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 422
        finally:
423
            close_session()
1220 chandransh 424
 
6751 amar.kumar 425
    def addInvoiceNumber(self, orderId, invoiceNumber, color, serialNumber, itemNumber):
4579 rajveer 426
        """
427
        Add the invoice number to the order.
428
 
429
        Parameters:
430
         - orderId
431
         - invoice_number
432
        """
433
        try:
6751 amar.kumar 434
            add_invoice_number(orderId, invoiceNumber, color, serialNumber, itemNumber)
4579 rajveer 435
        finally:
436
            close_session()
437
 
1220 chandransh 438
    def batchOrders(self, warehouseId):
439
        """
440
        Create a batch of all the pending orders for the given warehouse.
441
        The returned list is orderd by created_timestamp.
442
        If there are no pending orders, an empty list is returned.
1208 chandransh 443
 
1220 chandransh 444
        Parameters:
445
         - warehouseId
446
        """
447
        try:
448
            pending_orders = batch_orders(warehouseId)
449
            return [to_t_order(order) for order in pending_orders]
450
        finally:
451
            close_session()
452
 
1208 chandransh 453
    def markOrderAsOutOfStock(self, orderId):
454
        """
455
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
456
 
457
 
458
        Parameters:
459
         - orderId
460
        """
461
        try:
462
            return order_outofstock(orderId)
463
        finally:
464
            close_session()
465
 
4910 phani.kuma 466
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod, orderIds):
759 chandransh 467
        """
3064 chandransh 468
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4910 phani.kuma 469
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 470
 
471
        Parameters:
472
         - warehouseId
473
         - providerId
3064 chandransh 474
         - cod
759 chandransh 475
        """
766 rajveer 476
        try:
4910 phani.kuma 477
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds)
766 rajveer 478
        finally:
479
            close_session()
1113 chandransh 480
 
5713 rajveer 481
    def markOrdersAsReturnedFromStore(self, providerId, orderIds, awbs):
5676 rajveer 482
        """
483
        Parameters:
484
         - providerId
485
         - orderIds
5713 rajveer 486
         - awbs
5676 rajveer 487
        """
488
        try:
5713 rajveer 489
            return mark_orders_as_returned_from_store(providerId, orderIds, awbs)
5676 rajveer 490
        finally:
491
            close_session()
492
 
493
    def setOrderAttributes(self, orderId, attributes):
494
        """
495
        sets attributes for an order
496
 
497
        Parameters:
498
         - orderId
499
         - attributes
500
        """
501
        try:
502
            return set_order_attributes(orderId, attributes)
503
        finally:
504
            close_session()
505
 
506
 
4910 phani.kuma 507
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
4410 rajveer 508
        """
4910 phani.kuma 509
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
510
        Raises an exception if we encounter report for an AWB number that we did not ship.
4410 rajveer 511
 
512
        Parameters:
513
         - providerId
4910 phani.kuma 514
         - pickupDetails
4410 rajveer 515
        """
516
        try:
4910 phani.kuma 517
            mark_orders_as_picked_up(providerId, pickupDetails)
4410 rajveer 518
        finally:
519
            close_session()
520
 
4910 phani.kuma 521
    def getOrdersNotPickedUp(self, providerId):
1113 chandransh 522
        """
523
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
524
 
525
        Parameters:
526
         - providerId
527
        """
528
        try:
4910 phani.kuma 529
            orders_not_picked_up = get_orders_not_picked_up(providerId)
1113 chandransh 530
            return [to_t_order(order) for order in orders_not_picked_up]
531
        finally:
532
            close_session()
1132 chandransh 533
 
534
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
535
        """
536
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
537
        the name of the receiver.
538
        Raises an exception if we encounter report for an AWB number that we did not ship.
539
 
540
        Parameters:
541
         - providerId
542
         - deliveredOrders
543
        """
544
        try:
545
            mark_orders_as_delivered(providerId, deliveredOrders)
546
        finally:
547
            close_session()
1135 chandransh 548
 
4712 rajveer 549
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
550
        """
551
        Attributes:
552
         - orderId
553
         - deliveryTimestamp
554
         - receiver
555
        """
556
        try:
557
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
558
        finally:
559
            close_session()
560
 
561
 
5555 rajveer 562
    def markOrderAsReceivedAtStore(self, orderId, deliveryTimestamp):
563
        """
564
        Attributes:
565
         - orderId
566
         - deliveryTimestamp
567
        """
568
        try:
569
            mark_order_as_received_at_store(orderId, to_py_date(deliveryTimestamp))
570
        finally:
571
            close_session()
572
 
573
    def getReceivePendingOrders(self, storeId):
574
        """
575
        Attributes:
576
         - storeId
577
        """
578
        try:
579
            orders = get_receive_pending_orders(storeId)
580
            return [to_t_order(order) for order in orders]
581
        finally:
582
            close_session()
583
 
584
    def getReceivedAtStoreOrders(self, storeId):
585
        """
586
        Attributes:
587
         - storeId
588
        """
589
        try:
590
            orders = get_received_at_store_orders(storeId)
591
            return [to_t_order(order) for order in orders]
592
        finally:
593
            close_session()
5713 rajveer 594
 
595
    def getOrdersCollectionAtStore(self, storeId, fromDate, toDate, onlyCod):
596
        """
597
        Parameters:
598
         - storeId
599
         - fromDate
600
         - toDate
601
         - onlyCod
602
        """
603
        try:
604
            orders = get_orders_collection_at_store(storeId, to_py_date(fromDate), to_py_date(toDate), onlyCod)
605
            return [to_t_order(order) for order in orders]
606
        finally:
607
            close_session()
608
 
4910 phani.kuma 609
    def markAsRTOrders(self, providerId, returnedOrders):
1135 chandransh 610
        """
4910 phani.kuma 611
        Mark all orders with AWBs in the given map as RTO. Also sets the delivery timestamp.
1135 chandransh 612
        Raises an exception if we encounter report for an AWB number that we did not ship.
613
 
614
        Parameters:
615
         - providerId
616
         - returnedOrders
617
        """
618
        try:
4910 phani.kuma 619
            mark_orders_as_rto(providerId, returnedOrders)
1135 chandransh 620
        finally:
621
            close_session()
1246 chandransh 622
 
4910 phani.kuma 623
    def getRTOrders(self, providerId):
624
        """
625
        Returns a list of orders that were returned by courier.
626
 
627
        Parameters:
628
         - providerId
629
        """
630
        try:
631
            rto_orders = get_rto_orders(providerId)
632
            return [to_t_order(order) for order in rto_orders]
633
        finally:
634
            close_session()
635
 
1246 chandransh 636
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
637
        """
638
        Update the status description of orders whose AWB numbers are keys of the Map.
639
 
640
        Parameters:
641
         - providerId
642
         - undelivered_orders
643
        """
644
        try:
4910 phani.kuma 645
            update_non_delivery_reason(providerId, undeliveredOrders)
646
        finally:
647
            close_session()
648
 
649
    def getNonDeliveredOrdersbyCourier(self, providerId):
650
        """
651
        Returns a list of orders that were picked up or shipped four days ago but did not get delivered.
652
 
653
        Parameters:
654
         - providerId
655
        """
656
        try:
657
            orders_not_delivered = get_non_delivered_orders_by_courier(providerId)
4581 phani.kuma 658
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 659
        finally:
660
            close_session()
1405 ankur.sing 661
 
4910 phani.kuma 662
    def markOrdersAsLocalConnected(self, providerId, local_connected_orders):
663
        """
664
        Mark all orders with AWBs in the given map as local connected. Also sets the local connected timestamp.
665
 
666
        Parameters:
667
         - providerId
668
         - local_connected_orders
669
        """
670
        try:
671
            mark_orders_as_local_connected(providerId, local_connected_orders)
672
        finally:
673
            close_session()
674
 
675
    def getOrdersNotLocalConnected(self, providerId):
676
        """
677
        Returns a list of orders that were picked up or shipped but pending local connection.
678
 
679
        Parameters:
680
         - providerId
681
        """
682
        try:
683
            orders_pending_local_connection = get_orders_not_local_connected(providerId)
684
            return [to_t_order(order) for order in orders_pending_local_connection]
685
        finally:
686
            close_session()
687
 
688
    def markOrdersAsDestinationCityReached(self, providerId, destination_city_reached_orders):
689
        """
690
        Mark all orders with AWBs in the given map as reached destination city. Also sets the reached destination timestamp.
691
 
692
        Parameters:
693
         - providerId
694
         - destination_city_reached_orders
695
        """
696
        try:
697
            mark_orders_as_destinationCityReached(providerId, destination_city_reached_orders)
698
        finally:
699
            close_session()
700
 
701
    def markOrdersAsFirstDeliveryAttempted(self, providerId, first_atdl_orders):
702
        """
703
        Mark all orders with AWBs in the given map as first delivery attempt made. Also sets the first delivery attempted timestamp.
704
 
705
        Parameters:
706
         - providerId
707
         - first_atdl_orders
708
        """
709
        try:
710
            mark_orders_as_firstDeliveryAttempted(providerId, first_atdl_orders)
711
        finally:
712
            close_session()
713
 
4783 phani.kuma 714
    def getUndeliveredOrdersExpectedDeliveryDateNotMet(self):
715
        """
716
        Returns the list of orders whose expected delivery date has passed but have not been
717
        delivered yet.
718
        Returns an empty list if no such orders exist.
719
        """
720
        try:
721
            orders_not_delivered = get_orders_not_met_expected_delivery_date()
722
            return [to_t_order(order) for order in orders_not_delivered]
723
        finally:
724
            close_session()
725
 
1405 ankur.sing 726
    def getUndeliveredOrders(self, providerId, warehouseId):
727
        """
728
        Returns the list of orders whose delivery time has passed but have not been
729
        delivered yet for the given provider and warehouse. To get a complete list of
730
        undelivered orders, pass them as -1.
731
        Returns an empty list if no such orders exist.
732
 
733
        Parameters:
734
         - providerId
735
         - warehouseId
736
        """
737
        try:
738
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
739
            return [to_t_order(order) for order in undelivered_orders]
740
        finally:
741
            close_session()
1351 varun.gupt 742
 
1398 varun.gupt 743
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 744
        """
1398 varun.gupt 745
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 746
 
747
        Parameters:
748
         - transactionId
749
        """
750
        try:
1398 varun.gupt 751
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 752
        finally:
753
            close_session()
754
 
4444 rajveer 755
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 756
        """
757
        Parameters:
4394 rajveer 758
         - type
4444 rajveer 759
         - warehouseId
4394 rajveer 760
         - status
761
         - timestamp
483 rajveer 762
        """
766 rajveer 763
        try:
4444 rajveer 764
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 765
 
766
            t_alerts = []
767
            for alert in alerts:
768
                t_alerts.append(to_t_alert(alert)) 
769
 
770
            return t_alerts
771
        finally:
772
            close_session()
4394 rajveer 773
 
4447 rajveer 774
    def addAlert(self, type, warehouseId, description):
483 rajveer 775
        """
776
        Parameters:
777
         - type
4394 rajveer 778
         - description
4447 rajveer 779
         - warehouseId
483 rajveer 780
        """
766 rajveer 781
        try:
4447 rajveer 782
            add_alert(type, warehouseId, description)
766 rajveer 783
        finally:
784
            close_session()
1596 ankur.sing 785
 
4444 rajveer 786
    def markAlertsAsSeen(self, warehouseId):
787
        """
788
        Parameters:
789
         - warehouseId
790
        """
791
        try:
792
            mark_alerts_as_seen(warehouseId)
793
        finally:
794
            close_session()
795
        pass
796
 
1596 ankur.sing 797
    def getValidOrderCount(self, ):
798
        """
799
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
800
        """
1731 ankur.sing 801
        try:
802
            return get_valid_order_count()
803
        finally:
804
            close_session()
1627 ankur.sing 805
 
806
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
807
        """
808
        Returns the number of distinct customers who have done successful transactions
809
        """
1731 ankur.sing 810
        try:
811
            return get_cust_count_with_successful_txn()
812
        finally:
813
            close_session()
1627 ankur.sing 814
 
1731 ankur.sing 815
 
816
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 817
        """
1731 ankur.sing 818
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
819
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 820
        """
1731 ankur.sing 821
        try:
822
            return get_valid_orders_amount_range()
823
        finally:
824
            close_session()
1627 ankur.sing 825
 
5874 rajveer 826
    def getValidOrders(self, limit, onlyStore):
1886 ankur.sing 827
        """
828
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
829
        If limit is passed as 0, then all valid Orders are returned.
830
 
831
        Parameters:
832
         - limit
5874 rajveer 833
         - onlyStore
1886 ankur.sing 834
        """
835
        try:
5874 rajveer 836
            return [to_t_order(order) for order in get_valid_orders(limit, onlyStore)]
1886 ankur.sing 837
        finally:
838
            close_session()
104 ashish 839
 
2536 chandransh 840
    def toggleDOAFlag(self, orderId):
104 ashish 841
        """
2536 chandransh 842
        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.
843
        Returns the final flag status.
844
        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 845
 
132 ashish 846
        Parameters:
2536 chandransh 847
         - orderId
132 ashish 848
        """
2536 chandransh 849
        try:
850
            return toggle_doa_flag(orderId)
851
        finally:
852
            close_session()
483 rajveer 853
 
4454 rajveer 854
    def markOrderDoaRequestReceived(self, orderId):
855
        """
856
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
857
 
858
        Parameters:
859
         - orderId
860
        """
861
        try:
862
            return mark_order_doa_request_received(orderId)
863
        finally:
864
            close_session()
865
 
866
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized):
867
        """
868
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
869
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
870
 
871
        Parameters:
872
         - orderId
873
         - isAuthorized
874
        """
875
        try:
876
            return mark_order_doa_request_authorized(orderId, isAuthorized)
877
        finally:
878
            close_session()
879
 
4488 rajveer 880
    def markOrderReturnRequestReceived(self, orderId):
881
        """
882
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
883
 
884
        Parameters:
885
         - orderId
886
        """
887
        try:
888
            return mark_order_return_request_received(orderId)
889
        finally:
890
            close_session()
891
 
892
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized):
893
        """
894
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
895
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
896
 
897
        Parameters:
898
         - orderId
899
         - isAuthorized
900
        """
901
        try:
902
            return mark_order_return_request_authorized(orderId, isAuthorized)
903
        finally:
904
            close_session()
905
 
4579 rajveer 906
    def requestPickupNumber(self, orderId, providerId):
104 ashish 907
        """
2536 chandransh 908
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 909
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
910
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 911
        For any other status, it returns false.
912
        Throws an exception if the order with the given id couldn't be found.
104 ashish 913
 
914
        Parameters:
2536 chandransh 915
         - orderId
104 ashish 916
        """
2536 chandransh 917
        try:
4579 rajveer 918
            return request_pickup_number(orderId, providerId)
2536 chandransh 919
        finally:
920
            close_session()
483 rajveer 921
 
4602 rajveer 922
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 923
        """
4452 rajveer 924
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 925
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
926
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
927
            3. Returns true
928
        If the order is any other status, it returns false.
929
        Throws an exception if the order with the given id couldn't be found.
304 ashish 930
 
931
        Parameters:
2536 chandransh 932
         - orderId
933
         - pickupNumber
304 ashish 934
        """
2536 chandransh 935
        try:
4602 rajveer 936
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 937
        finally:
938
            close_session()    
2764 chandransh 939
 
940
    def markDoasAsPickedUp(self, providerId, pickupDetails):
941
        """
942
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
943
 
944
        Parameters:
945
         - providerId
946
         - pickupDetails
947
        """
948
        try:
4910 phani.kuma 949
            mark_doas_as_picked_up(providerId, pickupDetails)
950
        finally:
951
            close_session()
952
 
953
    def getDoasNotPickedUp(self, providerId):
954
        """
955
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
956
 
957
        Parameters:
958
         - providerId
959
        """
960
        try:
961
            orders_not_picked_up = get_doas_not_picked_up(providerId)
2764 chandransh 962
            return [to_t_order(order) for order in orders_not_picked_up]
963
        finally:
964
            close_session()
4910 phani.kuma 965
 
4741 phani.kuma 966
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
967
        """
968
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
969
 
970
        Parameters:
971
         - providerId
972
         - pickupDetails
973
        """
974
        try:
4910 phani.kuma 975
            mark_return_orders_as_picked_up(providerId, pickupDetails)
976
        finally:
977
            close_session()
978
 
979
    def getReturnOrdersNotPickedUp(self, providerId):
980
        """
981
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
982
 
983
        Parameters:
984
         - providerId
985
        """
986
        try:
987
            orders_not_picked_up = get_return_orders_not_picked_up(providerId)
4741 phani.kuma 988
            return [to_t_order(order) for order in orders_not_picked_up]
989
        finally:
990
            close_session()
4910 phani.kuma 991
 
4479 rajveer 992
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 993
        """
4452 rajveer 994
        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 995
        If the order is in any other state, it returns false.
996
        Throws an exception if the order with the given id couldn't be found.
997
 
998
        Parameters:
999
         - orderId
1000
        """
1001
        try:
4479 rajveer 1002
            return receive_return(orderId, receiveCondition)
2591 chandransh 1003
        finally:
1004
            close_session()
1005
 
1006
    def validateDoa(self, orderId, isValid):
1007
        """
4452 rajveer 1008
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 1009
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 1010
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
1011
        If the order is in any other state, it returns false.
1012
        Throws an exception if the order with the given id couldn't be found.
1013
 
1014
        Parameters:
1015
         - orderId
1016
         - isValid
1017
        """
1018
        try:
1019
            return validate_doa(orderId, isValid)
1020
        finally:
1021
            close_session()
2628 chandransh 1022
 
4495 rajveer 1023
    def validateReturnProduct(self, orderId, isUsable):
1024
        """
1025
        Parameters:
1026
         - orderId
1027
         - isUsable
1028
        """
1029
        try:
1030
            return validate_return_product(orderId, isUsable)
1031
        finally:
1032
            close_session()
1033
 
2628 chandransh 1034
    def reshipOrder(self, orderId):
1035
        """
4484 rajveer 1036
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1037
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 1038
            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 1039
 
1040
        If the order is in DOA_CERT_VALID state, it does the following:
1041
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1042
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 1043
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 1044
 
1045
        Returns the id of the newly created order.
1046
 
1047
        Throws an exception if the order with the given id couldn't be found.
1048
 
1049
        Parameters:
1050
         - orderId
1051
        """
1052
        try:
1053
            return reship_order(orderId)
1054
        finally:
1055
            close_session()
1056
 
3226 chandransh 1057
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 1058
        """
4484 rajveer 1059
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1060
            1. Creates a refund request for batch processing.
1061
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 1062
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 1063
 
1064
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1065
            1. Creates a refund request for batch processing.
3226 chandransh 1066
            2. Cancels the reservation of the item in the warehouse.
1067
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 1068
 
3226 chandransh 1069
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1070
            1. Cancels the reservation of the item in the warehouse.
1071
            2. Marks the current order as CANCELED.
1072
 
1073
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
1074
 
2628 chandransh 1075
        Returns True if it is successful, False otherwise.
1076
 
1077
        Throws an exception if the order with the given id couldn't be found.
1078
 
1079
        Parameters:
1080
         - orderId
3226 chandransh 1081
         - refundedBy
1082
         - reason
2628 chandransh 1083
        """
1084
        try:
3226 chandransh 1085
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 1086
        finally:
1087
            close_session()
1088
 
2697 chandransh 1089
    def getReturnOrders(self, warehouseId, fromDate, toDate):
1090
        """
1091
        Get all return orders created between the from and to dates for the given warehouse.
1092
        Ignores the warehouse if it is passed as -1.
1093
 
1094
        Parameters:
1095
         - warehouseId
1096
         - fromDate
1097
         - toDate
1098
        """
1099
        try:
1100
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1101
            return get_return_orders(warehouseId, from_date, to_date)
1102
        finally:
1103
            close_session()
1104
 
5481 phani.kuma 1105
    def getAllReturnOrders(self, onlyNotProcessed, fromDate, toDate):
1106
        """
1107
        Get all return orders created between the from and to dates for the given warehouse.
1108
        Ignores the warehouse if it is passed as -1.
1109
 
1110
        Parameters:
1111
         - warehouseId
1112
         - fromDate
1113
         - toDate
1114
        """
1115
        try:
1116
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1117
            return get_all_return_orders(onlyNotProcessed, from_date, to_date)
1118
        finally:
1119
            close_session()
1120
 
2700 chandransh 1121
    def getReturnOrder(self, id):
1122
        """
1123
        Returns the ReturnOrder corresponding to the given id.
1124
        Throws an exception if the return order with the given id couldn't be found.
1125
 
1126
        Parameters:
1127
         - id
1128
        """
1129
        try:
1130
            return get_return_order(id)
1131
        finally:
1132
            close_session()
1133
 
2697 chandransh 1134
    def processReturn(self, returnOrderId):
1135
        """
1136
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
1137
 
1138
        Parameters:
1139
         - returnOrderId
1140
        """
1141
        try:
1142
            process_return(returnOrderId)
1143
        finally:
1144
            close_session()
4757 mandeep.dh 1145
 
1146
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 1147
        """
4757 mandeep.dh 1148
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
1149
        the quantities for which the PO is raised.
1150
 
2819 chandransh 1151
        Parameters:
4757 mandeep.dh 1152
         - itemIdQuantityMap
1153
         - purchaseOrderId
2819 chandransh 1154
         - warehouseId
1155
        """
1156
        try:
4757 mandeep.dh 1157
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 1158
        finally:
1159
            close_session()
4757 mandeep.dh 1160
 
3451 chandransh 1161
    def updateWeight(self, orderId, weight):
1162
        """
1163
        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.
1164
 
1165
        Parameters:
1166
         - orderId
1167
         - weight
1168
        """
1169
        try:
1170
            order = update_weight(orderId, weight)
1171
            return to_t_order(order)
1172
        finally:
1173
            close_session()
1174
 
3469 chandransh 1175
    def changeItem(self, orderId, itemId):
1176
        """
1177
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
1178
        Currently, it also ensures that only a different color of the given item is shipped.
1179
 
1180
        Parameters:
1181
         - orderId
1182
         - itemId
1183
        """
1184
        try:
1185
            order = change_product(orderId, itemId)
1186
            return to_t_order(order)
1187
        finally:
1188
            close_session()
1189
 
1190
    def shiftToWarehouse(self, orderId, warehouseId):
1191
        """
1192
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
1193
 
1194
        Parameters:
1195
         - orderId
1196
         - warehouseId
1197
        """
1198
        try:
1199
            order = change_warehouse(orderId, warehouseId)
1200
            return to_t_order(order)
1201
        finally:
1202
            close_session()
3553 chandransh 1203
 
4647 rajveer 1204
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 1205
        """
1206
        Adds the given delay reason to the given order.
3986 chandransh 1207
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 1208
        Raises an exception if no order with the given id can be found.
3469 chandransh 1209
 
3553 chandransh 1210
        Parameters:
1211
         - orderId
1212
         - delayReason
1213
        """
1214
        try:
4647 rajveer 1215
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 1216
        finally:
1217
            close_session()
1218
 
3956 chandransh 1219
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
1220
        """
1221
        Marks the COD orders with given AWB nos. as having been processed.
1222
        Updates the captured amount for the corresponding payment.
1223
 
1224
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
1225
        1. There is no order corresponding to an AWB number.
1226
        2. The captured amount for a payment exceeds the total payment.
1227
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
1228
 
1229
        Parameters:
1230
         - collectedAmountMap
1231
         - xferBy
1232
         - xferTxnId
1233
         - xferDate
1234
        """
1235
        try:
1236
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
1237
        finally:
1238
            close_session()
4008 mandeep.dh 1239
 
1240
    def getTransactionsRequiringExtraProcessing(self, category):
1241
        """
1242
        Returns the list of transactions that require some extra processing and
1243
        which belong to a particular category. This is currently used by CRM
1244
        application.
1245
        """
1246
        try:
1247
            return get_transactions_requiring_extra_processing(category)
1248
        finally:
1249
            close_session()
1250
 
1251
    def markTransactionAsProcessed(self, transactionId, category):
1252
        """
1253
        Marks a particular transaction as processed for a particular category.
1254
        It essentially deletes the transaction if it is processed for a particular
1255
        category. This is currently used by CRM application.
1256
        """
1257
        try:
1258
            return mark_transaction_as_processed(transactionId, category)
1259
        finally:
1260
            close_session()
4018 chandransh 1261
 
1262
    def getItemWiseRiskyOrdersCount(self, ):
1263
        """
1264
        Returns a map containing the number of risky orders keyed by item id. A risky order
1265
        is defined as one whose shipping date is about to expire.
1266
        """
1267
        try:
1268
            return get_item_wise_risky_orders_count()
1269
        finally:
1270
            close_session()
3956 chandransh 1271
 
4247 rajveer 1272
    def markOrderCancellationRequestReceived(self, orderId):
1273
        """
1274
        Mark order as cancellation request received. If customer sends request of cancellation of
1275
        a particular order, this method will be called. It will just change status of the order
1276
        depending on its current status. It also records the previous status, so that we can move
1277
        back to that status if cancellation request is denied.
1278
 
1279
        Parameters:
1280
         - orderId
1281
        """
1282
        try:
1283
            return mark_order_cancellation_request_received(orderId)
1284
        finally:
1285
            close_session()
1286
 
1287
 
4662 rajveer 1288
    def markOrderAsLostInTransit(self, orderId):
1289
        """
1290
        Parameters:
1291
         - orderId
1292
        """
1293
        try:
1294
            return mark_order_as_lost_in_transit(orderId)
1295
        finally:
1296
            close_session()
1297
 
4258 rajveer 1298
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1299
        """
4258 rajveer 1300
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1301
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1302
 
1303
        Parameters:
4258 rajveer 1304
         - transactionId
4247 rajveer 1305
        """
1306
        try:
4259 anupam.sin 1307
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1308
        finally:
1309
            close_session()
4259 anupam.sin 1310
 
1311
    def refundTransaction(self, transactionId, refundedBy, reason):
1312
        """
1313
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1314
        need to be cancelled
1315
 
1316
        Parameters:
1317
         - transactionId
1318
        """
1319
        try:
1320
            return refund_transaction(transactionId, refundedBy, reason)
1321
        finally:
1322
            close_session()
4247 rajveer 1323
 
1324
    def markOrderCancellationRequestDenied(self, orderId):
1325
        """
1326
        If we decide to not to cancel order, we will move the order ro previous status.
1327
 
1328
        Parameters:
1329
         - orderId
1330
        """
1331
        try:
1332
            return mark_order_cancellation_request_denied(orderId)
1333
        finally:
1334
            close_session()
1335
 
1336
    def markOrderCancellationRequestConfirmed(self, orderId):
1337
        """
1338
        If we decide to to cancel order, CRM will call this method to move the status of order to
1339
        cancellation request confirmed. After this OM will be able to cancel the order.
1340
 
1341
        Parameters:
1342
         - orderId
1343
        """
1344
        try:
1345
            return mark_order_cancellation_request_confirmed(orderId)
1346
        finally:
1347
            close_session()
1348
 
4324 mandeep.dh 1349
    def updateShipmentAddress(self, orderId, addressId):
1350
        """
1351
        Updates shipment address of an order. Delivery and shipping date estimates
1352
        etc. are also updated here.
1353
 
1354
        Throws TransactionServiceException in case address change is not
1355
        possible due to certain reasons such as new pincode in address is
1356
        not serviceable etc.
1357
 
1358
        Parameters:
1359
         - orderId
1360
         - addressId
1361
        """
1362
        try:
1363
            update_shipment_address(orderId, addressId)
1364
        finally:
1365
            close_session()
1366
 
4285 rajveer 1367
    def acceptOrdersForItemId(self, itemId, inventory):
1368
        """
1369
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1370
        given order is not a COD order, it also captures the payment if the same has not been captured.
1371
 
1372
        Parameters:
1373
         - itemId
1374
         - inventory
1375
        """
1376
        try:
1377
            return accept_orders_for_item_id(itemId, inventory)
1378
        finally:
1379
            close_session()
1380
 
4303 rajveer 1381
 
1382
 
4369 rajveer 1383
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1384
        """
1385
        Parameters:
1386
         - vendorId
1387
         - itemId
1388
         - quantity
1389
         - estimate
4369 rajveer 1390
         - isReminder
4303 rajveer 1391
        """
1392
        try:
4369 rajveer 1393
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1394
        finally:
1395
            close_session()
1396
 
4369 rajveer 1397
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1398
        """
1399
        Parameters:
1400
         - vendorId
1401
         - itemId
1402
         - quantity
1403
         - estimate
4369 rajveer 1404
         - isReminder
4303 rajveer 1405
        """
1406
        try:
4369 rajveer 1407
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1408
        finally:
1409
            close_session()
1410
 
4369 rajveer 1411
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1412
        """
1413
        Parameters:
1414
         - vendorId
1415
         - itemId
1416
         - quantity
1417
         - estimate
4369 rajveer 1418
         - isReminder
4303 rajveer 1419
        """
1420
        try:
4369 rajveer 1421
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1422
        finally:
1423
            close_session()
1424
 
1425
 
4369 rajveer 1426
    def markOrdersAsTimeout(self, vendorId):
1427
        """
1428
        Parameters:
1429
         - vendorId
1430
        """
1431
        try:
1432
            return mark_orders_as_timeout(vendorId)
1433
        finally:
1434
            close_session()
4386 anupam.sin 1435
 
1436
    def getOrderForAwb(self, awb):
1437
        """
1438
        Parameters:
1439
         - AirwayBill Number
1440
        """
1441
        try:
1442
            return to_t_order(get_order_for_awb(awb))
1443
        finally:
1444
            close_session()
4369 rajveer 1445
 
4910 phani.kuma 1446
    def getOrdersForProviderForStatus(self, provider_id, order_status_list):
4506 phani.kuma 1447
        """
1448
        Parameters:
1449
         - provider id
1450
         - order status
1451
        """
1452
        try:
4910 phani.kuma 1453
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status_list)
4506 phani.kuma 1454
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1455
        finally:
1456
            close_session()
4600 varun.gupt 1457
 
1458
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1459
        '''
1460
        Parameters:
1461
         - vendorId
1462
         - billingDateFrom
1463
         - billingDateTo
1464
        '''
1465
        try:
1466
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1467
        finally:
1468
            close_session()
1469
 
4607 rajveer 1470
    def getSlippedSippingDateOrders(self):
1471
        try:
1472
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1473
        finally:
1474
            close_session()
1475
 
4709 rajveer 1476
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1477
        try:
1478
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1479
        finally:
1480
            close_session()
1481
 
4600 varun.gupt 1482
    def getEBSSettlementSummaries(self):
1483
        try:
1484
            return get_ebs_settlement_summaries()
1485
        finally:
1486
            close_session()
4369 rajveer 1487
 
4600 varun.gupt 1488
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1489
        try:
1490
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1491
        finally:
1492
            close_session()
1493
 
5386 phani.kuma 1494
    def getSettlementForPrepaid(self, referenceId, isRefund):
4600 varun.gupt 1495
        '''
1496
        Parameters:
5189 varun.gupt 1497
         - referenceId
1498
         - isRefund
4600 varun.gupt 1499
        '''
1500
        try:
5386 phani.kuma 1501
            return to_t_payment_settlement(get_settlement_for_Prepaid(referenceId, isRefund))
4600 varun.gupt 1502
        finally:
1503
            close_session()
5386 phani.kuma 1504
 
1505
    def getSettlementForCod(self, orderId, isRefund):
1506
        '''
1507
        Parameters:
1508
         - orderId
1509
         - isRefund
1510
        '''
1511
        try:
1512
            return to_t_payment_settlement(get_settlement_for_Cod(orderId, isRefund))
1513
        finally:
1514
            close_session()
1515
 
4600 varun.gupt 1516
    def getEBSSettlementDate(self, settlementId):
1517
        try:
1518
            return to_java_date(get_ebs_settlement_date(settlementId))
1519
        finally:
1520
            close_session()
1521
 
4905 varun.gupt 1522
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection):
4600 varun.gupt 1523
        try:
4905 varun.gupt 1524
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection)
4600 varun.gupt 1525
        finally:
1526
            close_session()
1527
 
1528
    def markEBSSettlementUploaded(self, settlementId):
1529
        try:
1530
            mark_ebs_settlement_uploaded(settlementId)
1531
        finally:
1532
            close_session()
1533
 
4715 varun.gupt 1534
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1535
        try:
1536
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1537
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1538
        finally:
1539
            close_session()
1540
 
1541
    def getReshippedOrderIds(self, orderIds):
1542
        try:
1543
            return get_reshipped_order_ids(orderIds)
1544
        finally:
1545
            close_session()
1546
 
5481 phani.kuma 1547
    def getBilledOrders(self, vendorId, onlyVendorNotPaid, billingDateFrom, billingDateTo):
4875 varun.gupt 1548
        try:
5481 phani.kuma 1549
            from_date, to_date = get_fdate_tdate(billingDateFrom, billingDateTo)
1550
            return [to_t_order(order) for order in get_billed_orders(vendorId, onlyVendorNotPaid, from_date, to_date)]
4875 varun.gupt 1551
        finally:
1552
            close_session()
1553
 
5062 varun.gupt 1554
    def getStatusDistributionOfOrders(self, startDate, endDate):
1555
        try:
5067 varun.gupt 1556
            distribution = {}
1557
 
1558
            for status, count in get_order_distribution_by_status(to_py_date(startDate), to_py_date(endDate)):
1559
                distribution[status] = count
1560
 
1561
            return distribution
5062 varun.gupt 1562
        finally:
1563
            close_session()
1564
 
5067 varun.gupt 1565
    def getOrderIdsForStatus(self, status, startDatetime, endDatetime):
1566
        try:
1567
            orders = get_order_ids_for_status(status, to_py_date(startDatetime), to_py_date(endDatetime))
1568
            return [order.id for order in orders]
1569
        finally:
1570
            close_session()
1571
 
5099 varun.gupt 1572
    def updateOrderAsPaidToVendor(self, orderId):
1573
        try:
1574
            update_orders_as_paid_to_vendor(orderId)
1575
        finally:
1576
            close_session()
1577
 
5348 anupam.sin 1578
    def updateCODAgent(self, agentEmailId, orderId):
1579
        try:
1580
            update_COD_agent(agentEmailId, orderId)
1581
        finally:
1582
            close_session()
1583
 
5386 phani.kuma 1584
    def updateOrderOnlyAsPaidToVendor(self, orderId):
1585
        try:
1586
            update_order_only_as_paid_to_vendor(orderId)
1587
        finally:
1588
            close_session()
1589
 
5208 varun.gupt 1590
    def getRefundedOrdersMarkedPaid(self):
1591
        try:
1592
            return [to_t_order(order) for order in get_refunded_orders_marked_paid()]
1593
        finally:
1594
            close_session()
5447 anupam.sin 1595
 
1596
    def getAllVerificationAgents(self, minOrderId, maxOrderId):
1597
        try:
1598
            return [to_t_verification_agent(codAgent) for codAgent in get_all_verification_agents(minOrderId, maxOrderId)]
1599
        finally:
5527 anupam.sin 1600
            close_session()
1601
 
1602
    def getAllAttributesForOrderId(self, orderId):
1603
        try:
1604
            return [to_t_attribute(attribute) for attribute in get_all_attributes_for_order_id(orderId)]
1605
        finally:
1606
            close_session()
1607
 
1608
    def setOrderAttributeForTransaction(self, transactionId, attribute):
1609
        try:
1610
            set_order_attribute_for_transaction(transactionId, attribute)                    
1611
        finally:
1612
            close_session()
5593 mandeep.dh 1613
 
1614
    def acceptOrderForItem(self, itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
1615
        """
1616
        Accepts appropriate order for an item in a given billingWarehouse. Usually
1617
        invoked while scanning IN of items.
1618
 
1619
        Parameters:
1620
         - itemId
1621
         - quantity
1622
         - fulfilmentWarehouseId
1623
         - billingWarehouseId
1624
        """
1625
        try:
1626
            accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId)
1627
        finally:
1628
            close_session()
1629
 
5833 rajveer 1630
    def getOrderAttributeValue(self, orderId, attributeName):
1631
        """
1632
        Parameters:
1633
         - orderId
1634
         - attributeName
1635
        """
1636
        try:
6019 rajveer 1637
            return get_order_attribute_value(orderId, attributeName)
5833 rajveer 1638
        finally:
1639
            close_session()
1640
 
6019 rajveer 1641
    def changeJacketNumber(self, orderId, jacketNumber):
1642
        """
1643
        Parameters:
1644
         - orderId
1645
         - jacketNumber
1646
        """
1647
        try:
1648
            return change_jacket_number(orderId, jacketNumber)
1649
        finally:
1650
            close_session()
1651
 
1652
    def markOrderAsRtoInTransit(self, orderId):
1653
        """
1654
        Parameters:
1655
         - orderId
1656
        """
1657
        try:
1658
            return mark_order_as_rto_in_transit(orderId)
1659
        finally:
1660
            close_session()        
1661
 
6000 mandeep.dh 1662
    def createRechargeOrder(self, thriftRechargeOrder):
1663
        """
1664
        Parameters:
1665
         - thriftRechargeOrder
1666
        """
6031 rajveer 1667
        try:
1668
            if thriftRechargeOrder is None or thriftRechargeOrder.rechargeType is None:
1669
                raise TransactionServiceException(102, 'Order or the type is Null')
1670
 
1671
            rechargeOrder = None
1672
            if thriftRechargeOrder.rechargeType == RechargeType.MOBILE:
1673
                rechargeOrder = MobileRechargeOrder()
1674
            elif thriftRechargeOrder.rechargeType == RechargeType.DTH:
1675
                rechargeOrder = DTHRechargeOrder()
1676
 
1677
            if rechargeOrder is None:
1678
                raise TransactionServiceException(102, 'Unsupported recharge type')
6000 mandeep.dh 1679
 
6031 rajveer 1680
            transaction = DigitalTransaction()
1681
            transaction.createdOn = datetime.datetime.now()
6056 amit.gupta 1682
            transaction.userId = thriftRechargeOrder.userId
6031 rajveer 1683
            transaction.orders = [rechargeOrder]
1684
 
6000 mandeep.dh 1685
            rechargeOrder.from_thrift_object(thriftRechargeOrder)
1686
            session.commit()
6031 rajveer 1687
            return rechargeOrder.to_thrift_object()
6000 mandeep.dh 1688
        except:
1689
            raise TransactionServiceException(103, 'Invalid values passed')
1690
        finally:
1691
            self.closeSession()
1692
 
6031 rajveer 1693
    def getRechargeOrder(self, rechargeOrderId):
1694
        """
1695
        Parameters:
1696
         - rechargeOrderId
1697
        """
1698
        try:
6048 rajveer 1699
            return get_recharge_order(rechargeOrderId).to_thrift_object()
6031 rajveer 1700
        finally:
1701
            self.closeSession()
1702
 
1703
    def getRechargeOrders(self, userId):
1704
        """
1705
        Parameters:
1706
         - userId
1707
        """
1708
        try:
1709
            return [order.to_thrift_object() for order in get_recharge_orders(userId)]
1710
        finally:
1711
            self.closeSession()
1712
 
6000 mandeep.dh 1713
    def updateRechargeOrderStatus(self, rechargeOrderId, rechargeOrderStatus):
1714
        """
1715
        Parameters:
1716
         - rechargeOrderId
1717
         - rechargeOrderStatus
1718
        """
6031 rajveer 1719
        try:
1720
            return update_recharge_order_status(rechargeOrderId, rechargeOrderStatus)
1721
        finally:
1722
            self.closeSession()
1723
 
1724
    def activateRechargeTxn(self, rechargeOrderId):
6000 mandeep.dh 1725
        """
1726
        Parameters:
6031 rajveer 1727
         - rechargeOrderId
6000 mandeep.dh 1728
        """
6031 rajveer 1729
        try:
1730
            return True
1731
            activate_recharge_txn(rechargeOrderId)
1732
        finally:
1733
            self.closeSession()
6000 mandeep.dh 1734
 
6031 rajveer 1735
    def getUserWallet(self, userId):
6000 mandeep.dh 1736
        """
1737
        Parameters:
6031 rajveer 1738
         - userId
6000 mandeep.dh 1739
        """
6031 rajveer 1740
        try:
1741
            return get_user_wallet(userId).to_thrift_object()
1742
        finally:
1743
            self.closeSession()
6000 mandeep.dh 1744
 
6031 rajveer 1745
    def getUserWalletHistory(self, userId):
6000 mandeep.dh 1746
        """
1747
        Parameters:
6031 rajveer 1748
         - userId
6000 mandeep.dh 1749
        """
6031 rajveer 1750
        try:
1751
            return [wallet.to_thrift_object() for wallet in get_user_wallet_history(userId)]
1752
        finally:
1753
            self.closeSession()
6000 mandeep.dh 1754
 
6206 rajveer 1755
    def getServiceProviders(self, rechargeType, onlyActive):
6048 rajveer 1756
        """
1757
        Parameters:
1758
         - rechargeType
6206 rajveer 1759
         - onlyActive
6048 rajveer 1760
        """
6077 anupam.sin 1761
 
6048 rajveer 1762
        try:
6206 rajveer 1763
            return get_service_providers(rechargeType, onlyActive)
6048 rajveer 1764
        finally:
1765
            self.closeSession()
1766
 
6049 rajveer 1767
    def getServiceProviderForDevice(self, rechargeType, deviceNumber):
6048 rajveer 1768
        """
1769
        Parameters:
1770
         - deviceNumber
1771
        """
1772
        try:
6049 rajveer 1773
            return get_service_provider_for_device(rechargeType, deviceNumber)
6048 rajveer 1774
        finally:
1775
            self.closeSession()
6056 amit.gupta 1776
 
6591 anupam.sin 1777
    def validateRecharge(self, rechargeType, deviceNumber, userSelectedProviderId, clientAddress):
6269 rajveer 1778
        """
1779
        Parameters:
1780
         - deviceNumber
1781
        """
1782
        try:
6591 anupam.sin 1783
            return validate_recharge(rechargeType, deviceNumber, userSelectedProviderId, clientAddress)
6269 rajveer 1784
        finally:
1785
            self.closeSession()
1786
 
6056 amit.gupta 1787
    def getRechargeOrdersForTransaction(self, txId):
1788
        """
1789
        Parameters:
1790
         - transactionId
1791
        """
1792
        try:
1793
            return get_recharge_orders_for_transaction(txId).to_thrift_object()
1794
        finally:
1795
            self.closeSession()
6048 rajveer 1796
 
6094 rajveer 1797
    def getRechargeOrdersForDevice(self, deviceNumber):
1798
        """
1799
        Parameters:
1800
        - deviceNumber
1801
        """
1802
        try:
1803
            return [order.to_thrift_object() for order in get_recharge_orders_for_device(deviceNumber)]
1804
        finally:
1805
            self.closeSession()
1806
 
6154 rajveer 1807
    def getRechargeOrdersForStatus(self, status):
1808
        """
1809
        Parameters:
1810
        - status
1811
        """
1812
        try:
1813
            return [order.to_thrift_object() for order in get_recharge_orders_for_status(status)]
1814
        finally:
1815
            self.closeSession()
1816
 
6159 rajveer 1817
    def getPlansForOperator(self, operatorId):
1818
        """
1819
        Parameters:
1820
        - operatorId
1821
        """
1822
        try:
1823
            return [plan.to_thrift_object() for plan in get_plans_for_operator(operatorId)]
1824
        finally:
1825
            self.closeSession()
1826
 
1827
 
6094 rajveer 1828
    def addAmountToWallet(self, userId, orderId, amount):
1829
        """
1830
        Parameters:
1831
        - userId
1832
        - orderId
1833
        - amount
1834
        """
1835
        try:
1836
            update_amount_in_wallet(userId, amount, orderId)
1837
        finally:
1838
            self.closeSession()
1839
 
6188 rajveer 1840
    def getRechargeStatistics(self):
1841
        """
1842
        Parameters:
1843
        """
1844
        try:
1845
            return get_recharge_statistics()
1846
        finally:
1847
            self.closeSession()
1848
 
6307 anupam.sin 1849
    def getRechargeDenominations(self, operatorId, circleCode, denominationType):
6289 anupam.sin 1850
        try:
1851
            returnList = []
6307 anupam.sin 1852
            rechargeDenominations = get_recharge_denominations(operatorId, circleCode, denominationType)
6289 anupam.sin 1853
            for rechargeDenomination in rechargeDenominations:
1854
                returnList.append(rechargeDenomination.to_thrift_object())
1855
            return returnList
1856
        finally:
1857
            self.closeSession() 
6188 rajveer 1858
 
6371 rajveer 1859
    def updateAvailabilityStatus(self, operatorId, circleId, isAvailable):
1860
        try:
1861
            update_availability_status(operatorId, circleId, isAvailable)
1862
        finally:
1863
            self.closeSession() 
1864
 
6396 amit.gupta 1865
    def getAvailableEmiSchemes(self):
1866
        try:
1867
            return get_available_emi_schemes()
1868
        finally:
1869
            self.closeSession()
1870
 
6389 rajveer 1871
    def getMiscCharges(self, transactionId):
1872
        try:
1873
            return get_misc_charges(transactionId)
1874
        finally:
1875
            self.closeSession()
1876
 
6507 anupam.sin 1877
    def refundRechargeOrder (self, rechargeOrderId):
1878
        try:
1879
            return refund_recharge_order(rechargeOrderId)
1880
        finally:
1881
            self.closeSession()
6821 amar.kumar 1882
 
1883
    def getPhysicalOrders(self, start_date, end_date):
1884
        try:
6832 amar.kumar 1885
            return [to_t_order(order) for order in get_physical_orders(to_py_date(start_date), to_py_date(end_date))]
6821 amar.kumar 1886
        finally:
1887
            self.closeSession()
6507 anupam.sin 1888
 
6906 rajveer 1889
    def getDocument(self, docType, docSource):
1890
        try:
1891
            return get_document(docType, docSource)
1892
        finally:
1893
            self.closeSession()
6988 rajveer 1894
 
1895
    def retrieveInvoice(self, orderId):
1896
        try:
1897
            return retrieve_invoice(orderId)
1898
        finally:
1899
            self.closeSession()
6906 rajveer 1900
 
7027 rajveer 1901
    def receiveUpdatesForRedExpress(self, awbNumber):
1902
        try:
7032 rajveer 1903
            return RedExpressUpdateService.get_updates_for_user(awbNumber)
7027 rajveer 1904
        finally:
1905
            self.closeSession()
1906
 
6985 anupam.sin 1907
    def changeShippingAddress(self, orderId, line1, line2, city, state, pin):
1908
        try:
1909
            return change_shipping_address(orderId, line1, line2, city, state, pin)
1910
        finally:
1911
            self.closeSession()
1912
 
2536 chandransh 1913
    def closeSession(self, ):
1914
        close_session()
3376 rajveer 1915
 
1916
    def isAlive(self, ):
1917
        """
5447 anupam.sin 1918
        For checking whether service is alive or not. It also checks connectivity with database
3376 rajveer 1919
        """
1920
        try:
1921
            return is_alive()
1922
        finally:
6988 rajveer 1923
            close_session()