Subversion Repositories SmartDukaan

Rev

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