Subversion Repositories SmartDukaan

Rev

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