Subversion Repositories SmartDukaan

Rev

Rev 7169 | Rev 7190 | 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
'''
6056 amit.gupta 6
from elixir import session
7032 rajveer 7
from shop2020.model.v1.order.impl import DataService, RedExpressUpdateService
6000 mandeep.dh 8
from shop2020.model.v1.order.impl.Convertors import to_t_transaction, to_t_alert, \
9
    to_t_order, to_t_lineitem, to_t_payment_settlement, to_t_verification_agent, \
7096 anupam.sin 10
    to_t_attribute, to_t_rechargeTransaction, to_t_frc, to_t_hotspot
6000 mandeep.dh 11
from shop2020.model.v1.order.impl.DataAccessors import create_transaction, \
12
    get_transactions_for_customer, get_transaction_status, get_line_items_for_order, \
13
    get_transaction, get_transactions_for_shopping_cart_id, \
14
    change_transaction_status, get_orders_for_customer, get_orders_for_transaction, \
15
    get_order, get_returnable_orders_for_customer, \
16
    get_cancellable_orders_for_customer, get_orders_by_billing_date, get_all_orders, \
17
    change_order_status, get_alerts, add_alert, add_billing_details, close_session, \
18
    accept_order, mark_orders_as_picked_up, mark_orders_as_delivered, \
19
    mark_orders_as_rto, order_outofstock, batch_orders, update_non_delivery_reason, \
20
    enqueue_transaction_info_email, get_undelivered_orders, get_order_for_customer, \
21
    get_valid_order_count, get_cust_count_with_successful_txn, \
22
    get_valid_orders_amount_range, get_valid_orders, toggle_doa_flag, \
23
    request_pickup_number, authorize_pickup, receive_return, validate_doa, \
24
    reship_order, refund_order, get_return_orders, process_return, get_return_order, \
25
    mark_doas_as_picked_up, verify_order, is_alive, get_orders_by_shipping_date, \
26
    update_weight, change_warehouse, change_product, add_delay_reason, \
27
    reconcile_cod_collection, get_transactions_requiring_extra_processing, \
28
    mark_transaction_as_processed, get_item_wise_risky_orders_count, \
29
    accept_order_for_item, get_orders_in_batch, get_order_count, \
30
    get_ebs_settlement_summaries, mark_order_cancellation_request_received, \
31
    mark_order_cancellation_request_denied, refund_transaction, \
32
    mark_order_cancellation_request_confirmed, \
33
    mark_transaction_as_payment_flag_removed, accept_orders_for_item_id, \
34
    mark_orders_as_po_raised, mark_orders_as_reversal_initiated, \
35
    mark_orders_as_not_available, update_shipment_address, mark_orders_as_timeout, \
36
    get_order_for_awb, mark_orders_as_shipped_from_warehouse, mark_alerts_as_seen, \
37
    mark_order_doa_request_received, mark_order_doa_request_authorized, \
38
    mark_order_return_request_received, mark_order_return_request_authorized, \
39
    add_invoice_number, get_reshipped_order_ids, validate_return_product, \
40
    get_orders_for_provider_for_status, save_ebs_settlement_summary, \
41
    get_ebs_settlement_date, save_payment_settlements, mark_ebs_settlement_uploaded, \
42
    get_billed_orders_for_vendor, get_settlement_for_Prepaid, \
43
    get_settlements_by_date, get_slipped_sipping_date_orders, \
44
    mark_order_as_lost_in_transit, get_cancelled_orders, mark_order_as_delivered, \
45
    mark_return_orders_as_picked_up, update_orders_as_PORaised, \
46
    get_order_distribution_by_status, get_orders_not_met_expected_delivery_date, \
47
    mark_orders_as_local_connected, mark_orders_as_destinationCityReached, \
48
    mark_orders_as_firstDeliveryAttempted, get_non_delivered_orders_by_courier, \
49
    get_orders_not_local_connected, get_doas_not_picked_up, \
50
    get_return_orders_not_picked_up, get_orders_not_picked_up, get_rto_orders, \
51
    get_order_list, get_order_ids_for_status, update_orders_as_paid_to_vendor, \
52
    update_COD_agent, get_refunded_orders_marked_paid, get_settlement_for_Cod, \
53
    get_order_list_for_vendor, update_order_only_as_paid_to_vendor, \
54
    get_all_verification_agents, get_all_attributes_for_order_id, \
55
    set_order_attribute_for_transaction, get_billed_orders, get_all_return_orders, \
56
    mark_order_as_received_at_store, get_receive_pending_orders, \
57
    get_received_at_store_orders, mark_orders_as_returned_from_store, \
6056 amit.gupta 58
    set_order_attributes, get_orders_collection_at_store, get_order_attribute_value, \
59
    change_jacket_number, mark_order_as_rto_in_transit, get_recharge_order, \
60
    get_recharge_orders, update_recharge_order_status, activate_recharge_txn, \
61
    get_user_wallet, get_user_wallet_history, get_service_providers, \
6396 amit.gupta 62
    get_service_provider_for_device, get_recharge_orders_for_transaction, \
63
    update_amount_in_wallet, get_recharge_orders_for_device, \
64
    get_recharge_orders_for_status, get_plans_for_operator, get_recharge_statistics, \
65
    validate_recharge, get_recharge_denominations, update_availability_status, \
6821 amar.kumar 66
    get_misc_charges, get_available_emi_schemes, refund_recharge_order, \
7073 anupam.sin 67
    create_recharge_transaction, get_physical_orders, get_document, retrieve_invoice, \
7125 amit.gupta 68
    change_shipping_address, get_recharge_transactions, get_recharge_transaction, \
7151 amit.gupta 69
    get_frcs, get_hotspot_store, get_circle, retrieve_hotspot_recharge_invoice, \
7169 anupam.sin 70
    get_recharge_trans, get_recharge_transactions_by_number, update_hotspot_store_password
6000 mandeep.dh 71
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
6056 amit.gupta 72
from shop2020.model.v1.order.impl.model.DigitalTransaction import \
73
    DigitalTransaction
6000 mandeep.dh 74
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import \
75
    MobileRechargeOrder
76
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
77
    RechargeType
78
from shop2020.utils.Utils import to_py_date, get_fdate_tdate, to_java_date
6031 rajveer 79
import datetime
1405 ankur.sing 80
 
5527 anupam.sin 81
 
104 ashish 82
 
83
class OrderServiceHandler:
84
 
3187 rajveer 85
    def __init__(self, dbname='transaction', db_hostname='localhost'):
483 rajveer 86
        """
104 ashish 87
        Constructor
483 rajveer 88
        """
3187 rajveer 89
        DataService.initialize(dbname, db_hostname)
104 ashish 90
 
91
    def createTransaction(self, transaction):
92
        """
93
        Parameters:
94
         - transaction
95
        """
766 rajveer 96
        try:
97
            return create_transaction(transaction)
98
        finally:
99
            close_session()
100
 
104 ashish 101
    def getTransaction(self, id):
102
        """
103
            Get transaction methods.
104
 
105
        Parameters:
106
         - id
107
        """
766 rajveer 108
        try:
109
            transaction = get_transaction(id)
110
            return to_t_transaction(transaction)
111
        finally:
112
            close_session()
113
 
483 rajveer 114
    def getTransactionsForCustomer(self, customerId, from_date, to_date, status):
104 ashish 115
        """
116
        Parameters:
483 rajveer 117
         - customerId
104 ashish 118
         - from_date
119
         - to_date
483 rajveer 120
         - status
104 ashish 121
        """
766 rajveer 122
        try:
123
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
124
 
125
            transactions = get_transactions_for_customer(customerId, current_from_date, current_to_date, status)
126
            t_transaction = []
127
            for transaction in transactions:
128
                t_transaction.append(to_t_transaction(transaction))
129
            return t_transaction
130
        finally:
131
            close_session()
483 rajveer 132
 
133
    def getTransactionsForShoppingCartId(self, shoppingCartId):
134
        """
135
        Parameters:
136
            - shoppingCartId
137
        """
766 rajveer 138
        try:
139
            transactions = get_transactions_for_shopping_cart_id(shoppingCartId)
140
            t_transaction = []
141
            for transaction in transactions:
142
                t_transaction.append(to_t_transaction(transaction))
143
            return t_transaction
144
        finally:
145
            close_session()
104 ashish 146
 
483 rajveer 147
    def getTransactionStatus(self, transactionId):
104 ashish 148
        """
149
        Parameters:
483 rajveer 150
         - transactionId
151
        """
766 rajveer 152
        try:
153
            return get_transaction_status(transactionId)
154
        finally:
155
            close_session()
156
 
5527 anupam.sin 157
    def changeTransactionStatus(self, transactionId, status, description, pickUp, orderType):
483 rajveer 158
        """
159
        Parameters:
160
         - transactionId
104 ashish 161
         - status
483 rajveer 162
         - description
5387 rajveer 163
         - selfPickup
483 rajveer 164
        """
766 rajveer 165
        try:
5527 anupam.sin 166
            return change_transaction_status(transactionId, status, description, pickUp, orderType)
766 rajveer 167
        finally:
168
            close_session()
169
 
1528 ankur.sing 170
    def getOrdersForTransaction(self, transactionId, customerId):
483 rajveer 171
        """
1528 ankur.sing 172
        Returns list of orders for given transaction Id. Also filters based on customer Id so that
173
        only user who owns the transaction can view its order details.
174
 
483 rajveer 175
        Parameters:
176
         - transactionId
1528 ankur.sing 177
         - customerId
483 rajveer 178
        """
766 rajveer 179
        try:
1528 ankur.sing 180
            orders = get_orders_for_transaction(transactionId, customerId)
766 rajveer 181
            return [to_t_order(order) for order in orders]    
182
        finally:
183
            close_session()
184
 
4801 anupam.sin 185
    def getAllOrders(self, statuses, from_date, to_date, warehouse_id):
483 rajveer 186
        """
187
        Parameters:
188
         - status
104 ashish 189
         - from_date
190
         - to_date
483 rajveer 191
         - warehouse_id
104 ashish 192
        """
766 rajveer 193
        try:
194
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)        
4801 anupam.sin 195
            orders = get_all_orders(statuses, current_from_date, current_to_date, warehouse_id)
766 rajveer 196
            return [to_t_order(order) for order in orders]
197
        finally:
198
            close_session()
4133 chandransh 199
 
200
    def getOrdersInBatch(self, statuses, offset, limit, warehouse_id):
201
        """
202
        Returns at most 'limit' orders with the given statuses for the given warehouse starting from the given offset.
203
        Pass the status as null and the limit as 0 to ignore them.
204
 
205
        Parameters:
206
         - statuses
207
         - offset
208
         - limit
209
         - warehouse_id
210
        """
211
        try:
212
            orders = get_orders_in_batch(statuses, offset, limit, warehouse_id)
213
            return [to_t_order(order) for order in orders]
214
        finally:
215
            close_session()
216
 
217
    def getOrderCount(self, statuses, warehouseId):
218
        """
219
        Returns the count of orders with the given statuses assigned to the given warehouse.
220
 
221
        Parameters:
222
         - statuses
223
         - warehouseId
224
        """
225
        try:
226
            return get_order_count(statuses, warehouseId)
227
        finally:
228
            close_session()
229
 
995 varun.gupt 230
    def getOrdersByBillingDate(self, status, start_billing_date, end_billing_date, warehouse_id):
231
        """
232
        Parameters:
233
         - status
234
         - start_billing_date
235
         - end_billing_date
236
         - warehouse_id
237
        """
238
        try:
239
            current_start_billing_date, current_end_billing_date = get_fdate_tdate(start_billing_date, end_billing_date)
240
            orders = get_orders_by_billing_date(status, current_start_billing_date, current_end_billing_date, warehouse_id)
241
            return [to_t_order(order) for order in orders]
242
        finally:
243
            close_session()
1382 varun.gupt 244
 
3451 chandransh 245
    def getOrdersByShippingDate(self, fromShippingDate, toShippingDate, providerId, warehouseId, cod):
3427 chandransh 246
        """
247
        Returns orders for a particular provider and warehouse which were shipped between the given dates.
3451 chandransh 248
        Returned orders comprise of COD orders if cod parameter is true. It comprises of prepaid orders otherwise.
249
        Pass providerId and warehouseId as -1 to ignore both these parameters.
3427 chandransh 250
 
251
        Parameters:
252
         - fromShippingDate
253
         - toShippingDate
254
         - providerId
255
         - warehouseId
3451 chandransh 256
         - cod
3427 chandransh 257
        """
258
        try:
259
            from_shipping_date, to_shipping_date = get_fdate_tdate(fromShippingDate, toShippingDate)
3451 chandransh 260
            orders = get_orders_by_shipping_date(from_shipping_date, to_shipping_date, providerId, warehouseId, cod)
3427 chandransh 261
            return [to_t_order(order) for order in orders]
262
        finally:
263
            close_session()
264
 
1382 varun.gupt 265
    def getReturnableOrdersForCustomer(self, customerId, limit = None):
266
        """
267
        Parameters:
268
         - customerId
269
         - limit
270
        """
271
        try:
272
            return get_returnable_orders_for_customer(customerId, limit)
273
        finally:
274
            close_session()
995 varun.gupt 275
 
1382 varun.gupt 276
    def getCancellableOrdersForCustomer(self, customerId, limit = None):
277
        """
278
        Parameters:
279
         - customerId
280
         - limit
281
        """
282
        try:
283
            return get_cancellable_orders_for_customer(customerId, limit)
284
        finally:
285
            close_session()
286
 
483 rajveer 287
    def changeOrderStatus(self, orderId, status, description):
288
        """
289
        Parameters:
290
         - orderId
291
         - status
292
         - description
293
         - 
294
        """
766 rajveer 295
        try:
296
            return change_order_status(self, orderId, status, description)
297
        finally:
298
            close_session()
921 rajveer 299
 
3064 chandransh 300
    def verifyOrder(self, orderId):
301
        """
302
        Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
303
        timestamp. It is intended to be used for COD orders but can be harmlessly
304
        used for all other orders as well.
305
        Throws an exception if no such order exists.
306
 
307
        Parameters:
308
         - orderId
309
        """
310
        try:
311
            return verify_order(self, orderId)
312
        finally:
313
            close_session()
314
 
921 rajveer 315
    def acceptOrder(self, orderId):
316
        """
3064 chandransh 317
        Marks the given order as ACCEPTED and updates the accepted timestamp. If the
318
        given order is not a COD order, it also captures the payment if the same has
319
        not been captured.
320
        Throws an exception if no such order exists.
321
 
921 rajveer 322
        Parameters:
323
         - orderId
324
        """
325
        try:
4285 rajveer 326
            return accept_order(orderId)
921 rajveer 327
        finally:
328
            close_session()
329
 
3014 chandransh 330
    def getOrdersForCustomer(self, customerId, from_date, to_date, statuses):
104 ashish 331
        """
3014 chandransh 332
        Returns list of orders for the given customer created between the given dates and having the given statuses.
333
        Pass and empty list to ignore filtering on statuses.
334
 
104 ashish 335
        Parameters:
336
         - customerId
337
         - from_date
338
         - to_date
3014 chandransh 339
         - statuses
104 ashish 340
        """
766 rajveer 341
        try:
342
            current_from_date, current_to_date = get_fdate_tdate(from_date, to_date)
343
 
3014 chandransh 344
            orders = get_orders_for_customer(customerId, current_from_date, current_to_date, statuses)
766 rajveer 345
            return [to_t_order(order) for order in orders]
346
        finally:
347
            close_session()
1528 ankur.sing 348
 
349
    def getOrderForCustomer(self, orderId, customerId):
350
        """
351
        Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
352
        Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
353
 
354
        Parameters:
355
         - customerId
356
         - orderId
357
        """
358
        try:
359
            return to_t_order(get_order_for_customer(orderId, customerId))
360
        finally:
361
            close_session()
766 rajveer 362
 
483 rajveer 363
    def getOrder(self, id):
364
        """
365
        Parameters:
366
         - id
367
        """
766 rajveer 368
        try:
369
            return to_t_order(get_order(id))
370
        finally:
371
            close_session()
4999 phani.kuma 372
 
373
    def getOrderList(self, order_ids):
374
        """
375
        Parameters:
376
         - order_ids
377
        """
378
        try:
379
            orders = get_order_list(order_ids)
380
            return [to_t_order(order) for order in orders]
381
        finally:
382
            close_session()
383
 
5386 phani.kuma 384
    def getOrderListForVendor(self, order_ids, vendorId):
385
        """
386
        Parameters:
387
         - order_ids
388
         - vendorId
389
        """
390
        try:
391
            orders = get_order_list_for_vendor(order_ids, vendorId)
392
            return [to_t_order(order) for order in orders]
393
        finally:
394
            close_session()
395
 
483 rajveer 396
    def getLineItemsForOrder(self, orderId):
397
        """
398
        Parameters:
399
         - orderId
400
        """
766 rajveer 401
        try:
402
            lineitems = get_line_items_for_order(orderId)
403
            t_lineitems = []
404
            for lineitem in lineitems:
405
                t_lineitems.append(to_t_lineitem(lineitem))
406
            return t_lineitems
407
        finally:
408
            close_session()
1149 chandransh 409
 
4763 rajveer 410
    def addBillingDetails(self, orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
494 rajveer 411
        """
4658 mandeep.dh 412
        Adds jacket number and serial no. to the order. Doesn't update the serial no. if a -1 is supplied.
2783 chandransh 413
        Also marks the order as billed and sets the billing timestamp.
414
        Return false if it doesn't find the order with the given ID.
1149 chandransh 415
 
416
        Parameters:
417
         - orderId
418
         - jacketNumber
4658 mandeep.dh 419
         - serialNumber
2783 chandransh 420
         - itemNumber
421
         - billedBy
1149 chandransh 422
        """
423
        try:
4763 rajveer 424
            return add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize)
1149 chandransh 425
        finally:
426
            close_session()
1220 chandransh 427
 
6751 amar.kumar 428
    def addInvoiceNumber(self, orderId, invoiceNumber, color, serialNumber, itemNumber):
4579 rajveer 429
        """
430
        Add the invoice number to the order.
431
 
432
        Parameters:
433
         - orderId
434
         - invoice_number
435
        """
436
        try:
6751 amar.kumar 437
            add_invoice_number(orderId, invoiceNumber, color, serialNumber, itemNumber)
4579 rajveer 438
        finally:
439
            close_session()
440
 
1220 chandransh 441
    def batchOrders(self, warehouseId):
442
        """
443
        Create a batch of all the pending orders for the given warehouse.
444
        The returned list is orderd by created_timestamp.
445
        If there are no pending orders, an empty list is returned.
1208 chandransh 446
 
1220 chandransh 447
        Parameters:
448
         - warehouseId
449
        """
450
        try:
451
            pending_orders = batch_orders(warehouseId)
452
            return [to_t_order(order) for order in pending_orders]
453
        finally:
454
            close_session()
455
 
1208 chandransh 456
    def markOrderAsOutOfStock(self, orderId):
457
        """
458
        Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found.
459
 
460
 
461
        Parameters:
462
         - orderId
463
        """
464
        try:
465
            return order_outofstock(orderId)
466
        finally:
467
            close_session()
468
 
4910 phani.kuma 469
    def markOrdersAsShippedFromWarehouse(self, warehouseId, providerId, cod, orderIds):
759 chandransh 470
        """
3064 chandransh 471
        Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
4910 phani.kuma 472
        given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
759 chandransh 473
 
474
        Parameters:
475
         - warehouseId
476
         - providerId
3064 chandransh 477
         - cod
759 chandransh 478
        """
766 rajveer 479
        try:
4910 phani.kuma 480
            return mark_orders_as_shipped_from_warehouse(warehouseId, providerId, cod, orderIds)
766 rajveer 481
        finally:
482
            close_session()
1113 chandransh 483
 
5713 rajveer 484
    def markOrdersAsReturnedFromStore(self, providerId, orderIds, awbs):
5676 rajveer 485
        """
486
        Parameters:
487
         - providerId
488
         - orderIds
5713 rajveer 489
         - awbs
5676 rajveer 490
        """
491
        try:
5713 rajveer 492
            return mark_orders_as_returned_from_store(providerId, orderIds, awbs)
5676 rajveer 493
        finally:
494
            close_session()
495
 
496
    def setOrderAttributes(self, orderId, attributes):
497
        """
498
        sets attributes for an order
499
 
500
        Parameters:
501
         - orderId
502
         - attributes
503
        """
504
        try:
505
            return set_order_attributes(orderId, attributes)
506
        finally:
507
            close_session()
508
 
509
 
4910 phani.kuma 510
    def markOrdersAsPickedUp(self, providerId, pickupDetails):
4410 rajveer 511
        """
4910 phani.kuma 512
        Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
513
        Raises an exception if we encounter report for an AWB number that we did not ship.
4410 rajveer 514
 
515
        Parameters:
516
         - providerId
4910 phani.kuma 517
         - pickupDetails
4410 rajveer 518
        """
519
        try:
4910 phani.kuma 520
            mark_orders_as_picked_up(providerId, pickupDetails)
4410 rajveer 521
        finally:
522
            close_session()
523
 
4910 phani.kuma 524
    def getOrdersNotPickedUp(self, providerId):
1113 chandransh 525
        """
526
        Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
527
 
528
        Parameters:
529
         - providerId
530
        """
531
        try:
4910 phani.kuma 532
            orders_not_picked_up = get_orders_not_picked_up(providerId)
1113 chandransh 533
            return [to_t_order(order) for order in orders_not_picked_up]
534
        finally:
535
            close_session()
1132 chandransh 536
 
537
    def markOrdersAsDelivered(self, providerId, deliveredOrders):
538
        """
539
        Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
540
        the name of the receiver.
541
        Raises an exception if we encounter report for an AWB number that we did not ship.
542
 
543
        Parameters:
544
         - providerId
545
         - deliveredOrders
546
        """
547
        try:
548
            mark_orders_as_delivered(providerId, deliveredOrders)
549
        finally:
550
            close_session()
1135 chandransh 551
 
4712 rajveer 552
    def markOrderAsDelivered(self, orderId, deliveryTimestamp, receiver):
553
        """
554
        Attributes:
555
         - orderId
556
         - deliveryTimestamp
557
         - receiver
558
        """
559
        try:
560
            mark_order_as_delivered(orderId, to_py_date(deliveryTimestamp), receiver)
561
        finally:
562
            close_session()
563
 
564
 
5555 rajveer 565
    def markOrderAsReceivedAtStore(self, orderId, deliveryTimestamp):
566
        """
567
        Attributes:
568
         - orderId
569
         - deliveryTimestamp
570
        """
571
        try:
572
            mark_order_as_received_at_store(orderId, to_py_date(deliveryTimestamp))
573
        finally:
574
            close_session()
575
 
576
    def getReceivePendingOrders(self, storeId):
577
        """
578
        Attributes:
579
         - storeId
580
        """
581
        try:
582
            orders = get_receive_pending_orders(storeId)
583
            return [to_t_order(order) for order in orders]
584
        finally:
585
            close_session()
586
 
587
    def getReceivedAtStoreOrders(self, storeId):
588
        """
589
        Attributes:
590
         - storeId
591
        """
592
        try:
593
            orders = get_received_at_store_orders(storeId)
594
            return [to_t_order(order) for order in orders]
595
        finally:
596
            close_session()
5713 rajveer 597
 
598
    def getOrdersCollectionAtStore(self, storeId, fromDate, toDate, onlyCod):
599
        """
600
        Parameters:
601
         - storeId
602
         - fromDate
603
         - toDate
604
         - onlyCod
605
        """
606
        try:
607
            orders = get_orders_collection_at_store(storeId, to_py_date(fromDate), to_py_date(toDate), onlyCod)
608
            return [to_t_order(order) for order in orders]
609
        finally:
610
            close_session()
611
 
4910 phani.kuma 612
    def markAsRTOrders(self, providerId, returnedOrders):
1135 chandransh 613
        """
4910 phani.kuma 614
        Mark all orders with AWBs in the given map as RTO. Also sets the delivery timestamp.
1135 chandransh 615
        Raises an exception if we encounter report for an AWB number that we did not ship.
616
 
617
        Parameters:
618
         - providerId
619
         - returnedOrders
620
        """
621
        try:
4910 phani.kuma 622
            mark_orders_as_rto(providerId, returnedOrders)
1135 chandransh 623
        finally:
624
            close_session()
1246 chandransh 625
 
4910 phani.kuma 626
    def getRTOrders(self, providerId):
627
        """
628
        Returns a list of orders that were returned by courier.
629
 
630
        Parameters:
631
         - providerId
632
        """
633
        try:
634
            rto_orders = get_rto_orders(providerId)
635
            return [to_t_order(order) for order in rto_orders]
636
        finally:
637
            close_session()
638
 
1246 chandransh 639
    def updateNonDeliveryReason(self, providerId, undeliveredOrders):
640
        """
641
        Update the status description of orders whose AWB numbers are keys of the Map.
642
 
643
        Parameters:
644
         - providerId
645
         - undelivered_orders
646
        """
647
        try:
4910 phani.kuma 648
            update_non_delivery_reason(providerId, undeliveredOrders)
649
        finally:
650
            close_session()
651
 
652
    def getNonDeliveredOrdersbyCourier(self, providerId):
653
        """
654
        Returns a list of orders that were picked up or shipped four days ago but did not get delivered.
655
 
656
        Parameters:
657
         - providerId
658
        """
659
        try:
660
            orders_not_delivered = get_non_delivered_orders_by_courier(providerId)
4581 phani.kuma 661
            return [to_t_order(order) for order in orders_not_delivered]
1246 chandransh 662
        finally:
663
            close_session()
1405 ankur.sing 664
 
4910 phani.kuma 665
    def markOrdersAsLocalConnected(self, providerId, local_connected_orders):
666
        """
667
        Mark all orders with AWBs in the given map as local connected. Also sets the local connected timestamp.
668
 
669
        Parameters:
670
         - providerId
671
         - local_connected_orders
672
        """
673
        try:
674
            mark_orders_as_local_connected(providerId, local_connected_orders)
675
        finally:
676
            close_session()
677
 
678
    def getOrdersNotLocalConnected(self, providerId):
679
        """
680
        Returns a list of orders that were picked up or shipped but pending local connection.
681
 
682
        Parameters:
683
         - providerId
684
        """
685
        try:
686
            orders_pending_local_connection = get_orders_not_local_connected(providerId)
687
            return [to_t_order(order) for order in orders_pending_local_connection]
688
        finally:
689
            close_session()
690
 
691
    def markOrdersAsDestinationCityReached(self, providerId, destination_city_reached_orders):
692
        """
693
        Mark all orders with AWBs in the given map as reached destination city. Also sets the reached destination timestamp.
694
 
695
        Parameters:
696
         - providerId
697
         - destination_city_reached_orders
698
        """
699
        try:
700
            mark_orders_as_destinationCityReached(providerId, destination_city_reached_orders)
701
        finally:
702
            close_session()
703
 
704
    def markOrdersAsFirstDeliveryAttempted(self, providerId, first_atdl_orders):
705
        """
706
        Mark all orders with AWBs in the given map as first delivery attempt made. Also sets the first delivery attempted timestamp.
707
 
708
        Parameters:
709
         - providerId
710
         - first_atdl_orders
711
        """
712
        try:
713
            mark_orders_as_firstDeliveryAttempted(providerId, first_atdl_orders)
714
        finally:
715
            close_session()
716
 
4783 phani.kuma 717
    def getUndeliveredOrdersExpectedDeliveryDateNotMet(self):
718
        """
719
        Returns the list of orders whose expected delivery date has passed but have not been
720
        delivered yet.
721
        Returns an empty list if no such orders exist.
722
        """
723
        try:
724
            orders_not_delivered = get_orders_not_met_expected_delivery_date()
725
            return [to_t_order(order) for order in orders_not_delivered]
726
        finally:
727
            close_session()
728
 
1405 ankur.sing 729
    def getUndeliveredOrders(self, providerId, warehouseId):
730
        """
731
        Returns the list of orders whose delivery time has passed but have not been
732
        delivered yet for the given provider and warehouse. To get a complete list of
733
        undelivered orders, pass them as -1.
734
        Returns an empty list if no such orders exist.
735
 
736
        Parameters:
737
         - providerId
738
         - warehouseId
739
        """
740
        try:
741
            undelivered_orders = get_undelivered_orders(providerId, warehouseId)
742
            return [to_t_order(order) for order in undelivered_orders]
743
        finally:
744
            close_session()
1351 varun.gupt 745
 
1398 varun.gupt 746
    def enqueueTransactionInfoEmail(self, transactionId):
1351 varun.gupt 747
        """
1398 varun.gupt 748
        Save the email containing order details to be sent to customer later by batch job
1351 varun.gupt 749
 
750
        Parameters:
751
         - transactionId
752
        """
753
        try:
1398 varun.gupt 754
            return enqueue_transaction_info_email(transactionId)
1351 varun.gupt 755
        finally:
756
            close_session()
757
 
4444 rajveer 758
    def getAlerts(self, type, warehouseId, status, timestamp):
483 rajveer 759
        """
760
        Parameters:
4394 rajveer 761
         - type
4444 rajveer 762
         - warehouseId
4394 rajveer 763
         - status
764
         - timestamp
483 rajveer 765
        """
766 rajveer 766
        try:
4444 rajveer 767
            alerts = get_alerts(type, warehouseId, status, timestamp)
766 rajveer 768
 
769
            t_alerts = []
770
            for alert in alerts:
771
                t_alerts.append(to_t_alert(alert)) 
772
 
773
            return t_alerts
774
        finally:
775
            close_session()
4394 rajveer 776
 
4447 rajveer 777
    def addAlert(self, type, warehouseId, description):
483 rajveer 778
        """
779
        Parameters:
780
         - type
4394 rajveer 781
         - description
4447 rajveer 782
         - warehouseId
483 rajveer 783
        """
766 rajveer 784
        try:
4447 rajveer 785
            add_alert(type, warehouseId, description)
766 rajveer 786
        finally:
787
            close_session()
1596 ankur.sing 788
 
4444 rajveer 789
    def markAlertsAsSeen(self, warehouseId):
790
        """
791
        Parameters:
792
         - warehouseId
793
        """
794
        try:
795
            mark_alerts_as_seen(warehouseId)
796
        finally:
797
            close_session()
798
        pass
799
 
1596 ankur.sing 800
    def getValidOrderCount(self, ):
801
        """
802
        Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
803
        """
1731 ankur.sing 804
        try:
805
            return get_valid_order_count()
806
        finally:
807
            close_session()
1627 ankur.sing 808
 
809
    def getNoOfCustomersWithSuccessfulTransaction(self, ):
810
        """
811
        Returns the number of distinct customers who have done successful transactions
812
        """
1731 ankur.sing 813
        try:
814
            return get_cust_count_with_successful_txn()
815
        finally:
816
            close_session()
1627 ankur.sing 817
 
1731 ankur.sing 818
 
819
    def getValidOrdersAmountRange(self, ):
1627 ankur.sing 820
        """
1731 ankur.sing 821
        Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
822
        List contains two values, first minimum amount and second maximum amount.
1627 ankur.sing 823
        """
1731 ankur.sing 824
        try:
825
            return get_valid_orders_amount_range()
826
        finally:
827
            close_session()
1627 ankur.sing 828
 
5874 rajveer 829
    def getValidOrders(self, limit, onlyStore):
1886 ankur.sing 830
        """
831
        Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
832
        If limit is passed as 0, then all valid Orders are returned.
833
 
834
        Parameters:
835
         - limit
5874 rajveer 836
         - onlyStore
1886 ankur.sing 837
        """
838
        try:
5874 rajveer 839
            return [to_t_order(order) for order in get_valid_orders(limit, onlyStore)]
1886 ankur.sing 840
        finally:
841
            close_session()
104 ashish 842
 
2536 chandransh 843
    def toggleDOAFlag(self, orderId):
104 ashish 844
        """
2536 chandransh 845
        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.
846
        Returns the final flag status.
847
        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 848
 
132 ashish 849
        Parameters:
2536 chandransh 850
         - orderId
132 ashish 851
        """
2536 chandransh 852
        try:
853
            return toggle_doa_flag(orderId)
854
        finally:
855
            close_session()
483 rajveer 856
 
4454 rajveer 857
    def markOrderDoaRequestReceived(self, orderId):
858
        """
859
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to DOA_REQUEST_RECEIVED
860
 
861
        Parameters:
862
         - orderId
863
        """
864
        try:
865
            return mark_order_doa_request_received(orderId)
866
        finally:
867
            close_session()
868
 
869
    def markOrderDoaRequestAuthorized(self, orderId, isAuthorized):
870
        """
871
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from DOA_REQUEST_RECEIVED
872
        to DOA_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
873
 
874
        Parameters:
875
         - orderId
876
         - isAuthorized
877
        """
878
        try:
879
            return mark_order_doa_request_authorized(orderId, isAuthorized)
880
        finally:
881
            close_session()
882
 
4488 rajveer 883
    def markOrderReturnRequestReceived(self, orderId):
884
        """
885
        Once user raise the request for a DOA, order status will be changed from DELVIERY_SUCCESS to RET_REQUEST_RECEIVED
886
 
887
        Parameters:
888
         - orderId
889
        """
890
        try:
891
            return mark_order_return_request_received(orderId)
892
        finally:
893
            close_session()
894
 
895
    def markOrderReturnRequestAuthorized(self, orderId, isAuthorized):
896
        """
897
        CRM person can authorize or deny the request reised by customer. If he authorizes order will change from RET_REQUEST_RECEIVED
898
        to RET_REQUEST_AUTHORIZED. If he denies, status will be changed back to DELVIERY_SUCCESS.
899
 
900
        Parameters:
901
         - orderId
902
         - isAuthorized
903
        """
904
        try:
905
            return mark_order_return_request_authorized(orderId, isAuthorized)
906
        finally:
907
            close_session()
908
 
4579 rajveer 909
    def requestPickupNumber(self, orderId, providerId):
104 ashish 910
        """
2536 chandransh 911
        Sends out an email to the account manager of the original courier provider used to ship the order.
4452 rajveer 912
        If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUEST_RAISED.
913
        If the order status was DOA_PICKUP_REQUEST_RAISED, it is left unchanged.
2536 chandransh 914
        For any other status, it returns false.
915
        Throws an exception if the order with the given id couldn't be found.
104 ashish 916
 
917
        Parameters:
2536 chandransh 918
         - orderId
104 ashish 919
        """
2536 chandransh 920
        try:
4579 rajveer 921
            return request_pickup_number(orderId, providerId)
2536 chandransh 922
        finally:
923
            close_session()
483 rajveer 924
 
4602 rajveer 925
    def authorizePickup(self, orderId, pickupNumber, providerId):
304 ashish 926
        """
4452 rajveer 927
        If the order status is DOA_PICKUP_REQUEST_RAISED, it does the following
2536 chandransh 928
            1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
929
            2. Changes order status to be DOA_PICKUP_AUTHORIZED.
930
            3. Returns true
931
        If the order is any other status, it returns false.
932
        Throws an exception if the order with the given id couldn't be found.
304 ashish 933
 
934
        Parameters:
2536 chandransh 935
         - orderId
936
         - pickupNumber
304 ashish 937
        """
2536 chandransh 938
        try:
4602 rajveer 939
            return authorize_pickup(orderId, pickupNumber, providerId)
2536 chandransh 940
        finally:
941
            close_session()    
2764 chandransh 942
 
943
    def markDoasAsPickedUp(self, providerId, pickupDetails):
944
        """
945
        Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
946
 
947
        Parameters:
948
         - providerId
949
         - pickupDetails
950
        """
951
        try:
4910 phani.kuma 952
            mark_doas_as_picked_up(providerId, pickupDetails)
953
        finally:
954
            close_session()
955
 
956
    def getDoasNotPickedUp(self, providerId):
957
        """
958
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
959
 
960
        Parameters:
961
         - providerId
962
        """
963
        try:
964
            orders_not_picked_up = get_doas_not_picked_up(providerId)
2764 chandransh 965
            return [to_t_order(order) for order in orders_not_picked_up]
966
        finally:
967
            close_session()
4910 phani.kuma 968
 
4741 phani.kuma 969
    def markReturnOrdersAsPickedUp(self, providerId, pickupDetails):
970
        """
971
        Marks all RET_PICKUP_CONFIRMED orders of the previous day for a provider as RET_RETURN_IN_TRANSIT.
972
 
973
        Parameters:
974
         - providerId
975
         - pickupDetails
976
        """
977
        try:
4910 phani.kuma 978
            mark_return_orders_as_picked_up(providerId, pickupDetails)
979
        finally:
980
            close_session()
981
 
982
    def getReturnOrdersNotPickedUp(self, providerId):
983
        """
984
        Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
985
 
986
        Parameters:
987
         - providerId
988
        """
989
        try:
990
            orders_not_picked_up = get_return_orders_not_picked_up(providerId)
4741 phani.kuma 991
            return [to_t_order(order) for order in orders_not_picked_up]
992
        finally:
993
            close_session()
4910 phani.kuma 994
 
4479 rajveer 995
    def receiveReturn(self, orderId, receiveCondition):
2591 chandransh 996
        """
4452 rajveer 997
        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 998
        If the order is in any other state, it returns false.
999
        Throws an exception if the order with the given id couldn't be found.
1000
 
1001
        Parameters:
1002
         - orderId
1003
        """
1004
        try:
4479 rajveer 1005
            return receive_return(orderId, receiveCondition)
2591 chandransh 1006
        finally:
1007
            close_session()
1008
 
1009
    def validateDoa(self, orderId, isValid):
1010
        """
4452 rajveer 1011
        Used to validate the DOA certificate for an order in the DOA_RECEIVED_PRESTINE state. If the certificate is valid,
2609 chandransh 1012
        the order state is changed to DOA_CERT_PENDING.
2591 chandransh 1013
        If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
1014
        If the order is in any other state, it returns false.
1015
        Throws an exception if the order with the given id couldn't be found.
1016
 
1017
        Parameters:
1018
         - orderId
1019
         - isValid
1020
        """
1021
        try:
1022
            return validate_doa(orderId, isValid)
1023
        finally:
1024
            close_session()
2628 chandransh 1025
 
4495 rajveer 1026
    def validateReturnProduct(self, orderId, isUsable):
1027
        """
1028
        Parameters:
1029
         - orderId
1030
         - isUsable
1031
        """
1032
        try:
1033
            return validate_return_product(orderId, isUsable)
1034
        finally:
1035
            close_session()
1036
 
2628 chandransh 1037
    def reshipOrder(self, orderId):
1038
        """
4484 rajveer 1039
        If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1040
            1. Creates a new order for processing in the BILLED state. All billing information is saved.
4484 rajveer 1041
            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 1042
 
1043
        If the order is in DOA_CERT_VALID state, it does the following:
1044
            1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
1045
            2. Creates a return order for the warehouse executive to return the DOA material.
4452 rajveer 1046
            3. Marks the current order as the final DOA_VALID_RESHIPPED state.
2628 chandransh 1047
 
1048
        Returns the id of the newly created order.
1049
 
1050
        Throws an exception if the order with the given id couldn't be found.
1051
 
1052
        Parameters:
1053
         - orderId
1054
        """
1055
        try:
1056
            return reship_order(orderId)
1057
        finally:
1058
            close_session()
1059
 
3226 chandransh 1060
    def refundOrder(self, orderId, refundedBy, reason):
2628 chandransh 1061
        """
4484 rajveer 1062
        If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
2628 chandransh 1063
            1. Creates a refund request for batch processing.
1064
            2. Creates a return order for the warehouse executive to return the shipped material.
4484 rajveer 1065
            3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
2628 chandransh 1066
 
1067
        If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1068
            1. Creates a refund request for batch processing.
3226 chandransh 1069
            2. Cancels the reservation of the item in the warehouse.
1070
            3. Marks the current order as the REFUNDED final state.
2628 chandransh 1071
 
3226 chandransh 1072
        For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
1073
            1. Cancels the reservation of the item in the warehouse.
1074
            2. Marks the current order as CANCELED.
1075
 
1076
        In all cases, it updates the reason for cancellation or refund and the person who performed the action.
1077
 
2628 chandransh 1078
        Returns True if it is successful, False otherwise.
1079
 
1080
        Throws an exception if the order with the given id couldn't be found.
1081
 
1082
        Parameters:
1083
         - orderId
3226 chandransh 1084
         - refundedBy
1085
         - reason
2628 chandransh 1086
        """
1087
        try:
3226 chandransh 1088
            return refund_order(orderId, refundedBy, reason)
2628 chandransh 1089
        finally:
1090
            close_session()
1091
 
2697 chandransh 1092
    def getReturnOrders(self, warehouseId, fromDate, toDate):
1093
        """
1094
        Get all return orders created between the from and to dates for the given warehouse.
1095
        Ignores the warehouse if it is passed as -1.
1096
 
1097
        Parameters:
1098
         - warehouseId
1099
         - fromDate
1100
         - toDate
1101
        """
1102
        try:
1103
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1104
            return get_return_orders(warehouseId, from_date, to_date)
1105
        finally:
1106
            close_session()
1107
 
5481 phani.kuma 1108
    def getAllReturnOrders(self, onlyNotProcessed, fromDate, toDate):
1109
        """
1110
        Get all return orders created between the from and to dates for the given warehouse.
1111
        Ignores the warehouse if it is passed as -1.
1112
 
1113
        Parameters:
1114
         - warehouseId
1115
         - fromDate
1116
         - toDate
1117
        """
1118
        try:
1119
            from_date, to_date = get_fdate_tdate(fromDate, toDate)
1120
            return get_all_return_orders(onlyNotProcessed, from_date, to_date)
1121
        finally:
1122
            close_session()
1123
 
2700 chandransh 1124
    def getReturnOrder(self, id):
1125
        """
1126
        Returns the ReturnOrder corresponding to the given id.
1127
        Throws an exception if the return order with the given id couldn't be found.
1128
 
1129
        Parameters:
1130
         - id
1131
        """
1132
        try:
1133
            return get_return_order(id)
1134
        finally:
1135
            close_session()
1136
 
2697 chandransh 1137
    def processReturn(self, returnOrderId):
1138
        """
1139
        Marks the return order with the given id as processed. Raises an exception if no such return order exists.
1140
 
1141
        Parameters:
1142
         - returnOrderId
1143
        """
1144
        try:
1145
            process_return(returnOrderId)
1146
        finally:
1147
            close_session()
4757 mandeep.dh 1148
 
1149
    def updateOrdersAsPORaised(self, itemIdQuantityMap, purchaseOrderId, warehouseId):
2819 chandransh 1150
        """
4757 mandeep.dh 1151
        Updates orders as PO raised. Also updates purchase order id in orders. Pass a map of items mapped to
1152
        the quantities for which the PO is raised.
1153
 
2819 chandransh 1154
        Parameters:
4757 mandeep.dh 1155
         - itemIdQuantityMap
1156
         - purchaseOrderId
2819 chandransh 1157
         - warehouseId
1158
        """
1159
        try:
4757 mandeep.dh 1160
            update_orders_as_PORaised(itemIdQuantityMap, purchaseOrderId, warehouseId)
2819 chandransh 1161
        finally:
1162
            close_session()
4757 mandeep.dh 1163
 
3451 chandransh 1164
    def updateWeight(self, orderId, weight):
1165
        """
1166
        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.
1167
 
1168
        Parameters:
1169
         - orderId
1170
         - weight
1171
        """
1172
        try:
1173
            order = update_weight(orderId, weight)
1174
            return to_t_order(order)
1175
        finally:
1176
            close_session()
1177
 
3469 chandransh 1178
    def changeItem(self, orderId, itemId):
1179
        """
1180
        Change the item to be shipped for this order. Also adjusts the reservation in the inventory accordingly.
1181
        Currently, it also ensures that only a different color of the given item is shipped.
1182
 
1183
        Parameters:
1184
         - orderId
1185
         - itemId
1186
        """
1187
        try:
1188
            order = change_product(orderId, itemId)
1189
            return to_t_order(order)
1190
        finally:
1191
            close_session()
1192
 
1193
    def shiftToWarehouse(self, orderId, warehouseId):
1194
        """
1195
        Moves the given order to the given warehouse. Also adjusts the inventory reservations accordingly.
1196
 
1197
        Parameters:
1198
         - orderId
1199
         - warehouseId
1200
        """
1201
        try:
1202
            order = change_warehouse(orderId, warehouseId)
1203
            return to_t_order(order)
1204
        finally:
1205
            close_session()
3553 chandransh 1206
 
4647 rajveer 1207
    def addDelayReason(self, orderId, delayReason, furtherDelay, delayReasonText):
3553 chandransh 1208
        """
1209
        Adds the given delay reason to the given order.
3986 chandransh 1210
        Increases the expected delivery time of the given order by the given no. of days.
3553 chandransh 1211
        Raises an exception if no order with the given id can be found.
3469 chandransh 1212
 
3553 chandransh 1213
        Parameters:
1214
         - orderId
1215
         - delayReason
1216
        """
1217
        try:
4647 rajveer 1218
            return add_delay_reason(orderId, delayReason, furtherDelay, delayReasonText)
3553 chandransh 1219
        finally:
1220
            close_session()
1221
 
3956 chandransh 1222
    def reconcileCodCollection(self, collectedAmountMap, xferBy, xferTxnId, xferDate):
1223
        """
1224
        Marks the COD orders with given AWB nos. as having been processed.
1225
        Updates the captured amount for the corresponding payment.
1226
 
1227
        Returns a map of AWBs which were not processed and the associated reason. An AWB is not processed if:
1228
        1. There is no order corresponding to an AWB number.
1229
        2. The captured amount for a payment exceeds the total payment.
1230
        3. The order corresponding to an AWB no. is in a state prior to DELIVERY_SUCCESS.
1231
 
1232
        Parameters:
1233
         - collectedAmountMap
1234
         - xferBy
1235
         - xferTxnId
1236
         - xferDate
1237
        """
1238
        try:
1239
            return reconcile_cod_collection(collectedAmountMap, xferBy, xferTxnId, xferDate)
1240
        finally:
1241
            close_session()
4008 mandeep.dh 1242
 
1243
    def getTransactionsRequiringExtraProcessing(self, category):
1244
        """
1245
        Returns the list of transactions that require some extra processing and
1246
        which belong to a particular category. This is currently used by CRM
1247
        application.
1248
        """
1249
        try:
1250
            return get_transactions_requiring_extra_processing(category)
1251
        finally:
1252
            close_session()
1253
 
1254
    def markTransactionAsProcessed(self, transactionId, category):
1255
        """
1256
        Marks a particular transaction as processed for a particular category.
1257
        It essentially deletes the transaction if it is processed for a particular
1258
        category. This is currently used by CRM application.
1259
        """
1260
        try:
1261
            return mark_transaction_as_processed(transactionId, category)
1262
        finally:
1263
            close_session()
4018 chandransh 1264
 
1265
    def getItemWiseRiskyOrdersCount(self, ):
1266
        """
1267
        Returns a map containing the number of risky orders keyed by item id. A risky order
1268
        is defined as one whose shipping date is about to expire.
1269
        """
1270
        try:
1271
            return get_item_wise_risky_orders_count()
1272
        finally:
1273
            close_session()
3956 chandransh 1274
 
4247 rajveer 1275
    def markOrderCancellationRequestReceived(self, orderId):
1276
        """
1277
        Mark order as cancellation request received. If customer sends request of cancellation of
1278
        a particular order, this method will be called. It will just change status of the order
1279
        depending on its current status. It also records the previous status, so that we can move
1280
        back to that status if cancellation request is denied.
1281
 
1282
        Parameters:
1283
         - orderId
1284
        """
1285
        try:
1286
            return mark_order_cancellation_request_received(orderId)
1287
        finally:
1288
            close_session()
1289
 
1290
 
4662 rajveer 1291
    def markOrderAsLostInTransit(self, orderId):
1292
        """
1293
        Parameters:
1294
         - orderId
1295
        """
1296
        try:
1297
            return mark_order_as_lost_in_transit(orderId)
1298
        finally:
1299
            close_session()
1300
 
4258 rajveer 1301
    def markTransactionAsPaymentFlagRemoved(self, transactionId):
4247 rajveer 1302
        """
4258 rajveer 1303
        If we and/or payment gateway has decided to accept the payment, this method needs to be called.
1304
        Changed transaction and all orders status to payment accepted.
4247 rajveer 1305
 
1306
        Parameters:
4258 rajveer 1307
         - transactionId
4247 rajveer 1308
        """
1309
        try:
4259 anupam.sin 1310
            return mark_transaction_as_payment_flag_removed(transactionId)
4247 rajveer 1311
        finally:
1312
            close_session()
4259 anupam.sin 1313
 
1314
    def refundTransaction(self, transactionId, refundedBy, reason):
1315
        """
1316
        This method is called when a flagged payment is deemed unserviceable and the corresponding orders
1317
        need to be cancelled
1318
 
1319
        Parameters:
1320
         - transactionId
1321
        """
1322
        try:
1323
            return refund_transaction(transactionId, refundedBy, reason)
1324
        finally:
1325
            close_session()
4247 rajveer 1326
 
1327
    def markOrderCancellationRequestDenied(self, orderId):
1328
        """
1329
        If we decide to not to cancel order, we will move the order ro previous status.
1330
 
1331
        Parameters:
1332
         - orderId
1333
        """
1334
        try:
1335
            return mark_order_cancellation_request_denied(orderId)
1336
        finally:
1337
            close_session()
1338
 
1339
    def markOrderCancellationRequestConfirmed(self, orderId):
1340
        """
1341
        If we decide to to cancel order, CRM will call this method to move the status of order to
1342
        cancellation request confirmed. After this OM will be able to cancel the order.
1343
 
1344
        Parameters:
1345
         - orderId
1346
        """
1347
        try:
1348
            return mark_order_cancellation_request_confirmed(orderId)
1349
        finally:
1350
            close_session()
1351
 
4324 mandeep.dh 1352
    def updateShipmentAddress(self, orderId, addressId):
1353
        """
1354
        Updates shipment address of an order. Delivery and shipping date estimates
1355
        etc. are also updated here.
1356
 
1357
        Throws TransactionServiceException in case address change is not
1358
        possible due to certain reasons such as new pincode in address is
1359
        not serviceable etc.
1360
 
1361
        Parameters:
1362
         - orderId
1363
         - addressId
1364
        """
1365
        try:
1366
            update_shipment_address(orderId, addressId)
1367
        finally:
1368
            close_session()
1369
 
4285 rajveer 1370
    def acceptOrdersForItemId(self, itemId, inventory):
1371
        """
1372
        Marks the orders as ACCEPTED for the given itemId and inventory. It also updates the accepted timestamp. If the
1373
        given order is not a COD order, it also captures the payment if the same has not been captured.
1374
 
1375
        Parameters:
1376
         - itemId
1377
         - inventory
1378
        """
1379
        try:
1380
            return accept_orders_for_item_id(itemId, inventory)
1381
        finally:
1382
            close_session()
1383
 
4303 rajveer 1384
 
1385
 
4369 rajveer 1386
    def markOrdersAsPORaised(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1387
        """
1388
        Parameters:
1389
         - vendorId
1390
         - itemId
1391
         - quantity
1392
         - estimate
4369 rajveer 1393
         - isReminder
4303 rajveer 1394
        """
1395
        try:
4369 rajveer 1396
            return mark_orders_as_po_raised(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1397
        finally:
1398
            close_session()
1399
 
4369 rajveer 1400
    def markOrdersAsReversalInitiated(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1401
        """
1402
        Parameters:
1403
         - vendorId
1404
         - itemId
1405
         - quantity
1406
         - estimate
4369 rajveer 1407
         - isReminder
4303 rajveer 1408
        """
1409
        try:
4369 rajveer 1410
            return mark_orders_as_reversal_initiated(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1411
        finally:
1412
            close_session()
1413
 
4369 rajveer 1414
    def markOrdersAsNotAvailabke(self, vendorId, itemId, quantity, estimate, isReminder):
4303 rajveer 1415
        """
1416
        Parameters:
1417
         - vendorId
1418
         - itemId
1419
         - quantity
1420
         - estimate
4369 rajveer 1421
         - isReminder
4303 rajveer 1422
        """
1423
        try:
4369 rajveer 1424
            return mark_orders_as_not_available(vendorId, itemId, quantity, estimate, isReminder)
4303 rajveer 1425
        finally:
1426
            close_session()
1427
 
1428
 
4369 rajveer 1429
    def markOrdersAsTimeout(self, vendorId):
1430
        """
1431
        Parameters:
1432
         - vendorId
1433
        """
1434
        try:
1435
            return mark_orders_as_timeout(vendorId)
1436
        finally:
1437
            close_session()
4386 anupam.sin 1438
 
1439
    def getOrderForAwb(self, awb):
1440
        """
1441
        Parameters:
1442
         - AirwayBill Number
1443
        """
1444
        try:
1445
            return to_t_order(get_order_for_awb(awb))
1446
        finally:
1447
            close_session()
4369 rajveer 1448
 
4910 phani.kuma 1449
    def getOrdersForProviderForStatus(self, provider_id, order_status_list):
4506 phani.kuma 1450
        """
1451
        Parameters:
1452
         - provider id
1453
         - order status
1454
        """
1455
        try:
4910 phani.kuma 1456
            orders_of_provider_by_status = get_orders_for_provider_for_status(provider_id, order_status_list)
4506 phani.kuma 1457
            return [to_t_order(order) for order in orders_of_provider_by_status if order != None]
1458
        finally:
1459
            close_session()
4600 varun.gupt 1460
 
1461
    def getBilledOrdersForVendor(self, vendorId, billingDateFrom, billingDateTo):
1462
        '''
