Subversion Repositories SmartDukaan

Rev

Rev 4757 | Rev 4783 | 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
'''
6
from shop2020.model.v1.order.impl import DataService
7
from shop2020.model.v1.order.impl.DataAccessors import create_transaction,\
1382 varun.gupt 8
    create_order, get_new_transaction, get_transactions_for_customer, get_transaction_status,\
9
    get_line_items_for_order, get_transaction, get_transactions_for_shopping_cart_id,\
10
    change_transaction_status, get_orders_for_customer,get_orders_for_transaction, get_order,\
11
    get_returnable_orders_for_customer, get_cancellable_orders_for_customer, get_orders_by_billing_date,\
4394 rajveer 12
    get_all_orders, change_order_status, get_alerts, add_alert, add_billing_details,\
4285 rajveer 13
    mark_orders_as_manifested, close_session, accept_order, mark_orders_as_picked_up,\
4283 anupam.sin 14
    mark_orders_as_delivered, mark_orders_as_failed,\
1405 ankur.sing 15
    order_outofstock, batch_orders, update_non_delivery_reason, enqueue_transaction_info_email,\
1627 ankur.sing 16
    get_undelivered_orders, get_order_for_customer, get_valid_order_count,\
1886 ankur.sing 17
    get_cust_count_with_successful_txn, get_valid_orders_amount_range,\
2591 chandransh 18
    get_valid_orders, toggle_doa_flag, request_pickup_number, authorize_pickup,\
2697 chandransh 19
    receive_return, validate_doa, reship_order, refund_order, get_return_orders,\
2819 chandransh 20
    process_return, get_return_order, mark_doas_as_picked_up,\
4757 mandeep.dh 21
    verify_order, is_alive, get_orders_by_shipping_date,\
3956 chandransh 22
    update_weight, change_warehouse, change_product, add_delay_reason,\
4008 mandeep.dh 23
    reconcile_cod_collection, get_transactions_requiring_extra_processing,\
4133 chandransh 24
    mark_transaction_as_processed, get_item_wise_risky_orders_count,\
4600 varun.gupt 25
    get_orders_in_batch, get_order_count, get_ebs_settlement_summaries, \
4259 anupam.sin 26
    mark_order_cancellation_request_received,\
27
    mark_order_cancellation_request_denied, refund_transaction,\
28
    mark_order_cancellation_request_confirmed,\
4303 rajveer 29
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id,\
30
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated,\
4369 rajveer 31
    mark_orders_as_not_available, update_shipment_address,\
4410 rajveer 32
    mark_orders_as_timeout, get_order_for_awb,\
4481 anupam.sin 33
    mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
4488 rajveer 34
    mark_order_doa_request_received, mark_order_doa_request_authorized,\
4715 varun.gupt 35
    mark_order_return_request_received, mark_order_return_request_authorized, add_invoice_number, get_reshipped_order_ids, \
4600 varun.gupt 36
    validate_return_product, get_orders_for_provider_for_status, save_ebs_settlement_summary, get_ebs_settlement_date, \
4715 varun.gupt 37
    save_payment_settlements, mark_ebs_settlement_uploaded, get_billed_orders_for_vendor, get_settlement_for_paymentId, \
38
    get_settlements_by_date, get_slipped_sipping_date_orders, mark_order_as_lost_in_transit,\
4757 mandeep.dh 39
    get_cancelled_orders, mark_order_as_delivered, mark_return_orders_as_picked_up, update_orders_as_PORaised
1405 ankur.sing 40
 
104 ashish 41
from shop2020.model.v1.order.impl.Convertors import to_t_transaction,\
4600 varun.gupt 42
    to_t_alert, to_t_order, to_t_lineitem, to_t_payment_settlement
483 rajveer 43
from shop2020.thriftpy.model.v1.order.ttypes import Transaction, OrderStatus,\
2783 chandransh 44
    LineItem, Order, TransactionServiceException
4600 varun.gupt 45
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
104 ashish 46
 
47
class OrderServiceHandler:
48
 
3187 rajveer 49
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 50
        """
104 ashish 51
        Constructor
483 rajveer 52
        """
3187 rajveer 53
        DataService.initialize(dbname, db_hostname)
104 ashish 54
 
55
    def createTransaction(self, transaction):
56
        """
57
        Parameters:
58
         - transaction
59
        """
766 rajveer 60
        try:
61
            return create_transaction(transaction)
62
        finally:
63
            close_session()
64
 
104 ashish 65
    def getTransaction(self, id):
66
        """
67
            Get transaction methods.
68
 
69
        Parameters:
70
         - id
71
        """
766 rajveer 72
        try:
73
            transaction = get_transaction(id)
74
            return to_t_transaction(transaction)
75
        finally:
76
            close_session()
77
 
483 rajveer 78
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 79
        """
80
        Parameters:
483 rajveer 81
         - customerId
104 ashish 82
         - from_date
83
         - to_date
483 rajveer 84
         - status
104 ashish 85
        """
766 rajveer 86
        try:
87
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
88
 
89
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
90
            t_transaction = []
91
            for transaction in transactions:
92
                t_transaction.append(to_t_transaction(transaction))
93
            return t_transaction
94
        finally:
95
            close_session()
483 rajveer 96
 
97
    def getTransactionsForShoppingCartId(self, shoppingCartId):
98
        """
99
        Parameters:
100
            - shoppingCartId
101
        """
766 rajveer 102
        try:
103
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
104
            t_transaction = []
105
            for transaction in transactions:
106
                t_transaction.append(to_t_transaction(transaction))
107
            return t_transaction
108
        finally:
109
            close_session()
104 ashish 110
 
483 rajveer 111
    def getTransactionStatus(self, transactionId):
104 ashish 112
        """
113
        Parameters:
483 rajveer 114
         - transactionId
115
        """
766 rajveer 116
        try:
117
            return get_transaction_status(transactionId)
118
        finally:
119
            close_session()
120
 
483 rajveer 121
    def changeTransactionStatus(self, transactionId, status, description):
122
        """
123
        Parameters:
124
         - transactionId
104 ashish 125
         - status
483 rajveer 126
         - description
127
        """
766 rajveer 128
        try:
129
            return change_transaction_status(transactionId, status, description)
130
        finally:
131
            close_session()
132
 
1528 ankur.sing 133
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 134
        """
1528 ankur.sing 135
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
136
        only user who owns the transaction can view its order details.
137
 
483 rajveer 138
        Parameters:
139
         - transactionId
1528 ankur.sing 140
         - customerId
483 rajveer 141
        """
766 rajveer 142
        try:
1528 ankur.sing 143
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 144
            return [to_t_order(order) for order in orders]    
145
        finally:
146
            close_session()
147
 
483 rajveer 148
    def getAllOrders(self, status, from_date, to_date, warehouse_id):
149
        """
150
        Parameters:
151
         - status
104 ashish 152
         - from_date
153
         - to_date
483 rajveer 154
         - warehouse_id
104 ashish 155
        """
766 rajveer 156
        try:
157
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
158
            orders = get_all_orders(status, current_from_date, current_to_date, warehouse_id)
159
            return [to_t_order(order) for order in orders]
160
        finally:
161
            close_session()
4133 chandransh 162
 
163
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id):
164
        """
165
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
166
        Pass the status as null and the limit as 0 to ignore them.
167
 
168
        Parameters:
169
         - statuses
170
         - offset
171
         - limit
172
         - warehouse_id
173
        """
174
        try:
175
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id)
176
            return [to_t_order(order) for order in orders]
177
        finally:
178
            close_session()
179
 
180
    def getOrderCount(self, statuses, warehouseId):
181
        """
182
        Returns the count of orders with the given statuses assigned to the given warehouse.
183
 
184
        Parameters:
185
         - statuses
186
         - warehouseId
187
        """
188
        try:
189
            return get_order_count(statuses, warehouseId)
190
        finally:
191
            close_session()
192
 
995 varun.gupt 193
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
194
        """
195
        Parameters:
196
         - status
197
         - start_billing_date
198
         - end_billing_date
199
         - warehouse_id
200
        """
201
        try:
202
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
203
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
204
            return [to_t_order(order) for order in orders]
205
        finally:
206
            close_session()
1382 varun.gupt 207
 
3451 chandransh 208
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 209
        """
210
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 211
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
212
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 213
 
214
        Parameters:
215
         - fromShippingDate
216
         - toShippingDate
217
         - providerId
218
         - warehouseId
3451 chandransh 219
         - cod
3427 chandransh 220
        """
221
        try:
222
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 223
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 224
            return [to_t_order(order) for order in orders]
225
        finally:
226
            close_session()
227
 
1382 varun.gupt 228
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
229
        """
230
        Parameters:
231
         - customerId
232
         - limit
233
        """
234
        try:
235
            return get_returnable_orders_for_customer(customerId, limit)
236
        finally:
237
            close_session()
995 varun.gupt 238
 
1382 varun.gupt 239
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
240
        """
241
        Parameters:
242
         - customerId
243
         - limit
244
        """
245
        try:
246
            return get_cancellable_orders_for_customer(customerId, limit)
247
        finally:
248
            close_session()
249
 
483 rajveer 250
    def changeOrderStatus(self, orderId, status, description):
251
        """
252
        Parameters:
253
         - orderId
254
         - status
255
         - description
256
         - 
257
        """
766 rajveer 258
        try:
259
            return change_order_status(self, orderId, status, description)
260
        finally:
261
            close_session()
921 rajveer 262
 
3064 chandransh 263
    def verifyOrder(self, orderId):
264
        """
265
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
266
        timestamp. It is intended to be used for COD orders but can be harmlessly
267
        used for all other orders as well.
268
        Throws an exception if no such order exists.
269
 
270
        Parameters:
271
         - orderId
272
        """
273
        try:
274
            return verify_order(self, orderId)
275
        finally:
276
            close_session()
277
 
921 rajveer 278
    def acceptOrder(self, orderId):
279
        """
3064 chandransh 280
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
281
        given order is not a COD order, it also captures the payment if the same has
282
        not been captured.
283
        Throws an exception if no such order exists.
284
 
921 rajveer 285
        Parameters:
286
         - orderId
287
        """
288
        try:
4285 rajveer 289
            return accept_order(orderId)
921 rajveer 290
        finally:
291
            close_session()
292
 
3014 chandransh 293
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 294
        """
3014 chandransh 295
        Returns list of orders for the given customer created between the given dates and having the given statuses.
296
        Pass and empty list to ignore filtering on statuses.
297
 
104 ashish 298
        Parameters:
299
         - customerId
300
         - from_date
301
         - to_date
3014 chandransh 302
         - statuses
104 ashish 303
        """
766 rajveer 304
        try:
305
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
306
 
3014 chandransh 307
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 308
            return [to_t_order(order) for order in orders]
309
        finally:
310
            close_session()
1528 ankur.sing 311
 
312
    def getOrderForCustomer(self, orderId, customerId):
313
        """
314
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
315
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
316
 
317
        Parameters:
318
         - customerId
319
         - orderId
320
        """
321
        try:
322
            return to_t_order(get_order_for_customer(orderId, customerId))
323
        finally:
324
            close_session()
766 rajveer 325
 
483 rajveer 326
    def getOrder(self, id):
327
        """
328
        Parameters:
329
         - id
330
        """
766 rajveer 331
        try:
332
            return to_t_order(get_order(id))
333
        finally:
334
            close_session()
335
 
483 rajveer 336
    def getLineItemsForOrder(self, orderId):
337
        """
338
        Parameters:
339
         - orderId
340
        """
766 rajveer 341
        try:
342
            lineitems = get_line_items_for_order(orderId)
343
            t_lineitems = []
344
            for lineitem in lineitems:
345
                t_lineitems.append(to_t_lineitem(lineitem))
346
            return t_lineitems
347
        finally:
348
            close_session()
1149 chandransh 349
 
4763 rajveer 350
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 351
        """
4658 mandeep.dh 352
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 353
        Also marks the order as billed and sets the billing timestamp.
354
        Return false if it doesn't find the order with the given ID.
1149 chandransh 355
 
356
        Parameters:
357
         - orderId
358
         - jacketNumber
4658 mandeep.dh 359
         - serialNumber
2783 chandransh 360
         - itemNumber
361
         - billedBy
1149 chandransh 362
        """
363
        try:
4763 rajveer 364
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 365
        finally:
366
            close_session()
1220 chandransh 367
 
4763 rajveer 368
    def addInvoiceNumber(self, orderId, invoiceNumber, color):
4579 rajveer 369
        """
370
        Add the invoice number to the order.
371
 
372
        Parameters:
373
         - orderId
374
         - invoice_number
375
        """
376
        try:
4763 rajveer 377
            add_invoice_number(orderId, invoiceNumber, color)
4579 rajveer 378
        finally:
379
            close_session()
380
 
1220 chandransh 381
    def batchOrders(self, warehouseId):
382
        """
383
        Create a batch of all the pending orders for the given warehouse.
384
        The returned list is orderd by created_timestamp.
385
        If there are no pending orders, an empty list is returned.
1208 chandransh 386
 
1220 chandransh 387
        Parameters:
388
         - warehouseId
389
        """
390
        try:
391
            pending_orders = batch_orders(warehouseId)
392
            return [to_t_order(order) for order in pending_orders]
393
        finally:
394
            close_session()
395
 
1208 chandransh 396
    def markOrderAsOutOfStock(self, orderId):
397
        """
398
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
399
 
400
 
401
        Parameters:
402
         - orderId
403
        """
404
        try:
405
            return order_outofstock(orderId)
406
        finally:
407
            close_session()
408
 
3064 chandransh 409
    def markOrdersAsManifested(self, warehouseId, providerId, cod):
759 chandransh 410
        """
3064 chandransh 411
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4410 rajveer 412
        given warehouse and were picked up by the given provider as MANIFESTED.
759 chandransh 413
 
414
        Parameters:
415
         - warehouseId
416
         - providerId
3064 chandransh 417
         - cod
759 chandransh 418
        """
766 rajveer 419
        try:
3064 chandransh 420
            return mark_orders_as_manifested(warehouseId, providerId, cod)
766 rajveer 421
        finally:
422
            close_session()
1113 chandransh 423
 
4410 rajveer 424
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod):
425
        """
426
        Depending on the third parameter, marks either all prepaid or all cod orders MANIFESTED by the
427
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
428
 
429
        Parameters:
430
         - warehouseId
431
         - providerId
432
         - cod
433
        """
434
        try:
435
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod)
436
        finally:
437
            close_session()
438
 
1113 chandransh 439
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
440
        """
441
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
442
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
443
        Raises an exception if we encounter report for an AWB number that we did not ship.
444
 
445
        Parameters:
446
         - providerId
447
         - pickupDetails
448
        """
449
        try:
450
            orders_not_picked_up = mark_orders_as_picked_up(providerId, pickupDetails)
451
            return [to_t_order(order) for order in orders_not_picked_up]
452
        finally:
453
            close_session()
1132 chandransh 454
 
455
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
456
        """
457
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
458
        the name of the receiver.
459
        Raises an exception if we encounter report for an AWB number that we did not ship.
460
 
461
        Parameters:
462
         - providerId
463
         - deliveredOrders
464
        """
465
        try:
466
            mark_orders_as_delivered(providerId, deliveredOrders)
467
        finally:
468
            close_session()
1135 chandransh 469
 
4712 rajveer 470
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
471
        """
472
        Attributes:
473
         - orderId
474
         - deliveryTimestamp
475
         - receiver
476
        """
477
        try:
478
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
479
        finally:
480
            close_session()
481
 
482
 
1135 chandransh 483
    def markOrdersAsFailed(self, providerId, returnedOrders):
484
        """
485
        Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
486
        Raises an exception if we encounter report for an AWB number that we did not ship.
487
 
488
        Parameters:
489
         - providerId
490
         - returnedOrders
491
        """
492
        try:
493
            mark_orders_as_failed(providerId, returnedOrders)
494
        finally:
495
            close_session()
1246 chandransh 496
 
497
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
498
        """
499
        Update the status description of orders whose AWB numbers are keys of the Map.
500
 
501
        Parameters:
502
         - providerId
503
         - undelivered_orders
504
        """
505
        try:
4581 phani.kuma 506
            orders_not_delivered = update_non_delivery_reason(providerId, undeliveredOrders)
507
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 508
        finally:
509
            close_session()
1405 ankur.sing 510
 
511
    def getUndeliveredOrders(self, providerId, warehouseId):
512
        """
513
        Returns the list of orders whose delivery time has passed but have not been
514
        delivered yet for the given provider and warehouse. To get a complete list of
515
        undelivered orders, pass them as -1.
516
        Returns an empty list if no such orders exist.
517
 
518
        Parameters:
519
         - providerId
520
         - warehouseId
521
        """
522
        try:
523
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
524
            return [to_t_order(order) for order in undelivered_orders]
525
        finally:
526
            close_session()
1351 varun.gupt 527
 
1398 varun.gupt 528
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 529
        """
1398 varun.gupt 530
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 531
 
532
        Parameters:
533
         - transactionId
534
        """
535
        try:
1398 varun.gupt 536
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 537
        finally:
538
            close_session()
539
 
4444 rajveer 540
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 541
        """
542
        Parameters:
4394 rajveer 543
         - type
4444 rajveer 544
         - warehouseId
4394 rajveer 545
         - status
546
         - timestamp
483 rajveer 547
        """
766 rajveer 548
        try:
4444 rajveer 549
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 550
 
551
            t_alerts = []
552
            for alert in alerts:
553
                t_alerts.append(to_t_alert(alert)) 
554
 
555
            return t_alerts
556
        finally:
557
            close_session()
4394 rajveer 558
 
4447 rajveer 559
    def addAlert(self, type, warehouseId, description):
483 rajveer 560
        """
561
        Parameters:
562
         - type
4394 rajveer 563
         - description
4447 rajveer 564
         - warehouseId
483 rajveer 565
        """
766 rajveer 566
        try:
4447 rajveer 567
            add_alert(type, warehouseId, description)
766 rajveer 568
        finally:
569
            close_session()
1596 ankur.sing 570
 
4444 rajveer 571
    def markAlertsAsSeen(self, warehouseId):
572
        """
573
        Parameters:
574
         - warehouseId
575
        """
576
        try:
577
            mark_alerts_as_seen(warehouseId)
578
        finally:
579
            close_session()
580
        pass
581
 
1596 ankur.sing 582
    def getValidOrderCount(self, ):
583
        """
584
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
585
        """
1731 ankur.sing 586
        try:
587
            return get_valid_order_count()
588
        finally:
589
            close_session()
1627 ankur.sing 590
 
591
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
592
        """
593
        Returns the number of distinct customers who have done successful transactions
594
        """
1731 ankur.sing 595
        try:
596
            return get_cust_count_with_successful_txn()
597
        finally:
598
            close_session()
1627 ankur.sing 599
 
1731 ankur.sing 600
 
601
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 602
        """
1731 ankur.sing 603
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
604
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 605
        """
1731 ankur.sing 606
        try:
607
            return get_valid_orders_amount_range()
608
        finally:
609
            close_session()
1627 ankur.sing 610
 
1886 ankur.sing 611
    def getValidOrders(self, limit):
612
        """
613
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
614
        If limit is passed as 0, then all valid Orders are returned.
615
 
616
        Parameters:
617
         - limit
618
        """
619
        try:
620
            return [to_t_order(order) for order in get_valid_orders(limit)]
621
        finally:
622
            close_session()
104 ashish 623
 
2536 chandransh 624
    def toggleDOAFlag(self, orderId):
104 ashish 625
        """
2536 chandransh 626
        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.
627
        Returns the final flag status.
628
        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 629
 
132 ashish 630
        Parameters:
2536 chandransh 631
         - orderId
132 ashish 632
        """
2536 chandransh 633
        try:
634
            return toggle_doa_flag(orderId)
635
        finally:
636
            close_session()
483 rajveer 637
 
4454 rajveer 638
    def markOrderDoaRequestReceived(self, orderId):
639
        """
640
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
641
 
642
        Parameters:
643
         - orderId
644
        """
645
        try:
646
            return mark_order_doa_request_received(orderId)
647
        finally:
648
            close_session()
649
 
650
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized):
651
        """
652
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
653
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
654
 
655
        Parameters:
656
         - orderId
657
         - isAuthorized
658
        """
659
        try:
660
            return mark_order_doa_request_authorized(orderId, isAuthorized)
661
        finally:
662
            close_session()
663
 
4488 rajveer 664
    def markOrderReturnRequestReceived(self, orderId):
665
        """
666
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
667
 
668
        Parameters:
669
         - orderId
670
        """
671
        try:
672
            return mark_order_return_request_received(orderId)
673
        finally:
674
            close_session()
675
 
676
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized):
677
        """
678
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
679
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
680
 
681
        Parameters:
682
         - orderId
683
         - isAuthorized
684
        """
685
        try:
686
            return mark_order_return_request_authorized(orderId, isAuthorized)
687
        finally:
688
            close_session()
689
 
4579 rajveer 690
    def requestPickupNumber(self, orderId, providerId):
104 ashish 691
        """
2536 chandransh 692
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 693
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
694
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 695
        For any other status, it returns false.
696
        Throws an exception if the order with the given id couldn't be found.
104 ashish 697
 
698
        Parameters:
2536 chandransh 699
         - orderId
104 ashish 700
        """
2536 chandransh 701
        try:
4579 rajveer 702
            return request_pickup_number(orderId, providerId)
2536 chandransh 703
        finally:
704
            close_session()
483 rajveer 705
 
4602 rajveer 706
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 707
        """
4452 rajveer 708
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 709
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
710
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
711
            3. Returns true
712
        If the order is any other status, it returns false.
713
        Throws an exception if the order with the given id couldn't be found.
304 ashish 714
 
715
        Parameters:
2536 chandransh 716
         - orderId
717
         - pickupNumber
304 ashish 718
        """
2536 chandransh 719
        try:
4602 rajveer 720
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 721
        finally:
722
            close_session()    
2764 chandransh 723
 
724
    def markDoasAsPickedUp(self, providerId, pickupDetails):
725
        """
726
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
727
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
728
 
729
        Parameters:
730
         - providerId
731
         - pickupDetails
732
        """
733
        try:
734
            orders_not_picked_up = mark_doas_as_picked_up(providerId, pickupDetails)
735
            return [to_t_order(order) for order in orders_not_picked_up]
736
        finally:
737
            close_session()
2591 chandransh 738
 
4741 phani.kuma 739
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
740
        """
741
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
742
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
743
 
744
        Parameters:
745
         - providerId
746
         - pickupDetails
747
        """
748
        try:
749
            orders_not_picked_up = mark_return_orders_as_picked_up(providerId, pickupDetails)
750
            return [to_t_order(order) for order in orders_not_picked_up]
751
        finally:
752
            close_session()
753
 
4479 rajveer 754
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 755
        """
4452 rajveer 756
        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 757
        If the order is in any other state, it returns false.
758
        Throws an exception if the order with the given id couldn't be found.
759
 
760
        Parameters:
761
         - orderId
762
        """
763
        try:
4479 rajveer 764
            return receive_return(orderId, receiveCondition)
2591 chandransh 765
        finally:
766
            close_session()
767
 
768
    def validateDoa(self, orderId, isValid):
769
        """
4452 rajveer 770
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 771
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 772
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
773
        If the order is in any other state, it returns false.
774
        Throws an exception if the order with the given id couldn't be found.
775
 
776
        Parameters:
777
         - orderId
778
         - isValid
779
        """
780
        try:
781
            return validate_doa(orderId, isValid)
782
        finally:
783
            close_session()
2628 chandransh 784
 
4495 rajveer 785
    def validateReturnProduct(self, orderId, isUsable):
786
        """
787
        Parameters:
788
         - orderId
789
         - isUsable
790
        """
791
        try:
792
            return validate_return_product(orderId, isUsable)
793
        finally:
794
            close_session()
795
 
2628 chandransh 796
    def reshipOrder(self, orderId):
797
        """
4484 rajveer 798
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 799
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 800
            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 801
 
802
        If the order is in DOA_CERT_VALID state, it does the following:
803
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
804
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 805
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 806
 
807
        Returns the id of the newly created order.
808
 
809
        Throws an exception if the order with the given id couldn't be found.
810
 
811
        Parameters:
812
         - orderId
813
        """
814
        try:
815
            return reship_order(orderId)
816
        finally:
817
            close_session()
818
 
3226 chandransh 819
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 820
        """
4484 rajveer 821
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 822
            1. Creates a refund request for batch processing.
823
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 824
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 825
 
826
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
827
            1. Creates a refund request for batch processing.
3226 chandransh 828
            2. Cancels the reservation of the item in the warehouse.
829
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 830
 
3226 chandransh 831
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
832
            1. Cancels the reservation of the item in the warehouse.
833
            2. Marks the current order as CANCELED.
834
 
835
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
836
 
2628 chandransh 837
        Returns True if it is successful, False otherwise.
838
 
839
        Throws an exception if the order with the given id couldn't be found.
840
 
841
        Parameters:
842
         - orderId
3226 chandransh 843
         - refundedBy
844
         - reason
2628 chandransh 845
        """
846
        try:
3226 chandransh 847
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 848
        finally:
849
            close_session()
850
 
2697 chandransh 851
    def getReturnOrders(self, warehouseId, fromDate, toDate):
852
        """
853
        Get all return orders created between the from and to dates for the given warehouse.
854
        Ignores the warehouse if it is passed as -1.
855
 
856
        Parameters:
857
         - warehouseId
858
         - fromDate
859
         - toDate
860
        """
861
        try:
862
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
863
            return get_return_orders(warehouseId, from_date, to_date)
864
        finally:
865
            close_session()
866
 
2700 chandransh 867
    def getReturnOrder(self, id):
868
        """
869
        Returns the ReturnOrder corresponding to the given id.
870
        Throws an exception if the return order with the given id couldn't be found.
871
 
872
        Parameters:
873
         - id
874
        """
875
        try:
876
            return get_return_order(id)
877
        finally:
878
            close_session()
879
 
2697 chandransh 880
    def processReturn(self, returnOrderId):
881
        """
882
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
883
 
884
        Parameters:
885
         - returnOrderId
886
        """
887
        try:
888
            process_return(returnOrderId)
889
        finally:
890
            close_session()
4757 mandeep.dh 891
 
892
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 893
        """
4757 mandeep.dh 894
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
895
        the quantities for which the PO is raised.
896
 
2819 chandransh 897
        Parameters:
4757 mandeep.dh 898
         - itemIdQuantityMap
899
         - purchaseOrderId
2819 chandransh 900
         - warehouseId
901
        """
902
        try:
4757 mandeep.dh 903
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 904
        finally:
905
            close_session()
4757 mandeep.dh 906
 
3451 chandransh 907
    def updateWeight(self, orderId, weight):
908
        """
909
        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.
910
 
911
        Parameters:
912
         - orderId
913
         - weight
914
        """
915
        try:
916
            order = update_weight(orderId, weight)
917
            return to_t_order(order)
918
        finally:
919
            close_session()
920
 
3469 chandransh 921
    def changeItem(self, orderId, itemId):
922
        """
923
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
924
        Currently, it also ensures that only a different color of the given item is shipped.
925
 
926
        Parameters:
927
         - orderId
928
         - itemId
929
        """
930
        try:
931
            order = change_product(orderId, itemId)
932
            return to_t_order(order)
933
        finally:
934
            close_session()
935
 
936
    def shiftToWarehouse(self, orderId, warehouseId):
937
        """
938
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
939
 
940
        Parameters:
941
         - orderId
942
         - warehouseId
943
        """
944
        try:
945
            order = change_warehouse(orderId, warehouseId)
946
            return to_t_order(order)
947
        finally:
948
            close_session()
3553 chandransh 949
 
4647 rajveer 950
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 951
        """
952
        Adds the given delay reason to the given order.
3986 chandransh 953
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 954
        Raises an exception if no order with the given id can be found.
3469 chandransh 955
 
3553 chandransh 956
        Parameters:
957
         - orderId
958
         - delayReason
959
        """
960
        try:
4647 rajveer 961
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 962
        finally:
963
            close_session()
964
 
3956 chandransh 965
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
966
        """
967
        Marks the COD orders with given AWB nos. as having been processed.
968
        Updates the captured amount for the corresponding payment.
969
 
970
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
971
        1. There is no order corresponding to an AWB number.
972
        2. The captured amount for a payment exceeds the total payment.
973
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
974
 
975
        Parameters:
976
         - collectedAmountMap
977
         - xferBy
978
         - xferTxnId
979
         - xferDate
980
        """
981
        try:
982
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
983
        finally:
984
            close_session()
4008 mandeep.dh 985
 
986
    def getTransactionsRequiringExtraProcessing(self, category):
987
        """
988
        Returns the list of transactions that require some extra processing and
989
        which belong to a particular category. This is currently used by CRM
990
        application.
991
        """
992
        try:
993
            return get_transactions_requiring_extra_processing(category)
994
        finally:
995
            close_session()
996
 
997
    def markTransactionAsProcessed(self, transactionId, category):
998
        """
999
        Marks a particular transaction as processed for a particular category.
1000
        It essentially deletes the transaction if it is processed for a particular
1001
        category. This is currently used by CRM application.
1002
        """
1003
        try:
1004
            return mark_transaction_as_processed(transactionId, category)
1005
        finally:
1006
            close_session()
4018 chandransh 1007
 
1008
    def getItemWiseRiskyOrdersCount(self, ):
1009
        """
1010
        Returns a map containing the number of risky orders keyed by item id. A risky order
1011
        is defined as one whose shipping date is about to expire.
1012
        """
1013
        try:
1014
            return get_item_wise_risky_orders_count()
1015
        finally:
1016
            close_session()
3956 chandransh 1017
 
4247 rajveer 1018
    def markOrderCancellationRequestReceived(self, orderId):
1019
        """
1020
        Mark order as cancellation request received. If customer sends request of cancellation of
1021
        a particular order, this method will be called. It will just change status of the order
1022
        depending on its current status. It also records the previous status, so that we can move
1023
        back to that status if cancellation request is denied.
1024
 
1025
        Parameters:
1026
         - orderId
1027
        """
1028
        try:
1029
            return mark_order_cancellation_request_received(orderId)
1030
        finally:
1031
            close_session()
1032
 
1033
 
4662 rajveer 1034
    def markOrderAsLostInTransit(self, orderId):
1035
        """
1036
        Parameters:
1037
         - orderId
1038
        """
1039
        try:
1040
            return mark_order_as_lost_in_transit(orderId)
1041
        finally:
1042
            close_session()
1043
 
4258 rajveer 1044
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1045
        """
4258 rajveer 1046
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1047
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1048
 
1049
        Parameters:
4258 rajveer 1050
         - transactionId
4247 rajveer 1051
        """
1052
        try:
4259 anupam.sin 1053
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1054
        finally:
1055
            close_session()
4259 anupam.sin 1056
 
1057
    def refundTransaction(self, transactionId, refundedBy, reason):
1058
        """
1059
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1060
        need to be cancelled
1061
 
1062
        Parameters:
1063
         - transactionId
1064
        """
1065
        try:
1066
            return refund_transaction(transactionId, refundedBy, reason)
1067
        finally:
1068
            close_session()
4247 rajveer 1069
 
1070
    def markOrderCancellationRequestDenied(self, orderId):
1071
        """
1072
        If we decide to not to cancel order, we will move the order ro previous status.
1073
 
1074
        Parameters:
1075
         - orderId
1076
        """
1077
        try:
1078
            return mark_order_cancellation_request_denied(orderId)
1079
        finally:
1080
            close_session()
1081
 
1082
    def markOrderCancellationRequestConfirmed(self, orderId):
1083
        """
1084
        If we decide to to cancel order, CRM will call this method to move the status of order to
1085
        cancellation request confirmed. After this OM will be able to cancel the order.
1086
 
1087
        Parameters:
1088
         - orderId
1089
        """
1090
        try:
1091
            return mark_order_cancellation_request_confirmed(orderId)
1092
        finally:
1093
            close_session()
1094
 
4324 mandeep.dh 1095
    def updateShipmentAddress(self, orderId, addressId):
1096
        """
1097
        Updates shipment address of an order. Delivery and shipping date estimates
1098
        etc. are also updated here.
1099
 
1100
        Throws TransactionServiceException in case address change is not
1101
        possible due to certain reasons such as new pincode in address is
1102
        not serviceable etc.
1103
 
1104
        Parameters:
1105
         - orderId
1106
         - addressId
1107
        """
1108
        try:
1109
            update_shipment_address(orderId, addressId)
1110
        finally:
1111
            close_session()
1112
 
4285 rajveer 1113
    def acceptOrdersForItemId(self, itemId, inventory):
1114
        """
1115
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1116
        given order is not a COD order, it also captures the payment if the same has not been captured.
1117
 
1118
        Parameters:
1119
         - itemId
1120
         - inventory
1121
        """
1122
        try:
1123
            return accept_orders_for_item_id(itemId, inventory)
1124
        finally:
1125
            close_session()
1126
 
4303 rajveer 1127
 
1128
 
4369 rajveer 1129
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1130
        """
1131
        Parameters:
1132
         - vendorId
1133
         - itemId
1134
         - quantity
1135
         - estimate
4369 rajveer 1136
         - isReminder
4303 rajveer 1137
        """
1138
        try:
4369 rajveer 1139
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1140
        finally:
1141
            close_session()
1142
 
4369 rajveer 1143
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1144
        """
1145
        Parameters:
1146
         - vendorId
1147
         - itemId
1148
         - quantity
1149
         - estimate
4369 rajveer 1150
         - isReminder
4303 rajveer 1151
        """
1152
        try:
4369 rajveer 1153
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1154
        finally:
1155
            close_session()
1156
 
4369 rajveer 1157
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1158
        """
1159
        Parameters:
1160
         - vendorId
1161
         - itemId
1162
         - quantity
1163
         - estimate
4369 rajveer 1164
         - isReminder
4303 rajveer 1165
        """
1166
        try:
4369 rajveer 1167
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1168
        finally:
1169
            close_session()
1170
 
1171
 
4369 rajveer 1172
    def markOrdersAsTimeout(self, vendorId):
1173
        """
1174
        Parameters:
1175
         - vendorId
1176
        """
1177
        try:
1178
            return mark_orders_as_timeout(vendorId)
1179
        finally:
1180
            close_session()
4386 anupam.sin 1181
 
1182
    def getOrderForAwb(self, awb):
1183
        """
1184
        Parameters:
1185
         - AirwayBill Number
1186
        """
1187
        try:
1188
            return to_t_order(get_order_for_awb(awb))
1189
        finally:
1190
            close_session()
4369 rajveer 1191
 
4506 phani.kuma 1192
    def getOrdersForProviderForStatus(self, provider_id, order_status):
1193
        """
1194
        Parameters:
1195
         - provider id
1196
         - order status
1197
        """
1198
        try:
1199
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status)
1200
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1201
        finally:
1202
            close_session()
4600 varun.gupt 1203
 
1204
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1205
        '''
