Subversion Repositories SmartDukaan

Rev

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