1463
        Parameters:
1464
         - vendorId
1465
         - billingDateFrom
1466
         - billingDateTo
1467
        '''
1468
        try:
1469
            return [to_t_order(order) for order in get_billed_orders_for_vendor(vendorId, to_py_date(billingDateFrom), to_py_date(billingDateTo))]
1470
        finally:
1471
            close_session()
1472
 
4607 rajveer 1473
    def getSlippedSippingDateOrders(self):
1474
        try:
1475
            return [to_t_order(order) for order in get_slipped_sipping_date_orders()]
1476
        finally:
1477
            close_session()
1478
 
4709 rajveer 1479
    def getCancelledOrders(self, cancelDateFrom, cancelDateTo):
1480
        try:
1481
            return [to_t_order(order) for order in get_cancelled_orders(to_py_date(cancelDateFrom), to_py_date(cancelDateTo))]
1482
        finally:
1483
            close_session()
1484
 
4600 varun.gupt 1485
    def getEBSSettlementSummaries(self):
1486
        try:
1487
            return get_ebs_settlement_summaries()
1488
        finally:
1489
            close_session()
4369 rajveer 1490
 
4600 varun.gupt 1491
    def saveEBSSettlementSummary(self, settlementId, settlementDate, transactionDateFrom, transactionDateTo, amount):
1492
        try:
1493
            save_ebs_settlement_summary(settlementId, to_py_date(settlementDate), to_py_date(transactionDateFrom), to_py_date(transactionDateTo), amount)
1494
        finally:
1495
            close_session()
1496
 
5386 phani.kuma 1497
    def getSettlementForPrepaid(self, referenceId, isRefund):
4600 varun.gupt 1498
        '''
