Subversion Repositories SmartDukaan

Rev

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