Subversion Repositories SmartDukaan

Rev

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