Subversion Repositories SmartDukaan

Rev

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