Subversion Repositories SmartDukaan

Rev

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