1499
        Parameters:
5189 varun.gupt 1500
         - referenceId
1501
         - isRefund
4600 varun.gupt 1502
        '''
1503
        try:
5386 phani.kuma 1504
            return to_t_payment_settlement(get_settlement_for_Prepaid(referenceId, isRefund))
4600 varun.gupt 1505
        finally:
1506
            close_session()
5386 phani.kuma 1507
 
1508
    def getSettlementForCod(self, orderId, isRefund):
1509
        '''
1510
        Parameters:
1511
         - orderId
1512
         - isRefund
1513
        '''
1514
        try:
1515
            return to_t_payment_settlement(get_settlement_for_Cod(orderId, isRefund))
1516
        finally:
1517
            close_session()
1518
 
4600 varun.gupt 1519
    def getEBSSettlementDate(self, settlementId):
1520
        try:
1521
            return to_java_date(get_ebs_settlement_date(settlementId))
1522
        finally:
1523
            close_session()
1524
 
4905 varun.gupt 1525
    def savePaymentSettlements(self, settlementDate, paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection):
4600 varun.gupt 1526
        try:
4905 varun.gupt 1527
            save_payment_settlements(to_py_date(settlementDate), paymentGatewayId, referenceId, serviceTax, otherCharges, netCollection)
4600 varun.gupt 1528
        finally:
1529
            close_session()
1530
 
1531
    def markEBSSettlementUploaded(self, settlementId):
1532
        try:
1533
            mark_ebs_settlement_uploaded(settlementId)
1534
        finally:
1535
            close_session()
1536
 
4715 varun.gupt 1537
    def getSettlementsByDate(self, settlementDateFrom, settlementDateTo, isRefund):
1538
        try:
1539
            settlements = get_settlements_by_date(to_py_date(settlementDateFrom), to_py_date(settlementDateTo), isRefund)
1540
            return [to_t_payment_settlement(settlement) for settlement in settlements]
1541
        finally:
1542
            close_session()
1543
 
1544
    def getReshippedOrderIds(self, orderIds):
1545
        try:
1546
            return get_reshipped_order_ids(orderIds)
1547
        finally:
1548
            close_session()
1549
 
5481 phani.kuma 1550
    def getBilledOrders(self, vendorId, onlyVendorNotPaid, billingDateFrom, billingDateTo):
4875 varun.gupt 1551
        try:
5481 phani.kuma 1552
            from_date, to_date = get_fdate_tdate(billingDateFrom, billingDateTo)
1553
            return [to_t_order(order) for order in get_billed_orders(vendorId, onlyVendorNotPaid, from_date, to_date)]
4875 varun.gupt 1554
        finally:
1555
            close_session()
1556
 
5062 varun.gupt 1557
    def getStatusDistributionOfOrders(self, startDate, endDate):
1558
        try:
5067 varun.gupt 1559
            distribution = {}
1560
 
1561
            for status, count in get_order_distribution_by_status(to_py_date(startDate), to_py_date(endDate)):
1562
                distribution[status] = count
1563
 
1564
            return distribution
5062 varun.gupt 1565
        finally:
1566
            close_session()
1567
 
5067 varun.gupt 1568
    def getOrderIdsForStatus(self, status, startDatetime, endDatetime):
1569
        try:
1570
            orders = get_order_ids_for_status(status, to_py_date(startDatetime), to_py_date(endDatetime))
1571
            return [order.id for order in orders]
1572
        finally:
1573
            close_session()
1574
 
5099 varun.gupt 1575
    def updateOrderAsPaidToVendor(self, orderId):
1576
        try:
1577
            update_orders_as_paid_to_vendor(orderId)
1578
        finally:
1579
            close_session()
1580
 
5348 anupam.sin 1581
    def updateCODAgent(self, agentEmailId, orderId):
1582
        try:
1583
            update_COD_agent(agentEmailId, orderId)
1584
        finally:
1585
            close_session()
1586
 
5386 phani.kuma 1587
    def updateOrderOnlyAsPaidToVendor(self, orderId):
1588
        try:
1589
            update_order_only_as_paid_to_vendor(orderId)
1590
        finally:
1591
            close_session()
1592
 
5208 varun.gupt 1593
    def getRefundedOrdersMarkedPaid(self):
1594
        try:
1595
            return [to_t_order(order) for order in get_refunded_orders_marked_paid()]
1596
        finally:
1597
            close_session()
5447 anupam.sin 1598
 
1599
    def getAllVerificationAgents(self, minOrderId, maxOrderId):
1600
        try:
1601
            return [to_t_verification_agent(codAgent) for codAgent in get_all_verification_agents(minOrderId, maxOrderId)]
1602
        finally:
5527 anupam.sin 1603
            close_session()
1604
 
1605
    def getAllAttributesForOrderId(self, orderId):
1606
        try:
1607
            return [to_t_attribute(attribute) for attribute in get_all_attributes_for_order_id(orderId)]
1608
        finally:
1609
            close_session()
1610
 
1611
    def setOrderAttributeForTransaction(self, transactionId, attribute):
1612
        try:
1613
            set_order_attribute_for_transaction(transactionId, attribute)                    
1614
        finally:
1615
            close_session()
5593 mandeep.dh 1616
 
1617
    def acceptOrderForItem(self, itemId, quantity, fulfilmentWarehouseId, billingWarehouseId):
1618
        """
1619
        Accepts appropriate order for an item in a given billingWarehouse. Usually
1620
        invoked while scanning IN of items.
1621
 
1622
        Parameters:
1623
         - itemId
1624
         - quantity
1625
         - fulfilmentWarehouseId
1626
         - billingWarehouseId
1627
        """
1628
        try:
1629
            accept_order_for_item(itemId, quantity, fulfilmentWarehouseId, billingWarehouseId)
1630
        finally:
1631
            close_session()
1632
 
5833 rajveer 1633
    def getOrderAttributeValue(self, orderId, attributeName):
1634
        """
1635
        Parameters:
1636
         - orderId
1637
         - attributeName
1638
        """
1639
        try:
6019 rajveer 1640
            return get_order_attribute_value(orderId, attributeName)
5833 rajveer 1641
        finally:
1642
            close_session()
1643
 
6019 rajveer 1644
    def changeJacketNumber(self, orderId, jacketNumber):
1645
        """
1646
        Parameters:
1647
         - orderId
1648
         - jacketNumber
1649
        """
1650
        try:
1651
            return change_jacket_number(orderId, jacketNumber)
1652
        finally:
1653
            close_session()
1654
 
1655
    def markOrderAsRtoInTransit(self, orderId):
1656
        """
1657
        Parameters:
1658
         - orderId
1659
        """
1660
        try:
1661
            return mark_order_as_rto_in_transit(orderId)
1662
        finally:
1663
            close_session()        
1664
 
6000 mandeep.dh 1665
    def createRechargeOrder(self, thriftRechargeOrder):
1666
        """
1667
        Parameters:
1668
         - thriftRechargeOrder
1669
        """
6031 rajveer 1670
        try:
1671
            if thriftRechargeOrder is None or thriftRechargeOrder.rechargeType is None:
1672
                raise TransactionServiceException(102, 'Order or the type is Null')
1673
 
1674
            rechargeOrder = None
1675
            if thriftRechargeOrder.rechargeType == RechargeType.MOBILE:
1676
                rechargeOrder = MobileRechargeOrder()
1677
            elif thriftRechargeOrder.rechargeType == RechargeType.DTH:
1678
                rechargeOrder = DTHRechargeOrder()
1679
 
1680
            if rechargeOrder is None:
1681
                raise TransactionServiceException(102, 'Unsupported recharge type')
6000 mandeep.dh 1682
 
6031 rajveer 1683
            transaction = DigitalTransaction()
1684
            transaction.createdOn = datetime.datetime.now()
6056 amit.gupta 1685
            transaction.userId = thriftRechargeOrder.userId
6031 rajveer 1686
            transaction.orders = [rechargeOrder]
1687
 
6000 mandeep.dh 1688
            rechargeOrder.from_thrift_object(thriftRechargeOrder)
1689
            session.commit()
6031 rajveer 1690
            return rechargeOrder.to_thrift_object()
6000 mandeep.dh 1691
        except:
1692
            raise TransactionServiceException(103, 'Invalid values passed')
1693
        finally:
1694
            self.closeSession()
1695
 
6031 rajveer 1696
    def getRechargeOrder(self, rechargeOrderId):
1697
        """
1698
        Parameters:
1699
         - rechargeOrderId
1700
        """
1701
        try:
6048 rajveer 1702
            return get_recharge_order(rechargeOrderId).to_thrift_object()
6031 rajveer 1703
        finally:
1704
            self.closeSession()
1705
 
1706
    def getRechargeOrders(self, userId):
1707
        """
1708
        Parameters:
1709
         - userId
1710
        """
1711
        try:
1712
            return [order.to_thrift_object() for order in get_recharge_orders(userId)]
1713
        finally:
1714
            self.closeSession()
1715
 
6000 mandeep.dh 1716
    def updateRechargeOrderStatus(self, rechargeOrderId, rechargeOrderStatus):
1717
        """
1718
        Parameters:
1719
         - rechargeOrderId
1720
         - rechargeOrderStatus
1721
        """
6031 rajveer 1722
        try:
1723
            return update_recharge_order_status(rechargeOrderId, rechargeOrderStatus)
1724
        finally:
1725
            self.closeSession()
1726
 
1727
    def activateRechargeTxn(self, rechargeOrderId):
6000 mandeep.dh 1728
        """
1729
        Parameters:
6031 rajveer 1730
         - rechargeOrderId
6000 mandeep.dh 1731
        """
6031 rajveer 1732
        try:
1733
            return True
1734
            activate_recharge_txn(rechargeOrderId)
1735
        finally:
1736
            self.closeSession()
6000 mandeep.dh 1737
 
6031 rajveer 1738
    def getUserWallet(self, userId):
6000 mandeep.dh 1739
        """
1740
        Parameters:
6031 rajveer 1741
         - userId
6000 mandeep.dh 1742
        """
6031 rajveer 1743
        try:
1744
            return get_user_wallet(userId).to_thrift_object()
1745
        finally:
1746
            self.closeSession()
6000 mandeep.dh 1747
 
6031 rajveer 1748
    def getUserWalletHistory(self, userId):
6000 mandeep.dh 1749
        """
1750
        Parameters:
6031 rajveer 1751
         - userId
6000 mandeep.dh 1752
        """
6031 rajveer 1753
        try:
1754
            return [wallet.to_thrift_object() for wallet in get_user_wallet_history(userId)]
1755
        finally:
1756
            self.closeSession()
6000 mandeep.dh 1757
 
6206 rajveer 1758
    def getServiceProviders(self, rechargeType, onlyActive):
6048 rajveer 1759
        """
1760
        Parameters:
1761
         - rechargeType
6206 rajveer 1762
         - onlyActive
6048 rajveer 1763
        """
6077 anupam.sin 1764
 
6048 rajveer 1765
        try:
6206 rajveer 1766
            return get_service_providers(rechargeType, onlyActive)
6048 rajveer 1767
        finally:
1768
            self.closeSession()
1769
 
6049 rajveer 1770
    def getServiceProviderForDevice(self, rechargeType, deviceNumber):
6048 rajveer 1771
        """
1772
        Parameters:
1773
         - deviceNumber
1774
        """
1775
        try:
6049 rajveer 1776
            return get_service_provider_for_device(rechargeType, deviceNumber)
6048 rajveer 1777
        finally:
1778
            self.closeSession()
6056 amit.gupta 1779
 
6591 anupam.sin 1780
    def validateRecharge(self, rechargeType, deviceNumber, userSelectedProviderId, clientAddress):
6269 rajveer 1781
        """
1782
        Parameters:
1783
         - deviceNumber
1784
        """
1785
        try:
6591 anupam.sin 1786
            return validate_recharge(rechargeType, deviceNumber, userSelectedProviderId, clientAddress)
6269 rajveer 1787
        finally:
1788
            self.closeSession()
1789
 
6056 amit.gupta 1790
    def getRechargeOrdersForTransaction(self, txId):
1791
        """
1792
        Parameters:
1793
         - transactionId
1794
        """
1795
        try:
1796
            return get_recharge_orders_for_transaction(txId).to_thrift_object()
1797
        finally:
1798
            self.closeSession()
6048 rajveer 1799
 
6094 rajveer 1800
    def getRechargeOrdersForDevice(self, deviceNumber):
1801
        """
1802
        Parameters:
1803
        - deviceNumber
1804
        """
1805
        try:
1806
            return [order.to_thrift_object() for order in get_recharge_orders_for_device(deviceNumber)]
1807
        finally:
1808
            self.closeSession()
1809
 
6154 rajveer 1810
    def getRechargeOrdersForStatus(self, status):
1811
        """
1812
        Parameters:
1813
        - status
1814
        """
1815
        try:
1816
            return [order.to_thrift_object() for order in get_recharge_orders_for_status(status)]
1817
        finally:
1818
            self.closeSession()
1819
 
6159 rajveer 1820
    def getPlansForOperator(self, operatorId):
1821
        """
1822
        Parameters:
1823
        - operatorId
1824
        """
1825
        try:
1826
            return [plan.to_thrift_object() for plan in get_plans_for_operator(operatorId)]
1827
        finally:
1828
            self.closeSession()
1829
 
1830
 
6094 rajveer 1831
    def addAmountToWallet(self, userId, orderId, amount):
1832
        """
1833
        Parameters:
1834
        - userId
1835
        - orderId
1836
        - amount
1837
        """
1838
        try:
1839
            update_amount_in_wallet(userId, amount, orderId)
1840
        finally:
1841
            self.closeSession()
1842
 
6188 rajveer 1843
    def getRechargeStatistics(self):
1844
        """
1845
        Parameters:
1846
        """
1847
        try:
1848
            return get_recharge_statistics()
1849
        finally:
1850
            self.closeSession()
1851
 
6307 anupam.sin 1852
    def getRechargeDenominations(self, operatorId, circleCode, denominationType):
6289 anupam.sin 1853
        try:
1854
            returnList = []
6307 anupam.sin 1855
            rechargeDenominations = get_recharge_denominations(operatorId, circleCode, denominationType)
6289 anupam.sin 1856
            for rechargeDenomination in rechargeDenominations:
1857
                returnList.append(rechargeDenomination.to_thrift_object())
1858
            return returnList
1859
        finally:
1860
            self.closeSession() 
6188 rajveer 1861
 
6371 rajveer 1862
    def updateAvailabilityStatus(self, operatorId, circleId, isAvailable):
1863
        try:
1864
            update_availability_status(operatorId, circleId, isAvailable)
1865
        finally:
1866
            self.closeSession() 
1867
 
6396 amit.gupta 1868
    def getAvailableEmiSchemes(self):
1869
        try:
1870
            return get_available_emi_schemes()
1871
        finally:
1872
            self.closeSession()
1873
 
6389 rajveer 1874
    def getMiscCharges(self, transactionId):
1875
        try:
1876
            return get_misc_charges(transactionId)
1877
        finally:
1878
            self.closeSession()
1879
 
6507 anupam.sin 1880
    def refundRechargeOrder (self, rechargeOrderId):
1881
        try:
1882
            return refund_recharge_order(rechargeOrderId)
1883
        finally:
1884
            self.closeSession()
6821 amar.kumar 1885
 
1886
    def getPhysicalOrders(self, start_date, end_date):
1887
        try:
6832 amar.kumar 1888
            return [to_t_order(order) for order in get_physical_orders(to_py_date(start_date), to_py_date(end_date))]
6821 amar.kumar 1889
        finally:
1890
            self.closeSession()
6507 anupam.sin 1891
 
6906 rajveer 1892
    def getDocument(self, docType, docSource):
1893
        try:
1894
            return get_document(docType, docSource)
1895
        finally:
1896
            self.closeSession()
6988 rajveer 1897
 
7075 rajveer 1898
    def retrieveInvoice(self, orderId, userId):
6988 rajveer 1899
        try:
7075 rajveer 1900
            return retrieve_invoice(orderId,userId)
6988 rajveer 1901
        finally:
1902
            self.closeSession()
6906 rajveer 1903
 
7027 rajveer 1904
    def receiveUpdatesForRedExpress(self, awbNumber):
1905
        try:
7032 rajveer 1906
            return RedExpressUpdateService.get_updates_for_user(awbNumber)
7027 rajveer 1907
        finally:
1908
            self.closeSession()
1909
 
6985 anupam.sin 1910
    def changeShippingAddress(self, orderId, line1, line2, city, state, pin):
1911
        try:
1912
            return change_shipping_address(orderId, line1, line2, city, state, pin)
1913
        finally:
1914
            self.closeSession()
1915
 
7073 anupam.sin 1916
    def createRechargeTransaction(self, t_rechargeTransaction):
1917
        try:
1918
            return to_t_rechargeTransaction(create_recharge_transaction(t_rechargeTransaction))
1919
        finally:
1920
            self.closeSession()
7084 rajveer 1921
 
1922
    def getRechargeTransactions(self, storeId):
1923
        try:
1924
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_transactions(storeId)]
1925
        finally:
1926
            self.closeSession()
1927
 
7151 amit.gupta 1928
    def getRechargeTrans(self, storeId, startdate, enddate, status):
1929
        try:
1930
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_trans(storeId,startdate, enddate, status)]
1931
        finally:
1932
            self.closeSession()
7084 rajveer 1933
 
7080 anupam.sin 1934
    def getRechargeTransaction(self, rechargeId):
1935
        try:
1936
            return to_t_rechargeTransaction(get_recharge_transaction(rechargeId))
1937
        finally:
1938
            self.closeSession()
1939
 
1940
    def getFRCs(self, circleId, operatorId):
1941
        try:
1942
            return [to_t_frc(frc) for frc in get_frcs(circleId, operatorId)]
1943
        finally:
1944
            self.closeSession()
1945
 
7096 anupam.sin 1946
    def getHotspotStore(self, id, hotspotid):
1947
        try:
1948
            return to_t_hotspot(get_hotspot_store(id, hotspotid))
1949
        finally:
1950
            self.closeSession()
1951
 
1952
    def getTelecomCircle(self, id, code):
1953
        try:
1954
            return get_circle(id, code).to_thrift_object()
1955
        finally:
1956
            self.closeSession()
1957
 
7109 anupam.sin 1958
    def retrieveHotspotRechargeInvoice(self, rechargeId):
1959
        try:
1960
            return retrieve_hotspot_recharge_invoice(rechargeId)
1961
        finally:
1962
            self.closeSession()
1963
 
7172 anupam.sin 1964
    def getRechargeTransactionsByNumber(self, number, storeId):
7169 anupam.sin 1965
        try:
7172 anupam.sin 1966
            return [to_t_rechargeTransaction(txn) for txn in get_recharge_transactions_by_number(number, storeId)]
7169 anupam.sin 1967
        finally:
1968
            self.closeSession()
1969
 
1970
    def updateHotspotStorePassword(self, storeId, password):
1971
        try:
1972
            return update_hotspot_store_password(storeId, password)
1973
        finally:
1974
            self.closeSession()
1975
 
2536 chandransh 1976
    def closeSession(self, ):
1977
        close_session()
3376 rajveer 1978
 
1979
    def isAlive(self, ):
1980
        """
5447 anupam.sin 1981
        For checking whether service is alive or not. It also checks connectivity with database
3376 rajveer 1982
        """
1983
        try:
1984
            return is_alive()
1985
        finally:
6988 rajveer 1986
            close_session()