Subversion Repositories SmartDukaan

Rev

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