Subversion Repositories SmartDukaan

Rev

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