Subversion Repositories SmartDukaan

Rev

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