Subversion Repositories SmartDukaan

Rev

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