Subversion Repositories SmartDukaan

Rev

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