1206
        Parameters:
1207
         - vendorId
1208
         - billingDateFrom
1209
         - billingDateTo
1210
        '''
1211
        try:
1212
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1213
        finally:
1214
            close_session()
1215
 
4607 rajveer 1216
    def getSlippedSippingDateOrders(self):
1217
        try:
1218
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1219
        finally:
1220
            close_session()
1221
 
4709 rajveer 1222
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1223
        try:
1224
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1225
        finally:
1226
            close_session()
1227
 
4600 varun.gupt 1228
    def getEBSSettlementSummaries(self):
1229
        try:
1230
            return get_ebs_settlement_summaries()
1231
        finally:
1232
            close_session()
4369 rajveer 1233
 
4600 varun.gupt 1234
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1235
        try:
1236
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1237
        finally:
1238
            close_session()
1239
 
1240
    def getSettlementForPaymentId(self, paymentId):
1241
        '''
1242
        Parameters:
1243
         - paymentId
1244
        '''
1245
        try:
1246
            return to_t_payment_settlement(get_settlement_for_paymentId(paymentId))
1247
        finally:
1248
            close_session()
1249
 
1250
    def getEBSSettlementDate(self, settlementId):
1251
        try:
1252
            return to_java_date(get_ebs_settlement_date(settlementId))
1253
        finally:
1254
            close_session()
1255
 
1256
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, paymentId, serviceTax, otherCharges, netCollection):
1257
        try:
1258
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, paymentId, serviceTax, otherCharges, netCollection)
1259
        finally:
1260
            close_session()
1261
 
1262
    def markEBSSettlementUploaded(self, settlementId):
1263
        try:
1264
            mark_ebs_settlement_uploaded(settlementId)
1265
        finally:
1266
            close_session()
1267
 
4715 varun.gupt 1268
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1269
        try:
1270
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1271
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1272
        finally:
1273
            close_session()
1274
 
1275
    def getReshippedOrderIds(self, orderIds):
1276
        try:
1277
            return get_reshipped_order_ids(orderIds)
1278
        finally:
1279
            close_session()
1280
 
2536 chandransh 1281
    def closeSession(self, ):
1282
        close_session()
3376 rajveer 1283
 
1284
    def isAlive(self, ):
1285
        """
1286
        For checking weather service is active alive or not. It also checks connectivity with database
1287
        """
1288
        try:
1289
            return is_alive()
1290
        finally:
4247 rajveer 1291
            close_session()