Subversion Repositories SmartDukaan

Rev

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