Subversion Repositories SmartDukaan

Rev

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