Subversion Repositories SmartDukaan

Rev

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