Subversion Repositories SmartDukaan

Rev

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