Subversion Repositories SmartDukaan

Rev

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